megabit-os/.github/scripts/release.js
2021-09-05 17:23:30 +09:00

28 lines
1 KiB
JavaScript

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 });
};