Skip to content

Commit c578c8d

Browse files
committed
Improve Release workflow
Use `workflow_run` to trigger the Release workflow once Tests completes successfully, instead of polling.
1 parent 9a17aab commit c578c8d

File tree

1 file changed

+83
-43
lines changed

1 file changed

+83
-43
lines changed

.github/workflows/release.yml

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,65 @@
11
name: Release
22

33
on:
4-
push:
5-
tags:
6-
- '[0-9]+.[0-9]+.[0-9]+'
4+
workflow_run:
5+
workflows: [Tests]
6+
types:
7+
- completed
8+
workflow_dispatch:
79

810
permissions:
911
contents: write
1012

1113
jobs:
14+
check-trigger:
15+
name: Check if triggered by tag
16+
runs-on: ubuntu-latest
17+
if: github.event.workflow_run.conclusion == 'success'
18+
outputs:
19+
is_tag: ${{ steps.check.outputs.is_tag }}
20+
tag_name: ${{ steps.check.outputs.tag_name }}
21+
steps:
22+
- name: Check if workflow was triggered by a version tag
23+
id: check
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
echo "Workflow run event: ${{ github.event.workflow_run.event }}"
28+
echo "Head branch: ${{ github.event.workflow_run.head_branch }}"
29+
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}"
30+
31+
# Get tags for this commit
32+
TAGS=$(gh api repos/${{ github.repository }}/git/refs/tags --jq '.[] | select(.object.sha == "${{ github.event.workflow_run.head_sha }}") | .ref' | sed 's|refs/tags/||')
33+
34+
if [ -z "$TAGS" ]; then
35+
echo "No tags found for this commit"
36+
echo "is_tag=false" >> $GITHUB_OUTPUT
37+
else
38+
# Check if any tag matches version pattern
39+
VERSION_TAG=$(echo "$TAGS" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
40+
if [ -n "$VERSION_TAG" ]; then
41+
echo "Found version tag: $VERSION_TAG"
42+
echo "is_tag=true" >> $GITHUB_OUTPUT
43+
echo "tag_name=$VERSION_TAG" >> $GITHUB_OUTPUT
44+
else
45+
echo "Tags found but none match version pattern"
46+
echo "is_tag=false" >> $GITHUB_OUTPUT
47+
fi
48+
fi
49+
1250
validate:
1351
name: Validate
52+
needs: check-trigger
53+
if: needs.check-trigger.outputs.is_tag == 'true'
1454
runs-on: ubuntu-latest
1555
timeout-minutes: 60
56+
outputs:
57+
tag_name: ${{ needs.check-trigger.outputs.tag_name }}
1658
steps:
17-
- name: Wait for Tests workflow to complete
18-
uses: WyriHaximus/github-action-wait-for-status@c638eadb55e7c6d951b0eb5fff5733569d82b03e # pinned commit for 1.8.0
19-
with:
20-
ignoreActions: Release
21-
checkInterval: 30
22-
env:
23-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24-
2559
- name: Checkout code
2660
uses: actions/checkout@v4 # not pinning to commit hash since this is a GitHub action, which we trust
61+
with:
62+
ref: ${{ github.event.workflow_run.head_sha }}
2763

2864
- name: Setup Rust toolchain
2965
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # pinned commit for 1.15.2
@@ -44,6 +80,8 @@ jobs:
4480
name: Build ${{ matrix.platform }}-${{ matrix.arch }}
4581
needs: validate
4682
runs-on: ${{ matrix.os }}
83+
env:
84+
TAG_NAME: ${{ needs.validate.outputs.tag_name }}
4785
strategy:
4886
fail-fast: false
4987
matrix:
@@ -156,7 +194,7 @@ jobs:
156194
if: matrix.platform == 'linux'
157195
shell: bash
158196
run: |
159-
PKG_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
197+
PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
160198
echo "Creating package directory structure for $PKG_NAME..."
161199
162200
mkdir -p "$PKG_NAME/lib"
@@ -181,12 +219,12 @@ jobs:
181219
chmod +x "$PKG_NAME/bin/get-custom-params"
182220
183221
echo "Creating VERSION file..."
184-
echo "${{ github.ref_name }}" > "$PKG_NAME/VERSION"
222+
echo "$TAG_NAME" > "$PKG_NAME/VERSION"
185223
186224
echo "Creating README.txt..."
187225
cat > "$PKG_NAME/README.txt" <<EOF
188226
crc-fast Binary Distribution
189-
Version: ${{ github.ref_name }}
227+
Version: $TAG_NAME
190228
Platform: Linux ${{ matrix.arch }}
191229
192230
CONTENTS
@@ -246,7 +284,7 @@ jobs:
246284
if: matrix.platform == 'linux'
247285
shell: bash
248286
run: |
249-
PKG_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
287+
PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
250288
ARCHIVE_NAME="${PKG_NAME}.tar.gz"
251289
252290
echo "Creating compressed archive: $ARCHIVE_NAME"
@@ -264,7 +302,7 @@ jobs:
264302
if: matrix.platform == 'linux'
265303
shell: bash
266304
run: |
267-
ARCHIVE_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
305+
ARCHIVE_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
268306
CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
269307
270308
echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -282,7 +320,7 @@ jobs:
282320
if: matrix.platform == 'macos'
283321
shell: bash
284322
run: |
285-
PKG_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
323+
PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
286324
echo "Creating package directory structure for $PKG_NAME..."
287325
288326
mkdir -p "$PKG_NAME/lib"
@@ -307,12 +345,12 @@ jobs:
307345
chmod +x "$PKG_NAME/bin/get-custom-params"
308346
309347
echo "Creating VERSION file..."
310-
echo "${{ github.ref_name }}" > "$PKG_NAME/VERSION"
348+
echo "$TAG_NAME" > "$PKG_NAME/VERSION"
311349
312350
echo "Creating README.txt..."
313351
cat > "$PKG_NAME/README.txt" <<EOF
314352
crc-fast Binary Distribution
315-
Version: ${{ github.ref_name }}
353+
Version: $TAG_NAME
316354
Platform: macOS ${{ matrix.arch }}
317355
318356
CONTENTS
@@ -371,7 +409,7 @@ jobs:
371409
if: matrix.platform == 'macos'
372410
shell: bash
373411
run: |
374-
PKG_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
412+
PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
375413
ARCHIVE_NAME="${PKG_NAME}.tar.gz"
376414
377415
echo "Creating compressed archive: $ARCHIVE_NAME"
@@ -389,7 +427,7 @@ jobs:
389427
if: matrix.platform == 'macos'
390428
shell: bash
391429
run: |
392-
ARCHIVE_NAME="crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
430+
ARCHIVE_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
393431
CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
394432
395433
echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -407,7 +445,7 @@ jobs:
407445
if: matrix.platform == 'windows'
408446
shell: pwsh
409447
run: |
410-
$PKG_NAME = "crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
448+
$PKG_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
411449
Write-Host "Creating package directory structure for $PKG_NAME..."
412450
413451
New-Item -ItemType Directory -Path "$PKG_NAME/bin" -Force | Out-Null
@@ -428,12 +466,12 @@ jobs:
428466
Copy-Item "target/release/get-custom-params.exe" "$PKG_NAME/bin/"
429467
430468
Write-Host "Creating VERSION file..."
431-
"${{ github.ref_name }}" | Out-File -FilePath "$PKG_NAME/VERSION" -Encoding utf8 -NoNewline
469+
"$env:TAG_NAME" | Out-File -FilePath "$PKG_NAME/VERSION" -Encoding utf8 -NoNewline
432470
433471
Write-Host "Creating README.txt..."
434472
@"
435473
crc-fast Binary Distribution
436-
Version: ${{ github.ref_name }}
474+
Version: $env:TAG_NAME
437475
Platform: Windows ${{ matrix.arch }}
438476
439477
CONTENTS
@@ -495,7 +533,7 @@ jobs:
495533
if: matrix.platform == 'windows'
496534
shell: pwsh
497535
run: |
498-
$PKG_NAME = "crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}"
536+
$PKG_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
499537
$ARCHIVE_NAME = "${PKG_NAME}.zip"
500538
501539
Write-Host "Creating compressed archive: $ARCHIVE_NAME"
@@ -516,7 +554,7 @@ jobs:
516554
if: matrix.platform == 'windows'
517555
shell: pwsh
518556
run: |
519-
$ARCHIVE_NAME = "crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.zip"
557+
$ARCHIVE_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.zip"
520558
$CHECKSUM_FILE = "${ARCHIVE_NAME}.sha256"
521559
522560
Write-Host "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -537,23 +575,25 @@ jobs:
537575
- name: Upload package artifact
538576
uses: actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
539577
with:
540-
name: crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
541-
path: crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
578+
name: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
579+
path: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
542580
if-no-files-found: error
543581
retention-days: 90
544582

545583
- name: Upload checksum artifact
546584
uses: actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
547585
with:
548-
name: crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
549-
path: crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
586+
name: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
587+
path: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
550588
if-no-files-found: error
551589
retention-days: 90
552590

553591
publish:
554592
name: Publish
555-
needs: build
593+
needs: [validate, build]
556594
runs-on: ubuntu-latest
595+
env:
596+
TAG_NAME: ${{ needs.validate.outputs.tag_name }}
557597
steps:
558598
- name: Download all artifacts
559599
uses: actions/download-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
@@ -567,11 +607,11 @@ jobs:
567607
env:
568608
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
569609
run: |
570-
echo "Checking if release exists for tag: ${{ github.ref_name }}"
610+
echo "Checking if release exists for tag: $TAG_NAME"
571611
572612
RELEASE_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
573613
-H "Accept: application/vnd.github+json" \
574-
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}")
614+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME")
575615
576616
if echo "$RELEASE_DATA" | jq -e '.id' > /dev/null 2>&1; then
577617
RELEASE_ID=$(echo "$RELEASE_DATA" | jq -r '.id')
@@ -599,16 +639,16 @@ jobs:
599639
600640
echo "Verifying all expected files are present..."
601641
EXPECTED_FILES=(
602-
"crc-fast-${{ github.ref_name }}-linux-x86_64.tar.gz"
603-
"crc-fast-${{ github.ref_name }}-linux-x86_64.tar.gz.sha256"
604-
"crc-fast-${{ github.ref_name }}-linux-aarch64.tar.gz"
605-
"crc-fast-${{ github.ref_name }}-linux-aarch64.tar.gz.sha256"
606-
"crc-fast-${{ github.ref_name }}-macos-aarch64.tar.gz"
607-
"crc-fast-${{ github.ref_name }}-macos-aarch64.tar.gz.sha256"
608-
"crc-fast-${{ github.ref_name }}-windows-x86_64.zip"
609-
"crc-fast-${{ github.ref_name }}-windows-x86_64.zip.sha256"
610-
"crc-fast-${{ github.ref_name }}-windows-aarch64.zip"
611-
"crc-fast-${{ github.ref_name }}-windows-aarch64.zip.sha256"
642+
"crc-fast-$TAG_NAME-linux-x86_64.tar.gz"
643+
"crc-fast-$TAG_NAME-linux-x86_64.tar.gz.sha256"
644+
"crc-fast-$TAG_NAME-linux-aarch64.tar.gz"
645+
"crc-fast-$TAG_NAME-linux-aarch64.tar.gz.sha256"
646+
"crc-fast-$TAG_NAME-macos-aarch64.tar.gz"
647+
"crc-fast-$TAG_NAME-macos-aarch64.tar.gz.sha256"
648+
"crc-fast-$TAG_NAME-windows-x86_64.zip"
649+
"crc-fast-$TAG_NAME-windows-x86_64.zip.sha256"
650+
"crc-fast-$TAG_NAME-windows-aarch64.zip"
651+
"crc-fast-$TAG_NAME-windows-aarch64.zip.sha256"
612652
)
613653
614654
MISSING_FILES=()

0 commit comments

Comments
 (0)