generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (62 loc) · 1.91 KB
/
index.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const core = require('@actions/core');
const github = require('@actions/github');
const read = require('fs-readdir-recursive');
async function readPR (octokit, context, bumpUpBranchPrefix, version) {
const { repo: { owner, repo } } = context;
const prs = await octokit.rest.pulls.list({
owner,
repo,
state: "closed",
head: `${owner}:${bumpUpBranchPrefix}${version}`,
});
const pr = prs.data.filter(x => !!x.merged_at);
if (pr.length == 1) {
return pr[0].body;
}
return "";
}
async function run() {
try {
const fs = require('fs').promises;
const path = require('path');
const token = core.getInput('github-token');
const directory = core.getInput('directory');
const tagPrefix = core.getInput('tag-prefix');
const bumpUpBranchPrefix = core.getInput('bump-up-branch-prefix');
const octokit = github.getOctokit(token);
const context = github.context;
const { repo: { owner, repo }, ref } = context;
const tag = ref.replace('refs/tags/', '');
const release = await octokit.rest.repos.getReleaseByTag({
owner,
repo,
tag,
});
const version = ref.replace(tagPrefix, '');
const prText = await readPR(octokit, context, bumpUpBranchPrefix, version);
const artifacts = read('.', () => true, [], directory);
core.startGroup('Assets')
for (let file of artifacts) {
core.info('uploading ' + file);
await octokit.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: path.basename(file),
data: await fs.readFile(file),
});
}
core.endGroup()
await octokit.rest.repos.updateRelease({
owner,
repo,
release_id: release.data.id,
prerelease: false,
name: tag,
body: prText,
});
core.info("\u001b[1mRelease: " + release.data.html_url);
} catch (error) {
core.setFailed(error.message);
}
}
run();