Skip to content

Commit c88d28f

Browse files
committed
fix: improve release asset handling and permissions
1 parent 1b27546 commit c88d28f

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
runs-on: ${{ matrix.platform }}
2828
outputs:
2929
upload_url: ${{ steps.create_release.outputs.upload_url }}
30+
release_id: ${{ steps.create_release.outputs.id }}
3031
steps:
3132
- name: Checkout
3233
uses: actions/checkout@v4
@@ -83,6 +84,8 @@ jobs:
8384

8485
create-update:
8586
needs: build
87+
permissions:
88+
contents: write
8689
runs-on: ubuntu-latest
8790
steps:
8891
- name: Checkout
@@ -121,23 +124,31 @@ jobs:
121124
const maxAttempts = 30;
122125
123126
while (attempts < maxAttempts) {
124-
const release = await github.rest.repos.getReleaseByTag({
125-
owner,
126-
repo,
127-
tag
128-
});
129-
130-
const assets = release.data.assets.map(asset => asset.name);
131-
const missingAssets = artifacts.filter(artifact => !assets.includes(artifact));
132-
133-
if (missingAssets.length === 0) {
134-
console.log('All assets found!');
135-
break;
127+
try {
128+
const releases = await github.rest.repos.listReleases({
129+
owner,
130+
repo
131+
});
132+
133+
const release = releases.data.find(r => r.tag_name === tag);
134+
if (!release) {
135+
throw new Error('Release not found');
136+
}
137+
138+
const assets = release.assets.map(asset => asset.name);
139+
const missingAssets = artifacts.filter(artifact => !assets.includes(artifact));
140+
141+
if (missingAssets.length === 0) {
142+
console.log('All assets found!');
143+
break;
144+
}
145+
146+
console.log(`Waiting for assets: ${missingAssets.join(', ')}`);
147+
} catch (error) {
148+
console.log('Error checking release:', error.message);
136149
}
137150
138-
console.log(`Waiting for assets: ${missingAssets.join(', ')}`);
139151
attempts++;
140-
141152
if (attempts === maxAttempts) {
142153
throw new Error('Timed out waiting for assets');
143154
}
@@ -160,20 +171,24 @@ jobs:
160171
const owner = context.repo.owner;
161172
const repo = context.repo.repo;
162173
163-
const release = await github.rest.repos.getReleaseByTag({
174+
const releases = await github.rest.repos.listReleases({
164175
owner,
165-
repo,
166-
tag
176+
repo
167177
});
168178
179+
const release = releases.data.find(r => r.tag_name === tag);
180+
if (!release) {
181+
throw new Error('Release not found');
182+
}
183+
169184
const fs = require('fs');
170185
const path = require('path');
171186
172187
if (!fs.existsSync('artifacts')) {
173188
fs.mkdirSync('artifacts');
174189
}
175190
176-
for (const asset of release.data.assets) {
191+
for (const asset of release.assets) {
177192
if (artifacts.includes(asset.name)) {
178193
const response = await github.request(asset.browser_download_url);
179194
fs.writeFileSync(path.join('artifacts', asset.name), Buffer.from(response.data));

0 commit comments

Comments
 (0)