Skip to content

.github/workflows/release.yml #718

.github/workflows/release.yml

.github/workflows/release.yml #718

Workflow file for this run

#
#
#
# *** If you edit this file, make sure that CONTRIBUTING.md stays up to date.
#
#
#
on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch: # Can also be triggered manually from github UI
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: git fetch --tags
- id: tagname
run: |
if git tag -l --contains HEAD | grep .; then
# Commit already tagged
echo datetag= >> $GITHUB_OUTPUT
else
echo datetag=$(date +'%Y-%m-%d-%H00') > $GITHUB_OUTPUT
fi
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Download latest GitHub actions build results
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 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 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 === 'windows-zip')[0];
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("nested-zip-file.zip", Buffer.from(zip.data));
# We get a zip file inside a zip file:
# * Inner zip file: The build creates a releasing-ready zip file. This is
# good because you can test the zip file before Jou is released.
# * Outer zip file: It is possible to include multiple files to the same
# GitHub Actions artifact, and downloadArtifact() gives a zip of all
# files that the artifact consists of.
- if: ${{ steps.tagname.outputs.datetag != '' }}
run: unzip nested-zip-file.zip
- if: ${{ steps.tagname.outputs.datetag != '' }}
run: mv jou.zip jou_windows_64bit_${{ steps.tagname.outputs.datetag }}.zip
- if: ${{ steps.tagname.outputs.datetag != '' }}
name: Create release
uses: ncipollo/release-action@v1
with:
commit: main
tag: ${{ steps.tagname.outputs.datetag }}
artifacts: jou_windows_64bit_${{ steps.tagname.outputs.datetag }}.zip
skipIfReleaseExists: true