-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.mjs
40 lines (34 loc) · 1.1 KB
/
updater.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 注意要安装@actions/github依赖
import { context, getOctokit } from "@actions/github";
import { readFile } from "node:fs/promises";
// 在容器中可以通过env环境变量来获取参数
const octokit = getOctokit(process.env.GITHUB_TOKEN);
const updateRelease = async () => {
// 获取updater tag的release
const { data: release } = await octokit.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: "updater",
});
// 删除旧的的文件
const deletePromises = release.assets
.filter((item) => item.name === "latest.json")
.map(async (item) => {
await octokit.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: item.id,
});
});
await Promise.all(deletePromises);
// 上传新的文件
const file = await readFile("latest.json", { encoding: "utf-8" });
await octokit.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name: "latest.json",
data: file,
});
};
updateRelease();