88jobs :
99 release :
1010 runs-on : ubuntu-latest
11+ # Grant the workflow write permission to repository contents.
12+ permissions :
13+ contents : write
14+
1115 steps :
12- # Check out the repository code
16+ # 1. Checkout the repository code
1317 - name : Checkout Code
1418 uses : actions/checkout@v3
1519
16- # Cache dependencies (example for Node.js projects)
20+ # 2. Cache dependencies (example for Node.js projects)
1721 - name : Cache Node Modules
1822 uses : actions/cache@v3
1923 with :
@@ -22,38 +26,40 @@ jobs:
2226 restore-keys : |
2327 ${{ runner.os }}-node-
2428
25- # (Optional) Install dependencies if your workflow requires them
29+ # 3. Optionally install dependencies if needed (for example, to build assets)
2630 - name : Install Dependencies
2731 if : exists('package-lock.json')
2832 run : npm ci
2933
30- # Validate and fix the tag name if it matches a 40-character hexadecimal string
34+ # 4. Validate and fix the tag name if it matches a 40-character commit SHA
3135 - id : validate_tag
3236 name : Validate and Fix Tag Name
3337 shell : bash
3438 run : |
35- # Extract tag name from the Git reference
39+ # Extract the tag name from the Git ref (removing 'refs/tags/')
3640 TAG="${GITHUB_REF##*/}"
3741 echo "Original tag: ${TAG}"
3842
39- # If tag is exactly 40 hex characters (looks like a commit SHA), adjust it
43+ # If tag is exactly 40 hex characters (i.e. a commit SHA)
4044 if [[ "${TAG}" =~ ^[0-9a-f]{40}$ ]]; then
45+ # Adjust the tag name: prefix with 'v' and shorten (commonly to 7 chars)
4146 NEW_TAG="v${TAG:0:7}"
4247 echo "Tag appears to be a commit SHA. Adjusting tag to: ${NEW_TAG}"
4348 TAG="${NEW_TAG}"
4449 else
4550 echo "Tag is valid: ${TAG}"
4651 fi
47-
48- # Set the adjusted tag as output for later steps
52+ # Set the (possibly adjusted) tag as output for later steps
4953 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
5054
51- # Create the GitHub release using the validated/adjusted tag
55+ # 5. Create the GitHub release using the validated/adjusted tag
5256 - name : Create Release
5357 uses : actions/create-release@v1
5458 env :
59+ # Using the default GITHUB_TOKEN. If you encounter permission issues in a fork,
60+ # consider using a PAT with the necessary scopes.
5561 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5662 with :
5763 tag_name : ${{ steps.validate_tag.outputs.tag }}
58- release_name : " Release ${{ steps.validate_tag.outputs.tag }}"
59- body : " Changelog for release ${{ steps.validate_tag.outputs.tag }}"
64+ release_name : " Automated release for commit ${{ steps.validate_tag.outputs.tag }}"
65+ body : " Automated release for commit ${{ steps.validate_tag.outputs.tag }}"
0 commit comments