Closed simonw closed 3 years ago
I'm going to call this release.yml
.
It will be very similar to test.yml
- https://github.com/simonw/datasette-app/blob/5c3c0ab193f779856a53d68f2c0934575a733de4/.github/workflows/test.yml - but will be triggered by a release and will attach something to the release instead of publishing an artifact.
Weird that GitHub have archived their official action for this: https://github.com/actions/upload-release-asset
From https://github.com/actions/upload-release-asset/blob/main/src/upload-release-asset.js it looks like I can do this using a actions/github-script
step, as seen in https://github.com/simonw/datasette-plugin-template-repository/blob/7a0af5da0a4141c81b9866d585ccde954f06dd95/.github/workflows/cookiecutter.yml#L18-L43
I'm going to figure this out in my https://github.com/simonw/playing-with-actions repo.
After a few iterations I managed to ship https://github.com/simonw/playing-with-actions/releases/tag/v4 using the code from https://github.com/simonw/playing-with-actions/blob/v4/.github/workflows/release.yml - in particular this script block:
- uses: actions/github-script@v4
name: Upload release attachment
with:
script: |
const fs = require('fs');
const tag = context.ref.replace("refs/tags/", "");
console.log("tag = ", tag);
// Get release for this tag
const release = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag
});
console.log("release = ", release);
// Upload the release asset
await github.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: "My.zip",
data: await fs.readFileSync("My.zip")
});
Follows #20 and #50 - when I create a release in this GitHub repo it should attach the resulting
.zip
file to the release.