4646 with :
4747 fetch-depth : 0
4848 fetch-tags : true
49+ ref : ${{ github.event.repository.default_branch }}
4950
5051 - name : Tag - Validate and parse version
5152 id : version
@@ -63,60 +64,106 @@ jobs:
6364 id : check-tag
6465 run : |
6566 TAG="${{ steps.version.outputs.version }}"
67+ RELEASE_NAME="${{ steps.version.outputs.release_name }}"
6668 if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then
6769 TAG_SHA=$(git rev-parse "refs/tags/${TAG}^{commit}" 2>/dev/null || git rev-parse "refs/tags/${TAG}")
68- echo "tag_exists=true" >> $GITHUB_OUTPUT
69- echo "tag_sha=${TAG_SHA}" >> $GITHUB_OUTPUT
7070 echo "ℹ️ Tag ${TAG} already exists at commit ${TAG_SHA:0:8}"
71+
72+ # Verify version-bearing files at the tagged commit match the release
73+ TAG_SERVER_VERSION=$(git show "${TAG_SHA}:server/package.json" \
74+ | grep -m1 '"version"' \
75+ | sed 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
76+ if [[ "${TAG_SERVER_VERSION}" == "${RELEASE_NAME}" ]]; then
77+ echo "tag_exists=true" >> $GITHUB_OUTPUT
78+ echo "tag_sha=${TAG_SHA}" >> $GITHUB_OUTPUT
79+ echo "✅ Existing tag ${TAG} has correct version (${RELEASE_NAME})"
80+ else
81+ echo "⚠️ Version mismatch at tag ${TAG}: found ${TAG_SERVER_VERSION}, expected ${RELEASE_NAME}"
82+ echo " Removing stale tag to recreate with correct versions..."
83+ git tag -d "${TAG}" 2>/dev/null || true
84+ git push origin ":refs/tags/${TAG}" 2>/dev/null || true
85+ echo "tag_exists=false" >> $GITHUB_OUTPUT
86+ echo "ℹ️ Stale tag ${TAG} removed — will recreate with updated versions"
87+ fi
7188 else
7289 echo "tag_exists=false" >> $GITHUB_OUTPUT
7390 echo "ℹ️ Tag ${TAG} does not exist yet"
7491 fi
7592
93+ - name : Tag - Validate versions at existing tag
94+ id : validate-tag
95+ if : steps.check-tag.outputs.tag_exists == 'true'
96+ run : |
97+ TAG="${{ steps.version.outputs.version }}"
98+ RELEASE_NAME="${{ steps.version.outputs.release_name }}"
99+ echo "Validating version consistency at existing tag ${TAG}..."
100+
101+ # Check out the tagged commit to inspect version files
102+ git checkout "refs/tags/${TAG}"
103+
104+ if ./server/scripts/update-release-version.sh --check "${RELEASE_NAME}"; then
105+ echo "tag_valid=true" >> $GITHUB_OUTPUT
106+ echo "✅ Existing tag has correct versions"
107+ else
108+ echo "tag_valid=false" >> $GITHUB_OUTPUT
109+ echo ""
110+ echo "⚠️ Existing tag ${TAG} has incorrect versions."
111+ echo "Deleting tag and recreating with correct versions..."
112+
113+ # Return to the original branch
114+ git checkout -
115+
116+ # Delete the remote and local tag so it can be recreated
117+ git push --delete origin "${TAG}" || true
118+ git tag -d "${TAG}" || true
119+
120+ echo "🗑️ Deleted tag ${TAG} — will recreate with correct versions"
121+ fi
122+
76123 - name : Tag - Setup CodeQL environment
77- if : steps.check-tag.outputs.tag_exists != 'true'
124+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
78125 uses : ./.github/actions/setup-codeql-environment
79126 with :
80127 add-to-path : true
81128 install-language-runtimes : false
82129
83130 - name : Tag - Setup Node.js
84- if : steps.check-tag.outputs.tag_exists != 'true'
131+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
85132 uses : actions/setup-node@v6
86133 with :
87134 cache : ' npm'
88135 node-version-file : ' .node-version'
89136
90137 - name : Tag - Update release version
91- if : steps.check-tag.outputs.tag_exists != 'true'
138+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
92139 run : |
93140 TAG_VERSION="${{ steps.version.outputs.release_name }}"
94141 echo "Updating all version-bearing files to '${TAG_VERSION}'..."
95142 ./server/scripts/update-release-version.sh "${TAG_VERSION}"
96143
97144 - name : Tag - Install dependencies
98- if : steps.check-tag.outputs.tag_exists != 'true'
145+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
99146 run : npm install --include=optional
100147
101148 - name : Tag - Install CodeQL pack dependencies
102- if : steps.check-tag.outputs.tag_exists != 'true'
149+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
103150 run : server/scripts/install-packs.sh
104151
105152 - name : Tag - Tidy (lint and format)
106- if : steps.check-tag.outputs.tag_exists != 'true'
153+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
107154 run : npm run tidy
108155
109156 - name : Tag - Build server
110- if : steps.check-tag.outputs.tag_exists != 'true'
157+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
111158 run : npm run build -w server
112159
113160 - name : Tag - Run tests
114- if : steps.check-tag.outputs.tag_exists != 'true'
161+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
115162 run : npm run test:server
116163
117164 - name : Tag - Commit version changes and create tag
118165 id : create-tag
119- if : steps.check-tag.outputs.tag_exists != 'true'
166+ if : steps.check-tag.outputs.tag_exists != 'true' || steps.validate-tag.outputs.tag_valid == 'false'
120167 run : |
121168 TAG="${{ steps.version.outputs.version }}"
122169 RELEASE_NAME="${{ steps.version.outputs.release_name }}"
@@ -150,14 +197,14 @@ jobs:
150197
151198 - name : Tag - Output existing tag SHA
152199 id : existing-tag
153- if : steps.check-tag.outputs.tag_exists == 'true'
200+ if : steps.check-tag.outputs.tag_exists == 'true' && steps.validate-tag.outputs.tag_valid != 'false'
154201 run : |
155202 echo "tag_sha=${{ steps.check-tag.outputs.tag_sha }}" >> $GITHUB_OUTPUT
156203
157204 - name : Tag - Set final tag SHA output
158205 id : final-sha
159206 run : |
160- if [ "${{ steps.check-tag.outputs.tag_exists }}" == "true" ]; then
207+ if [ "${{ steps.check-tag.outputs.tag_exists }}" == "true" ] && [ "${{ steps.validate-tag.outputs.tag_valid }}" != "false" ] ; then
161208 SHA="${{ steps.check-tag.outputs.tag_sha }}"
162209 else
163210 SHA="${{ steps.create-tag.outputs.tag_sha }}"
@@ -169,7 +216,7 @@ jobs:
169216 TAG="${{ steps.version.outputs.version }}"
170217 echo "## Release Tag Summary" >> $GITHUB_STEP_SUMMARY
171218 echo "" >> $GITHUB_STEP_SUMMARY
172- if [ "${{ steps.check-tag.outputs.tag_exists }}" == "true" ]; then
219+ if [ "${{ steps.check-tag.outputs.tag_exists }}" == "true" ] && [ "${{ steps.validate-tag.outputs.tag_valid }}" != "false" ] ; then
173220 echo "ℹ️ Tag \`${TAG}\` already existed at \`${{ steps.check-tag.outputs.tag_sha }}\`" >> $GITHUB_STEP_SUMMARY
174221 else
175222 echo "✅ Created tag \`${TAG}\` at \`${{ steps.create-tag.outputs.tag_sha }}\`" >> $GITHUB_STEP_SUMMARY
0 commit comments