-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
65 lines (58 loc) · 2.48 KB
/
action.yml
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
name: "GitHub release"
description: "Create a GitHub release from a file and tag-based description"
inputs:
filename:
description: "release tarball to publish"
required: true
outputs:
checksum:
description: "SHA256 checksum of filename"
value: ${{ steps.publish.outputs.checksum }}
download:
description: "URL for downloading filename"
value: ${{ steps.publish.outputs.download }}
filename:
description: "Copy of inputs.filename, to re-use it for other jobs"
value: ${{ inputs.filename }}
body:
description: "Tag details without the subject"
value: ${{ steps.publish.outputs.body }}
runs:
using: composite
steps:
- name: Extract tag body
run: git tag --points-at "${{ github.ref }}" --format '%(contents:body)' | grep . | tee release-body
shell: bash
- name: Publish release
id: publish
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const version = '${{ github.ref }}'.split('/').pop();
const release_body = fs.readFileSync('release-body', {encoding: 'utf-8'});
const source = fs.readFileSync('${{ inputs.filename }}');
const release = await github.rest.repos.createRelease({
owner: context.repo.owner, repo: context.repo.repo,
tag_name: version, name: version, body: release_body, draft: true
});
/* We get a lot of connection reset errors... */
for (let retry = 0; retry < 5; retry++) {
try {
const upload = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner, repo: context.repo.repo, release_id: release.data.id,
name: '${{ inputs.filename }}', headers: {'Content-Type': 'application/x-xz'}, data: source});
break;
} catch (error) {
console.log(`Failed to upload (status ${error.status})`);
if (error.status != 500) {
throw error;
}
}
}
const update = await github.rest.repos.updateRelease({
owner: context.repo.owner, repo: context.repo.repo, release_id: release.data.id,
draft: false});
core.setOutput('checksum', require('crypto').createHash('sha256').update(source).digest('hex'));
core.setOutput('download', update.data.assets[0].browser_download_url);
core.setOutput('body', release_body);