11name : Release
22
33on :
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
810permissions :
911 contents : write
1012
1113jobs :
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
@@ -37,10 +73,15 @@ jobs:
3773 - name : Run clippy
3874 run : cargo clippy -- -D warnings
3975
76+ - name : Run tests
77+ run : cargo test
78+
4079 build :
4180 name : Build ${{ matrix.platform }}-${{ matrix.arch }}
4281 needs : validate
4382 runs-on : ${{ matrix.os }}
83+ env :
84+ TAG_NAME : ${{ needs.validate.outputs.tag_name }}
4485 strategy :
4586 fail-fast : false
4687 matrix :
@@ -153,7 +194,7 @@ jobs:
153194 if : matrix.platform == 'linux'
154195 shell : bash
155196 run : |
156- PKG_NAME="crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
197+ PKG_NAME="crc-fast-$TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
157198 echo "Creating package directory structure for $PKG_NAME..."
158199
159200 mkdir -p "$PKG_NAME/lib"
@@ -178,12 +219,12 @@ jobs:
178219 chmod +x "$PKG_NAME/bin/get-custom-params"
179220
180221 echo "Creating VERSION file..."
181- echo "${{ github.ref_name }} " > "$PKG_NAME/VERSION"
222+ echo "$TAG_NAME " > "$PKG_NAME/VERSION"
182223
183224 echo "Creating README.txt..."
184225 cat > "$PKG_NAME/README.txt" <<EOF
185226 crc-fast Binary Distribution
186- Version: ${{ github.ref_name }}
227+ Version: $TAG_NAME
187228 Platform: Linux ${{ matrix.arch }}
188229
189230 CONTENTS
@@ -243,7 +284,7 @@ jobs:
243284 if : matrix.platform == 'linux'
244285 shell : bash
245286 run : |
246- PKG_NAME="crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
287+ PKG_NAME="crc-fast-$TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
247288 ARCHIVE_NAME="${PKG_NAME}.tar.gz"
248289
249290 echo "Creating compressed archive: $ARCHIVE_NAME"
@@ -261,7 +302,7 @@ jobs:
261302 if : matrix.platform == 'linux'
262303 shell : bash
263304 run : |
264- 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"
265306 CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
266307
267308 echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -279,7 +320,7 @@ jobs:
279320 if : matrix.platform == 'macos'
280321 shell : bash
281322 run : |
282- PKG_NAME="crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
323+ PKG_NAME="crc-fast-$TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
283324 echo "Creating package directory structure for $PKG_NAME..."
284325
285326 mkdir -p "$PKG_NAME/lib"
@@ -304,12 +345,12 @@ jobs:
304345 chmod +x "$PKG_NAME/bin/get-custom-params"
305346
306347 echo "Creating VERSION file..."
307- echo "${{ github.ref_name }} " > "$PKG_NAME/VERSION"
348+ echo "$TAG_NAME " > "$PKG_NAME/VERSION"
308349
309350 echo "Creating README.txt..."
310351 cat > "$PKG_NAME/README.txt" <<EOF
311352 crc-fast Binary Distribution
312- Version: ${{ github.ref_name }}
353+ Version: $TAG_NAME
313354 Platform: macOS ${{ matrix.arch }}
314355
315356 CONTENTS
@@ -368,7 +409,7 @@ jobs:
368409 if : matrix.platform == 'macos'
369410 shell : bash
370411 run : |
371- PKG_NAME="crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
412+ PKG_NAME="crc-fast-$TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
372413 ARCHIVE_NAME="${PKG_NAME}.tar.gz"
373414
374415 echo "Creating compressed archive: $ARCHIVE_NAME"
@@ -386,7 +427,7 @@ jobs:
386427 if : matrix.platform == 'macos'
387428 shell : bash
388429 run : |
389- 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"
390431 CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
391432
392433 echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -404,7 +445,7 @@ jobs:
404445 if : matrix.platform == 'windows'
405446 shell : pwsh
406447 run : |
407- $PKG_NAME = "crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
448+ $PKG_NAME = "crc-fast-$env:TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
408449 Write-Host "Creating package directory structure for $PKG_NAME..."
409450
410451 New-Item -ItemType Directory -Path "$PKG_NAME/bin" -Force | Out-Null
@@ -425,12 +466,12 @@ jobs:
425466 Copy-Item "target/release/get-custom-params.exe" "$PKG_NAME/bin/"
426467
427468 Write-Host "Creating VERSION file..."
428- "${{ 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
429470
430471 Write-Host "Creating README.txt..."
431472 @"
432473 crc-fast Binary Distribution
433- Version: ${{ github.ref_name }}
474+ Version: $env:TAG_NAME
434475 Platform: Windows ${{ matrix.arch }}
435476
436477 CONTENTS
@@ -492,7 +533,7 @@ jobs:
492533 if : matrix.platform == 'windows'
493534 shell : pwsh
494535 run : |
495- $PKG_NAME = "crc-fast-${{ github.ref_name }} -${{ matrix.platform }}-${{ matrix.arch }}"
536+ $PKG_NAME = "crc-fast-$env:TAG_NAME -${{ matrix.platform }}-${{ matrix.arch }}"
496537 $ARCHIVE_NAME = "${PKG_NAME}.zip"
497538
498539 Write-Host "Creating compressed archive: $ARCHIVE_NAME"
@@ -513,7 +554,7 @@ jobs:
513554 if : matrix.platform == 'windows'
514555 shell : pwsh
515556 run : |
516- $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"
517558 $CHECKSUM_FILE = "${ARCHIVE_NAME}.sha256"
518559
519560 Write-Host "Generating SHA256 checksum for $ARCHIVE_NAME..."
@@ -534,23 +575,25 @@ jobs:
534575 - name : Upload package artifact
535576 uses : actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
536577 with :
537- name : crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
538- 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 }}
539580 if-no-files-found : error
540581 retention-days : 90
541582
542583 - name : Upload checksum artifact
543584 uses : actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
544585 with :
545- name : crc-fast-${{ github.ref_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
546- 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
547588 if-no-files-found : error
548589 retention-days : 90
549590
550591 publish :
551592 name : Publish
552- needs : build
593+ needs : [validate, build]
553594 runs-on : ubuntu-latest
595+ env :
596+ TAG_NAME : ${{ needs.validate.outputs.tag_name }}
554597 steps :
555598 - name : Download all artifacts
556599 uses : actions/download-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
@@ -564,11 +607,11 @@ jobs:
564607 env :
565608 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
566609 run : |
567- echo "Checking if release exists for tag: ${{ github.ref_name }} "
610+ echo "Checking if release exists for tag: $TAG_NAME "
568611
569612 RELEASE_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
570613 -H "Accept: application/vnd.github+json" \
571- "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} ")
614+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME ")
572615
573616 if echo "$RELEASE_DATA" | jq -e '.id' > /dev/null 2>&1; then
574617 RELEASE_ID=$(echo "$RELEASE_DATA" | jq -r '.id')
@@ -596,16 +639,16 @@ jobs:
596639
597640 echo "Verifying all expected files are present..."
598641 EXPECTED_FILES=(
599- "crc-fast-${{ github.ref_name }} -linux-x86_64.tar.gz"
600- "crc-fast-${{ github.ref_name }} -linux-x86_64.tar.gz.sha256"
601- "crc-fast-${{ github.ref_name }} -linux-aarch64.tar.gz"
602- "crc-fast-${{ github.ref_name }} -linux-aarch64.tar.gz.sha256"
603- "crc-fast-${{ github.ref_name }} -macos-aarch64.tar.gz"
604- "crc-fast-${{ github.ref_name }} -macos-aarch64.tar.gz.sha256"
605- "crc-fast-${{ github.ref_name }} -windows-x86_64.zip"
606- "crc-fast-${{ github.ref_name }} -windows-x86_64.zip.sha256"
607- "crc-fast-${{ github.ref_name }} -windows-aarch64.zip"
608- "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"
609652 )
610653
611654 MISSING_FILES=()
@@ -630,7 +673,7 @@ jobs:
630673 uses : softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # pinned commit for 2.4.1
631674 with :
632675 files : release-assets/*
633- draft : false
676+ draft : true
634677 prerelease : false
635678 fail_on_unmatched_files : true
636679 generate_release_notes : true
0 commit comments