Skip to content

Commit

Permalink
Fix release workflow (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Jan 21, 2023
1 parent ffed0bb commit fd6e59e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 64 deletions.
89 changes: 34 additions & 55 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,98 +10,77 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: git fetch --tags
- id: tagname
run: |
if git tag -l --contains HEAD | grep .; then
# Commit already tagged
echo "::set-output name=datetag::"
echo datetag= >> $GITHUB_OUTPUT
else
# When building just after midnight, use the date of the previous day, not current day.
# When triggered manually, use (most likely) the current date.
# This way, the date represents when the changes were made.
echo "::set-output name=datetag::master-$(date -d '5 minutes ago' +'%Y-%m-%d')"
echo datetag=$(date -d '5 minutes ago' +'%Y-%m-%d') > $GITHUB_OUTPUT
fi
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Download latest GitHub actions build results
uses: actions/github-script@v3
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
// Based on: https://github.com/python/typeshed/blob/82fa8473ffddc57a53b4dbcb1063aa2e66352ca9/.github/workflows/mypy_primer_comment.yml
const run = (
await github.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
branch: 'main',
})
).data.workflow_runs
.filter(run => run.name === '.github/workflows/windows.yml')
.sort((a, b) => (+new Date(b.created_at)) - (+new Date(a.created_at)))[0];
const allRuns = (
await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
branch: 'main',
})
).data.workflow_runs;
console.log(`Found ${allRuns.length} runs`);
console.log(allRuns.map(r => r.name));
const run = allRuns
.filter(r => r.name === '.github/workflows/windows.yml')
.sort((a, b) => (+new Date(b.run_started_at)) - (+new Date(a.run_started_at)))[0];
const [artifact] = (
await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id,
})
).data.artifacts
.filter(a => a.name === 'build');
const allArtifacts = (
await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id,
})
).data.artifacts;
console.log(`Found ${allArtifacts.length} artifacts`);
console.log(allArtifacts.map(a => a.name));
const artifact = allArtifacts.filter(a => a.name === 'exe-and-dlls')[0];
const zip = await github.actions.downloadArtifact({
const zip = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
// https://stackoverflow.com/a/46779188
fs.writeFileSync("windows-build.zip", Buffer.from(zip.data));
fs.writeFileSync("exe-and-dlls.zip", Buffer.from(zip.data));
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Create the zip file
run: |
unzip windows-build.zip
unzip exe-and-dlls.zip
ls -l
mkdir -v jou
cp -v jou.exe jou
cp -v *.dll jou
cp -rv stdlib jou
zip -r jou.zip jou
# https://stackoverflow.com/a/64479344
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Create tag
uses: actions/github-script@v3
with:
github-token: ${{ github.token }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.tagname.outputs.datetag }}",
sha: context.sha
})
zip -r jou_windows_64bit_${{ steps.tagname.outputs.datetag }}.zip jou
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Create release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tagname.outputs.datetag }}
release_name: ${{ steps.tagname.outputs.datetag }}

- if: ${{ steps.tagname.outputs.datetag != '' }}
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: jou.zip
asset_name: jou_${{ steps.tagname.outputs.datetag }}.zip
asset_content_type: application/zip
commit: main
tag: ${{ steps.tagname.outputs.datetag }}
artifacts: jou_windows_64bit_${{ steps.tagname.outputs.datetag }}.zip
48 changes: 39 additions & 9 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,49 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download LLVM binaries
# Apparently the exe file is created with nsis installer and 7z can extract from it.
# Figured out by looking at source code of https://github.com/KyleMayes/install-llvm-action
- uses: actions/checkout@v3
- name: Download LLVM installer
run: wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/LLVM-13.0.1-win64.exe
- name: Verify LLVM installer
run: |
wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/LLVM-13.0.1-win64.exe
7z x LLVM-13.0.1-win64.exe bin/LLVM-C.dll lib/LLVM-C.lib
# llvm-13-dev needed for the header files
ls -lh LLVM-13.0.1-win64.exe
if [ "$(sha256sum LLVM-13.0.1-win64.exe)" != "9d15be034d52ec57cfc97615634099604d88a54761649498daa7405983a7e12f LLVM-13.0.1-win64.exe" ]; then
echo "sha sum mismatch! something has changed!"
exit 1
fi
# Apparently the exe file is created with nsis installer and 7z can extract from it.
# Figured out by looking at source code of https://github.com/KyleMayes/install-llvm-action
- name: Extract files from LLVM installer
run: |
files="lib/LLVM-C.lib"
for file in $(7z l LLVM-13.0.1-win64.exe | grep -o 'bin/.*\.dll'); do
case $file in
# To figure out which dll files I need, I deleted them one by one and ran
# the compiler again.
#
# Unfortunately you need to do this locally instead of relying on github
# actions, because github actions comes with lots of software and hence lots
# of DLL files preinstalled. I used a Windows VM with nothing installed.
bin/LLVM-C.dll | \
bin/msvcp140.dll | \
bin/ucrtbase.dll | \
bin/vcruntime140.dll | \
bin/vcruntime140_1.dll | \
bin/api-ms-win-*.dll) # Not sure which of these we need and what each one does.
files="$files $file"
;;
*)
echo "*** skip dll: $file ***"
;;
esac
done
echo "Extracting $files"
7z x LLVM-13.0.1-win64.exe $files
# llvm-13-dev needed for the header files. They seem to be missing from LLVM windows installer.
# Using gcc instead of clang, because gcc "just works".
- run: sudo apt install -y llvm-13-dev gcc-mingw-w64-x86-64-win32
- run: CC=x86_64-w64-mingw32-gcc LDFLAGS=lib/LLVM-C.lib make
- run: mkdir -v exe-and-dlls
- run: cp -vr jou.exe bin/LLVM-C.dll exe-and-dlls/
- run: mkdir -v exe-and-dlls && cp -v jou.exe bin/*.dll exe-and-dlls/
- uses: actions/upload-artifact@v3
with:
name: exe-and-dlls
Expand Down

0 comments on commit fd6e59e

Please sign in to comment.