Skip to content

Commit b3c2715

Browse files
committed
ci: make releases atomic
Previously, "build and test" jobs would upload releases themselves, if they were cleared to do so. This mixing is not great from a pipeline security standpoint since the entire workflow runs with `contents: write`. It also introduces the potential for a *partial release*. If some jobs complete, but others do not, then a release will be issued without all its binaries. Make this operation more atomic by performing publishing activities in separate jobs. The publish jobs download all the artifacts and create the release.
1 parent d2a9bda commit b3c2715

1 file changed

Lines changed: 61 additions & 42 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ on:
77
pull_request:
88
branches: [ "develop" ]
99

10-
permissions:
11-
contents: write
12-
1310
env:
1411
CARGO_TERM_COLOR: always
1512
RUST_BACKTRACE: 1
@@ -153,7 +150,7 @@ jobs:
153150
run: |
154151
cargo test --frozen -p sameold --verbose --no-default-features --features "${{ matrix.features }}"
155152
156-
# Test and release samedec on Linux, via containers
153+
# Make release build of samedec for Linux, via containers
157154
release_samedec_linux:
158155
runs-on: ubuntu-latest
159156

@@ -211,39 +208,12 @@ jobs:
211208
cp /install/bin/samedec /install/bin/samedec-${{ matrix.target }}
212209
213210
- name: Store artifact
214-
uses: actions/upload-artifact@v4
211+
uses: actions/upload-artifact@v5
215212
with:
216213
name: samedec-${{ matrix.target }}
217214
path: /install/bin/samedec-${{ matrix.target }}
218215
retention-days: 3
219216

220-
- name: Upload tagged release (tags only)
221-
uses: svenstaro/upload-release-action@v2
222-
if: startsWith(github.ref, 'refs/tags/samedec-')
223-
with:
224-
repo_token: ${{ secrets.GITHUB_TOKEN }}
225-
file: /install/bin/samedec-${{ matrix.target }}
226-
overwrite: true
227-
228-
- name: Update tag for nightly release (develop-branch only)
229-
uses: richardsimko/update-tag@v1
230-
if: github.ref == 'refs/heads/develop'
231-
with:
232-
tag_name: latest
233-
env:
234-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
235-
236-
- name: Upload nightly release (develop-branch only)
237-
uses: svenstaro/upload-release-action@v2
238-
if: github.ref == 'refs/heads/develop'
239-
with:
240-
tag: "latest"
241-
release_name: "Nightly Release"
242-
body: "This is a rolling release built from the latest `develop` branch."
243-
prerelease: true
244-
file: /install/bin/samedec-${{ matrix.target }}
245-
overwrite: true
246-
247217
# MacOS and Windows builds
248218
release_samedec_nonlinux:
249219
strategy:
@@ -323,35 +293,84 @@ jobs:
323293
cp "$samedec_exe" "$samedec_target_exe"
324294
325295
- name: Store artifact
326-
uses: actions/upload-artifact@v4
296+
uses: actions/upload-artifact@v5
327297
with:
328298
name: samedec-${{ env.CARGO_BUILD_TARGET }}
329299
path: ${{ env.samedec_target_exe }}
330300
retention-days: 3
331301

332-
- name: Upload tagged release (tags only)
333-
uses: svenstaro/upload-release-action@v2
334-
if: startsWith(github.ref, 'refs/tags/samedec-')
302+
# Publish nightly builds
303+
publish_nightly:
304+
runs-on: ubuntu-latest
305+
306+
if: github.ref == 'refs/heads/develop'
307+
308+
permissions:
309+
contents: write
310+
311+
needs:
312+
- test_sameold
313+
- release_samedec_linux
314+
- release_samedec_nonlinux
315+
316+
name: Publish Nightly
317+
318+
steps:
319+
320+
- name: Download All Artifacts
321+
uses: actions/download-artifact@v5
335322
with:
336-
repo_token: ${{ secrets.GITHUB_TOKEN }}
337-
file: ${{ env.samedec_target_exe }}
338-
overwrite: true
323+
path: publish
324+
pattern: samedec-*
325+
merge-multiple: true
339326

340327
- name: Update tag for nightly release (develop-branch only)
341328
uses: richardsimko/update-tag@v1
342-
if: github.ref == 'refs/heads/develop'
343329
with:
344330
tag_name: latest
345331
env:
346332
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
347333

348334
- name: Upload nightly release (develop-only)
349335
uses: svenstaro/upload-release-action@v2
350-
if: github.ref == 'refs/heads/develop'
351336
with:
352337
tag: "latest"
353338
release_name: "Nightly Release"
354339
body: "This is a rolling release built from the latest `develop` branch."
355340
prerelease: true
356-
file: ${{ env.samedec_target_exe }}
341+
file_glob: true
342+
file: publish/samedec-*
343+
overwrite: true
344+
345+
# Publish tagged release
346+
publish_tag:
347+
runs-on: ubuntu-latest
348+
349+
if: startsWith(github.ref, 'refs/tags/samedec-')
350+
351+
permissions:
352+
contents: write
353+
354+
needs:
355+
- test_sameold
356+
- release_samedec_linux
357+
- release_samedec_nonlinux
358+
359+
name: Publish Tag
360+
361+
steps:
362+
363+
- name: Download All Artifacts
364+
uses: actions/download-artifact@v5
365+
with:
366+
path: publish
367+
pattern: samedec-*
368+
merge-multiple: true
369+
370+
- name: Upload tagged release (tags only)
371+
uses: svenstaro/upload-release-action@v2
372+
with:
373+
repo_token: ${{ secrets.GITHUB_TOKEN }}
374+
file_glob: true
375+
file: publish/samedec-*
357376
overwrite: true

0 commit comments

Comments
 (0)