-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (47 loc) · 1.33 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
const fs = require('fs');
const path = require('path');
const core = require('@actions/core');
const { Octokit } = require('@octokit/action');
const updateReleaseArtifact = async (releaseId, artifactPath) => {
const octokit = new Octokit();
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const { data } = await octokit.request(
'GET /repos/:owner/:repo/releases/:releaseId/assets',
{
owner,
repo,
releaseId,
}
);
for (const asset of data) {
await octokit.request(
'DELETE /repos/:owner/:repo/releases/assets/:assetId',
{
owner,
repo,
assetId: asset.id,
}
);
console.log(`- Removed ${asset.name} from release`);
}
await octokit.repos.uploadReleaseAsset({
owner,
repo,
release_id: releaseId,
name: path.basename(artifactPath),
data: fs.readFileSync(artifactPath),
});
};
async function run() {
try {
const artifactPath = core.getInput('artifact_path');
const releaseId = core.getInput('release_id');
console.log(`artifactPath: ${artifactPath}, releaseId: ${releaseId}`);
console.log(`Updating release artifact`);
await updateReleaseArtifact(releaseId, artifactPath);
console.log(`Successfully updated release artifact`);
} catch (error) {
core.setFailed(error.message);
}
}
run();