Skip to content

Commit 8adb13f

Browse files
committed
chore(ci): dev release placeholder
1 parent 1f3dff4 commit 8adb13f

1 file changed

Lines changed: 135 additions & 31 deletions

File tree

.github/workflows/esp32.yml

Lines changed: 135 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,66 @@ jobs:
2929
contents: write
3030
if: ${{ github.ref == 'refs/heads/main' }}
3131
steps:
32-
- name: Delete dev release
33-
run: gh release --repo ${{ github.repository }} delete dev --cleanup-tag -y
34-
continue-on-error: true
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
- name: Create tag
32+
- name: Update dev tag
3833
uses: actions/github-script@v9
3934
with:
4035
script: |
41-
github.rest.git.createRef({
42-
owner: context.repo.owner,
43-
repo: context.repo.repo,
44-
ref: 'refs/tags/dev',
45-
sha: context.sha
46-
})
36+
try {
37+
await github.rest.git.updateRef({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
ref: 'tags/dev',
41+
sha: context.sha,
42+
force: true
43+
});
44+
} catch (e) {
45+
if (e.status === 404 || (e.response && e.response.status === 404)) {
46+
await github.rest.git.createRef({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
ref: 'refs/tags/dev',
50+
sha: context.sha
51+
});
52+
} else {
53+
throw e;
54+
}
55+
}
56+
- name: Cleanup dev release
57+
uses: actions/github-script@v9
58+
with:
59+
script: |
60+
const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com';
61+
const runUrl = `${serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
62+
const body = `Latest commits are being processed, come back later.\nBuild status can be checked [here](${runUrl})`;
63+
64+
try {
65+
const { data: release } = await github.rest.repos.getReleaseByTag({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
tag: 'dev'
69+
});
70+
71+
for (const asset of release.assets) {
72+
await github.rest.repos.deleteReleaseAsset({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
asset_id: asset.id
76+
});
77+
}
78+
79+
await github.rest.repos.updateRelease({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
release_id: release.id,
83+
body: body
84+
});
85+
} catch (e) {
86+
if (e.status === 404 || (e.response && e.response.status === 404)) {
87+
console.log('No dev release found, skipping cleanup');
88+
} else {
89+
throw e;
90+
}
91+
}
4792
littlefs:
4893
runs-on: ubuntu-latest
4994
steps:
@@ -257,22 +302,81 @@ jobs:
257302
with:
258303
path: artifacts
259304
merge-multiple: true
260-
- name: Create release
261-
env:
262-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
263-
tag: ${{ github.ref_name }}
264-
run: |
265-
gh release create dev \
266-
--repo="$GITHUB_REPOSITORY" \
267-
--title="development" \
268-
--prerelease \
269-
--generate-notes \
270-
artifacts/esp32.firmware.bin \
271-
artifacts/esp32.firmware.factory.bin \
272-
artifacts/esp32c3.firmware.bin \
273-
artifacts/esp32c3.firmware.factory.bin \
274-
artifacts/esp32c6.firmware.bin \
275-
artifacts/esp32c6.firmware.factory.bin \
276-
artifacts/esp32s3.firmware.bin \
277-
artifacts/esp32s3.firmware.factory.bin \
278-
artifacts/littlefs.bin
305+
- name: Update dev release
306+
uses: actions/github-script@v9
307+
with:
308+
script: |
309+
const fs = require('fs');
310+
const path = require('path');
311+
312+
const artifactsDir = 'artifacts';
313+
const files = [
314+
'esp32.firmware.bin',
315+
'esp32.firmware.factory.bin',
316+
'esp32c3.firmware.bin',
317+
'esp32c3.firmware.factory.bin',
318+
'esp32c6.firmware.bin',
319+
'esp32c6.firmware.factory.bin',
320+
'esp32s3.firmware.bin',
321+
'esp32s3.firmware.factory.bin',
322+
'littlefs.bin'
323+
];
324+
325+
let release;
326+
try {
327+
const { data: existing } = await github.rest.repos.getReleaseByTag({
328+
owner: context.repo.owner,
329+
repo: context.repo.repo,
330+
tag: 'dev'
331+
});
332+
release = existing;
333+
} catch (e) {
334+
if (e.status === 404 || (e.response && e.response.status === 404)) {
335+
const { data: notes } = await github.rest.repos.generateReleaseNotes({
336+
owner: context.repo.owner,
337+
repo: context.repo.repo,
338+
tag_name: 'dev',
339+
target_commitish: context.sha
340+
});
341+
const { data: newRelease } = await github.rest.repos.createRelease({
342+
owner: context.repo.owner,
343+
repo: context.repo.repo,
344+
tag_name: 'dev',
345+
name: 'development',
346+
prerelease: true,
347+
body: notes.body
348+
});
349+
release = newRelease;
350+
} else {
351+
throw e;
352+
}
353+
}
354+
355+
for (const file of files) {
356+
const filePath = path.join(artifactsDir, file);
357+
if (!fs.existsSync(filePath)) {
358+
console.log(`Skipping missing file: ${file}`);
359+
continue;
360+
}
361+
await github.rest.repos.uploadReleaseAsset({
362+
owner: context.repo.owner,
363+
repo: context.repo.repo,
364+
release_id: release.id,
365+
name: file,
366+
data: fs.readFileSync(filePath)
367+
});
368+
}
369+
370+
const { data: notes } = await github.rest.repos.generateReleaseNotes({
371+
owner: context.repo.owner,
372+
repo: context.repo.repo,
373+
tag_name: 'dev',
374+
target_commitish: context.sha
375+
});
376+
377+
await github.rest.repos.updateRelease({
378+
owner: context.repo.owner,
379+
repo: context.repo.repo,
380+
release_id: release.id,
381+
body: notes.body
382+
});

0 commit comments

Comments
 (0)