1- name : Create Release
1+ name : Create Release on Every Commit
22
33on :
44 push :
5- tags :
6- - " *" # Trigger on any tag pushes
5+ # This will trigger on every commit push on any branch.
6+ branches :
7+ - ' **'
78
89jobs :
910 release :
@@ -12,11 +13,11 @@ jobs:
1213 contents : write
1314
1415 steps :
15- # 1. Checkout the repository code
16+ # 1. Checkout the repository code.
1617 - name : Checkout Code
1718 uses : actions/checkout@v4
1819
19- # 2. Cache Cargo Registry
20+ # 2. Cache Cargo Registry.
2021 - name : Cache Cargo Registry
2122 uses : actions/cache@v3
2223 with :
2526 restore-keys : |
2627 ${{ runner.os }}-cargo-registry-
2728
28- # 3. Cache Cargo Git Repositories
29+ # 3. Cache Cargo Git Repositories.
2930 - name : Cache Cargo Git Repositories
3031 uses : actions/cache@v3
3132 with :
3435 restore-keys : |
3536 ${{ runner.os }}-cargo-git-
3637
37- # 4. Cache Build Artifacts (the target directory)
38+ # 4. Cache Build Artifacts (the target directory).
3839 - name : Cache Build Output
3940 uses : actions/cache@v3
4041 with :
@@ -43,11 +44,11 @@ jobs:
4344 restore-keys : |
4445 ${{ runner.os }}-cargo-target-
4546
46- # 5. Build your project with Cargo in release mode
47+ # 5. Build your project with Cargo in release mode.
4748 - name : Build with Cargo
4849 run : cargo build --release
4950
50- # 6. Locate the compiled binary
51+ # 6. Locate the compiled binary.
5152 - name : Locate Binary File
5253 id : locate_binary
5354 run : |
@@ -61,40 +62,35 @@ jobs:
6162 echo "BINARY_PATH=${binary_path}" >> $GITHUB_ENV
6263 fi
6364
64- # 7. Validate and fix the tag name if it matches a 40-character commit SHA
65- - id : validate_tag
66- name : Validate and Fix Tag Name
65+ # 7. Determine the tag name.
66+ # If the push already is a tag push, respect that tag.
67+ # Otherwise, use the first 7 characters of the commit SHA prefixed with 'v'.
68+ - id : determine_tag
69+ name : Determine Tag Name
6770 shell : bash
6871 run : |
69- # Extract the tag name from the Git ref (removing 'refs/tags/')
70- TAG="${GITHUB_REF##*/}"
71- echo "Original tag: ${TAG}"
72-
73- # If the tag is exactly 40 hex characters (i.e. a commit SHA),
74- # adjust the tag by prefixing it with 'v' and shortening it to 7 characters.
75- if [[ "${TAG}" =~ ^[0-9a-f]{40}$ ]]; then
76- NEW_TAG="v${TAG:0:7}"
77- echo "Tag appears to be a commit SHA. Adjusting tag to: ${NEW_TAG}"
78- TAG="${NEW_TAG}"
72+ if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
73+ TAG="${GITHUB_REF##*/}"
74+ echo "Running on tag push. Using tag: ${TAG}"
7975 else
80- echo "Tag is valid: ${TAG}"
76+ TAG="v${GITHUB_SHA:0:7}"
77+ echo "Not a tag push. Using commit SHA as tag: ${TAG}"
8178 fi
82- # Set the (possibly adjusted) tag as output for later steps
8379 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
8480
85- # 8. Create the GitHub Release using the validated tag
81+ # 8. Create a GitHub Release using the determined tag.
8682 - name : Create GitHub Release
8783 id : create_release
8884 uses : actions/create-release@v1
8985 env :
9086 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9187 with :
92- tag_name : ${{ steps.validate_tag .outputs.tag }}
93- release_name : " Release ${{ steps.validate_tag .outputs.tag }}"
88+ tag_name : ${{ steps.determine_tag .outputs.tag }}
89+ release_name : " Release ${{ steps.determine_tag .outputs.tag }}"
9490 draft : false
9591 prerelease : false
9692
97- # 9. Upload the built binary as a release asset
93+ # 9. Upload the built binary as a release asset.
9894 - name : Upload Release Asset
9995 uses : actions/upload-release-asset@v1
10096 env :
0 commit comments