55 tags :
66 - " v*"
77 workflow_dispatch :
8+ inputs :
9+ tag_version :
10+ description : ' Tag version (e.g., v1.0.0 or leave empty to use git tag)'
11+ required : false
12+ default : ' '
813
914jobs :
1015 release :
1520 pull-requests : write
1621
1722 steps :
23+ - name : Determine tag version
24+ id : tag
25+ shell : bash
26+ run : |
27+ if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag_version }}" ]]; then
28+ TAG_VERSION="${{ github.event.inputs.tag_version }}"
29+ # Ensure tag starts with 'v'
30+ if [[ ! "$TAG_VERSION" =~ ^v ]]; then
31+ TAG_VERSION="v${TAG_VERSION}"
32+ fi
33+ elif [[ "${{ github.event_name }}" == "push" ]]; then
34+ TAG_VERSION="${{ github.ref_name }}"
35+ else
36+ echo "Error: No tag version provided"
37+ exit 1
38+ fi
39+
40+ # Validate tag format (e.g., v1.0.0)
41+ if [[ ! "$TAG_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42+ echo "Error: Invalid tag format. Expected vX.Y.Z, got $TAG_VERSION"
43+ exit 1
44+ fi
45+
46+ echo "tag_version=${TAG_VERSION}" >> $GITHUB_OUTPUT
47+ echo "Tag version: ${TAG_VERSION}"
48+
1849 - name : Checkout repository
1950 uses : actions/checkout@v4
51+ with :
52+ fetch-depth : 0
2053
2154 # https://github.com/marketplace/actions/setup-xcode-version
2255 # https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md#xcode
4780 shell : bash
4881 run : |
4982 set -eo pipefail
83+ TAG_VERSION="${{ steps.tag.outputs.tag_version }}"
5084 APP_PATH="build/Build/Products/Release/Volume Grid.app"
5185 if [[ ! -d "${APP_PATH}" ]]; then
5286 echo "Expected app bundle not found at ${APP_PATH}"
@@ -62,23 +96,25 @@ jobs:
6296 --icon-size 100 \
6397 --icon "Volume Grid.app" 150 200 \
6498 --app-drop-link 450 200 \
65- "VolumeGrid-${GITHUB_REF_NAME }.dmg" \
99+ "VolumeGrid-${TAG_VERSION }.dmg" \
66100 "${TMP_DIR}"
67101
68102 rm -rf "${TMP_DIR}"
69103
70104 - name : Calculate SHA256
71105 shell : bash
72106 run : |
73- SHA256=$(shasum -a 256 "VolumeGrid-${GITHUB_REF_NAME}.dmg" | awk '{print $1}')
107+ TAG_VERSION="${{ steps.tag.outputs.tag_version }}"
108+ SHA256=$(shasum -a 256 "VolumeGrid-${TAG_VERSION}.dmg" | awk '{print $1}')
74109 echo "DMG_SHA256=${SHA256}" >> $GITHUB_ENV
75110 echo "SHA256 Hash: ${SHA256}"
76111
77112 - name : Extract changelog
78113 id : changelog
79114 shell : bash
80115 run : |
81- VERSION="${GITHUB_REF_NAME#v}"
116+ TAG_VERSION="${{ steps.tag.outputs.tag_version }}"
117+ VERSION="${TAG_VERSION#v}"
82118 echo "Extracting changelog for version: $VERSION"
83119
84120 # Extract changelog content for this version
@@ -94,13 +130,13 @@ jobs:
94130 echo "$CHANGELOG"
95131
96132 - name : Create annotated tag with changelog
97- if : startsWith( github.ref, 'refs/tags/v')
133+ if : github.event_name == 'workflow_dispatch'
98134 shell : bash
99135 env :
100136 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
101137 run : |
102- VERSION ="${GITHUB_REF_NAME#v }"
103- TAG_NAME ="${GITHUB_REF_NAME }"
138+ TAG_VERSION ="${{ steps.tag.outputs.tag_version } }"
139+ VERSION ="${TAG_VERSION#v }"
104140
105141 # Get the changelog content
106142 CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '1d;$d')
@@ -111,28 +147,28 @@ jobs:
111147 git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
112148
113149 # Create annotated tag with changelog if it doesn't exist
114- if ! git rev-parse "$TAG_NAME " >/dev/null 2>&1; then
115- git tag -a "$TAG_NAME " -m "Release $TAG_NAME " -m "$CHANGELOG"
116- git push origin "$TAG_NAME "
150+ if ! git rev-parse "$TAG_VERSION " >/dev/null 2>&1; then
151+ git tag -a "$TAG_VERSION " -m "Release $TAG_VERSION " -m "$CHANGELOG"
152+ git push origin "$TAG_VERSION "
117153 echo "Annotated tag created and pushed with changelog"
118154 else
119- echo "Tag $TAG_NAME already exists, skipping tag creation"
155+ echo "Tag $TAG_VERSION already exists, skipping tag creation"
120156 fi
121157
122158 - name : Update cask file
123- if : startsWith(github.ref, 'refs/tags/v')
124159 shell : bash
125160 run : |
126- VERSION="${GITHUB_REF_NAME#v}"
161+ TAG_VERSION="${{ steps.tag.outputs.tag_version }}"
162+ VERSION="${TAG_VERSION#v}"
127163 sed -i '' "s/version \".*\"/version \"${VERSION}\"/" Casks/volume-grid.rb
128164 sed -i '' "s/sha256 \".*\"/sha256 \"${DMG_SHA256}\"/" Casks/volume-grid.rb
129165
130166 - name : Commit and push cask updates
131- if : startsWith(github.ref, 'refs/tags/v')
132167 shell : bash
133168 env :
134169 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
135170 run : |
171+ TAG_VERSION="${{ steps.tag.outputs.tag_version }}"
136172 git config user.name "github-actions[bot]"
137173 git config user.email "github-actions[bot]@users.noreply.github.com"
138174 git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
@@ -142,24 +178,24 @@ jobs:
142178 if git diff-index --quiet HEAD --; then
143179 echo "No changes to commit"
144180 else
145- git commit -m "chore: update cask version and sha256 for ${GITHUB_REF_NAME }"
181+ git commit -m "chore: update cask version and sha256 for ${TAG_VERSION }"
146182 git push origin main
147183 fi
148184
149185 - name : Upload build artifact
150186 uses : actions/upload-artifact@v4
151187 with :
152- name : VolumeGrid-${{ github.ref_name }}-app
153- path : VolumeGrid-${{ github.ref_name }}.dmg
188+ name : VolumeGrid-${{ steps.tag.outputs.tag_version }}-app
189+ path : VolumeGrid-${{ steps.tag.outputs.tag_version }}.dmg
154190
155191 - name : Publish GitHub release
156- if : startsWith( github.ref, 'refs/tags/v')
192+ if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
157193 uses : softprops/action-gh-release@v1
158194 with :
159- tag_name : ${{ github.ref_name }}
160- name : ${{ github.ref_name }}
195+ tag_name : ${{ steps.tag.outputs.tag_version }}
196+ name : ${{ steps.tag.outputs.tag_version }}
161197 body : ${{ steps.changelog.outputs.content }}
162- files : VolumeGrid-${{ github.ref_name }}.dmg
198+ files : VolumeGrid-${{ steps.tag.outputs.tag_version }}.dmg
163199 generate_release_notes : false
164200 env :
165201 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments