-
Notifications
You must be signed in to change notification settings - Fork 5
/
action.js
68 lines (63 loc) · 1.77 KB
/
action.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
require('child_process')
.execSync(
'npm install @actions/[email protected] @actions/[email protected]',
{ cwd: __dirname }
);
const fs = require('fs');
const core = require('@actions/core');
const github = require('@actions/github');
(async () => {
try {
const api = new github.GitHub(core.getInput('token'));
const name = core.getInput('name');
const code = core.getInput('code');
const body = core.getInput('body');
const prerelease = core.getInput('prerelease') == 'true';
const recreate = core.getInput('prerelease') == 'true';
const assets = core.getInput('assets').split(' ').map(asset => asset.split(':'));
if (recreate) {
try {
const release = await api.repos.getReleaseByTag({
...github.context.repo,
tag: code
});
await api.repos.deleteRelease({
...github.context.repo,
release_id: release.data.id
});
await api.git.deleteRef({
...github.context.repo,
ref: `tags/${code}`
});
}
catch (error) {
if (error.name != 'HttpError' || error.status != 404) {
throw error;
}
}
}
const release = await api.repos.createRelease({
...github.context.repo,
tag_name: code,
target_commitish: github.context.sha,
name,
body,
prerelease: prerelease
});
for (const [source, target, type] of assets) {
const data = fs.readFileSync(source);
api.repos.uploadReleaseAsset({
url: release.data.upload_url,
headers: {
['content-type']: type,
['content-length']: data.length
},
name: target,
file: data
});
}
} catch (error) {
console.error(error);
core.setFailed(error.message);
}
})();