From fd6e59e68917e67f7381ce19a25cb58b81429c53 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 22 Jan 2023 00:19:52 +0200 Subject: [PATCH] Fix release workflow (#108) --- .github/workflows/release.yml | 89 +++++++++++++---------------------- .github/workflows/windows.yml | 48 +++++++++++++++---- 2 files changed, 73 insertions(+), 64 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 704b02c2..fc92f797 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,48 +10,53 @@ 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, @@ -59,49 +64,23 @@ jobs: }); // 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/create-release@v1.0.0 - 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/upload-release-asset@v1.0.1 - 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 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e8169be0..1176a56a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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