add release job

This commit is contained in:
Nebel 2021-09-05 17:13:34 +09:00
parent 598305cce2
commit 720eb2e3df
2 changed files with 43 additions and 0 deletions

28
.github/scripts/release.js vendored Normal file
View file

@ -0,0 +1,28 @@
const path = require("path");
const fs = require("fs").promises;
const crypto = require("crypto");
/** actions/github-script でのリリース成果物のアップロード */
module.exports = async function ({ github, context, glob }) {
const version = context.payload.release.tag_name.replace(/^v/i, "");
const target = {
...context.repo,
release_id: context.payload.release.id,
};
let body = "## Megabit OS\n";
const globber = await glob.create("megabit-armhf.*.gz");
for await (const file of globber.globGenerator()) {
const name = path
.basename(file)
.replace(/^megabit-armhf[.]/, `megabit-${version}-armhf.`);
const data = await fs.readFile(file);
await github.repos.uploadReleaseAsset({ ...target, name, data });
const hash = crypto.createHash("sha256").update(data).digest("hex");
body = `${body}
${name.split(".").includes("img") ? "OS イメージ" : "ファイルシステム"}
- ${name} (SHA256: \`${hash}\`)
`;
}
await github.repos.updateRelease({ ...target, body, prerelease: false });
};

View file

@ -1,6 +1,8 @@
name: build name: build
on: on:
push: { branches: [main] } push: { branches: [main] }
release:
types: [published]
jobs: jobs:
main: main:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -14,3 +16,16 @@ jobs:
with: with:
name: megabit-armhf name: megabit-armhf
path: megabit-armhf.* path: megabit-armhf.*
release:
if: github.event.release.prerelease
needs: main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with: { name: megabit-armhf }
- uses: actions/github-script@v4
with:
script: |
const script = require("./.github/scripts/release.js");
await script({ github, context, glob });