Skip to content

Commit 8b94c53

Browse files
authored
Port the newer github-release action from wasmtime (#7)
Port the most recent version of the github-release action from wasmtime to spidermonkey-wasi-embedding, to fix the publishing of release artifacts from builds on the main branch.
1 parent 3678a0a commit 8b94c53

File tree

7 files changed

+610
-59
lines changed

7 files changed

+610
-59
lines changed

.github/actions/github-release/Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/actions/github-release/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ An action used to publish GitHub releases for `wasmtime`.
44

55
As of the time of this writing there's a few actions floating around which
66
perform github releases but they all tend to have their set of drawbacks.
7-
Additionally nothing handles deleting releases which we need for our rolling
8-
`dev` release.
97

108
To handle all this this action rolls-its-own implementation using the
119
actions/toolkit repository and packages published there. These run in a Docker

.github/actions/github-release/action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: 'SpiderMonkey WASI github release'
1+
name: 'wasmtime github releases'
2+
description: 'wasmtime github releases'
23
inputs:
34
token:
45
description: ''
@@ -10,5 +11,5 @@ inputs:
1011
description: ''
1112
required: true
1213
runs:
13-
using: 'docker'
14-
image: 'Dockerfile'
14+
using: 'node16'
15+
main: 'main.js'

.github/actions/github-release/main.js

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,52 @@ async function runOnce() {
2222
core.info(`name: ${name}`);
2323
core.info(`token: ${token}`);
2424

25-
const octokit = new github.GitHub(token);
25+
const octokit = github.getOctokit(token);
2626

27-
// Delete the previous release since we can't overwrite one. This may happen
28-
// due to retrying an upload or it may happen because we're doing the dev
29-
// release.
30-
const releases = await octokit.paginate("GET /repos/:owner/:repo/releases", { owner, repo });
31-
for (const release of releases) {
32-
if (release.tag_name !== name) {
33-
continue;
34-
}
35-
const release_id = release.id;
36-
core.info(`deleting release ${release_id}`);
37-
await octokit.repos.deleteRelease({ owner, repo, release_id });
38-
}
39-
40-
// We also need to update the `dev` tag while we're at it on the `dev` branch.
41-
if (name == 'dev') {
27+
// Try to load the release for this tag, and if it doesn't exist then make a
28+
// new one. We might race with other builders on creation, though, so if the
29+
// creation fails try again to get the release by the tag.
30+
let release = null;
31+
try {
32+
core.info(`fetching release`);
33+
release = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag: name });
34+
} catch (e) {
35+
console.log("ERROR: ", JSON.stringify(e, null, 2));
36+
core.info(`creating a release`);
4237
try {
43-
core.info(`updating dev tag`);
44-
await octokit.git.updateRef({
45-
owner,
46-
repo,
47-
ref: 'tags/dev',
48-
sha,
49-
force: true,
50-
});
51-
} catch (e) {
52-
console.log("ERROR: ", JSON.stringify(e, null, 2));
53-
core.info(`creating dev tag`);
54-
await octokit.git.createTag({
38+
release = await octokit.rest.repos.createRelease({
5539
owner,
5640
repo,
57-
tag: 'dev',
58-
message: 'dev release',
59-
object: sha,
60-
type: 'commit',
41+
tag_name: name,
42+
prerelease: name === 'dev',
6143
});
44+
} catch(e) {
45+
console.log("ERROR: ", JSON.stringify(e, null, 2));
46+
core.info(`fetching one more time`);
47+
release = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag: name });
6248
}
6349
}
64-
65-
// Creates an official GitHub release for this `tag`, and if this is `dev`
66-
// then we know that from the previous block this should be a fresh release.
67-
core.info(`creating a release`);
68-
const release = await octokit.repos.createRelease({
69-
owner,
70-
repo,
71-
tag_name: name,
72-
prerelease: name === 'dev',
73-
});
50+
console.log("found release: ", JSON.stringify(release.data, null, 2));
7451

7552
// Upload all the relevant assets for this release as just general blobs.
7653
for (const file of glob.sync(files)) {
7754
const size = fs.statSync(file).size;
55+
const name = path.basename(file);
56+
for (const asset of release.data.assets) {
57+
if (asset.name !== name)
58+
continue;
59+
console.log(`deleting prior asset ${asset.id}`);
60+
await octokit.rest.repos.deleteReleaseAsset({
61+
owner,
62+
repo,
63+
asset_id: asset.id,
64+
});
65+
}
7866
core.info(`upload ${file}`);
79-
await octokit.repos.uploadReleaseAsset({
67+
await octokit.rest.repos.uploadReleaseAsset({
8068
data: fs.createReadStream(file),
8169
headers: { 'content-length': size, 'content-type': 'application/octet-stream' },
82-
name: path.basename(file),
70+
name,
8371
url: release.data.upload_url,
8472
});
8573
}

0 commit comments

Comments
 (0)