generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (41 loc) · 1.44 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
const core = require('@actions/core');
const github = require('@actions/github');
const read = require('fs-readdir-recursive');
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 tag = core.getInput('tag');
const octokit = github.getOctokit(token);
const context = github.context;
const { repo: { owner, repo }, ref } = context;
const commit = await octokit.rest.repos.getCommit({ owner, repo, ref });
const staging = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });
await octokit.rest.repos.deleteRelease({ owner, repo, release_id: staging.data.id });
const newStaging = await octokit.rest.repos.createRelease({
owner,
repo,
tag_name: tag,
prerelease: true,
body: commit.data.commit.message,
});
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: newStaging.data.id,
name: path.basename(file),
data: await fs.readFile(file),
});
}
core.endGroup()
core.info("\u001b[1mStaging Release: " + newStaging.data.html_url);
} catch (error) {
core.setFailed(error.message);
}
}
run();