Skip to content

Commit ed49f73

Browse files
committed
Moved the release asset upload script to its own file.
1 parent 10451a5 commit ed49f73

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

.github/workflows/release-event-test.yml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on:
66
# -- Oh!
77
# > Note: The release event is not triggered for draft releases.
88
# Emphasis on ****release event****, I read this as meaning to be the "released" type.
9+
# `created` will fire if you create a release and publish immediately without making it a draft first.
910
#####################
1011
# Edited works!
1112
# Not sure how to trigger unpublished...
1213
# Deleted works
13-
# Not sure what prereleased/released are either (I would think they describe what I'd call "publish", but that's obviously a separate event)
14-
types: [published, unpublished, created, edited, deleted, prereleased, released]
14+
# `released` (and probably `prereleased`) seem to only happen if you publish immediately without making a draft first.
15+
#types: [published, unpublished, created, edited, deleted, prereleased, released]
16+
types: [published]
1517
jobs:
1618
do-release:
1719
runs-on: ubuntu-latest
@@ -29,6 +31,8 @@ jobs:
2931
if: github.event.action == 'published'
3032
runs-on: ubuntu-latest
3133
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v2
3236
- name: Test getting the release URL in a GitHub script
3337
uses: actions/github-script@v3
3438
with:
@@ -48,30 +52,8 @@ jobs:
4852
asset_name: test-uploadaction.txt
4953
asset_content_type: text/plain
5054
- name: Upload test files
51-
uses: actions/github-script@v3
55+
uses: actions/github-script@v4
5256
with:
5357
#github-token: ${{secrets.GITHUB_TOKEN}}
5458
user-agent: actions/github-script for ${{github.repository}}
55-
script: |
56-
const fs = require('fs').promises;
57-
const path = require('path');
58-
59-
for (let filePath of await fs.readdir('.')) {
60-
const fileExtension = path.extname(filePath);
61-
if (fileExtension != '.txt') {
62-
continue;
63-
}
64-
65-
console.log(`Uploading '${filePath}'`);
66-
const contentLength = (await fs.stat(filePath)).size;
67-
const fileContents = await fs.readFile(filePath);
68-
await github.repos.uploadReleaseAsset({
69-
url: '${{github.event.release.upload_url}}',
70-
headers: {
71-
'content-type': 'application/octet-stream',
72-
'content-length': contentLength
73-
},
74-
name: path.basename(filePath),
75-
data: fileContents
76-
});
77-
}
59+
script: await require('./.github/workflows/upload-release-assets.js')(github, context);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = async (github, context) => {
2+
const fs = require('fs').promises;
3+
const path = require('path');
4+
const upload_url = context.payload.release.upload_url;
5+
6+
if (!upload_url) {
7+
throw "Missing release asset upload URL!";
8+
}
9+
10+
for (let filePath of await fs.readdir('.')) {
11+
const fileExtension = path.extname(filePath);
12+
if (fileExtension != '.txt') {
13+
continue;
14+
}
15+
16+
console.log(`Uploading '${filePath}'`);
17+
const contentLength = (await fs.stat(filePath)).size;
18+
const fileContents = await fs.readFile(filePath);
19+
await github.repos.uploadReleaseAsset({
20+
url: context.payload.release.upload_url,
21+
headers: {
22+
'content-type': 'application/octet-stream',
23+
'content-length': contentLength
24+
},
25+
name: path.basename(filePath),
26+
data: fileContents
27+
});
28+
}
29+
};

0 commit comments

Comments
 (0)