Skip to content

Commit 05b9600

Browse files
committed
ci: harden release workflow idempotency and push semantics
1 parent 0789607 commit 05b9600

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

.github/workflows/release-on-main.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ EOF
187187
run: |
188188
set -euo pipefail
189189
CURRENT=$(node -p "require('./package.json').version")
190-
NEXT=$(node -e "const v='${CURRENT}'.split('.').map(Number); if('${BUMP}'==='minor'){v[1]++; v[2]=0;} else {v[2]++;} process.stdout.write(v.join('.')); ")
191-
node -e "const fs=require('fs'); const p='package.json'; const j=JSON.parse(fs.readFileSync(p,'utf8')); j.version='${NEXT}'; fs.writeFileSync(p, JSON.stringify(j,null,2)+'\\n');"
190+
NEXT=$(node -e "const v=process.argv[1].split('.').map(Number); if(process.argv[2]==='minor'){v[1]++; v[2]=0;} else {v[2]++;} process.stdout.write(v.join('.'))" -- "${CURRENT}" "${BUMP}")
191+
node -e "const fs=require('fs'); const p='package.json'; const j=JSON.parse(fs.readFileSync(p,'utf8')); j.version=process.argv[1]; fs.writeFileSync(p, JSON.stringify(j,null,2)+'\\n');" -- "${NEXT}"
192192
if [ -f package-lock.json ]; then
193193
npm install --package-lock-only --ignore-scripts
194194
fi
@@ -197,28 +197,30 @@ EOF
197197
echo "tag=v${NEXT}" >> "$GITHUB_OUTPUT"
198198
199199
- name: Check tag does not already exist
200+
id: tag_check
200201
if: steps.bump.outputs.tag != '' && steps.dryrun.outputs.enabled != 'true'
201202
env:
202203
TAG: ${{ steps.bump.outputs.tag }}
203204
run: |
204205
if git rev-parse "$TAG" >/dev/null 2>&1; then
205206
echo "Tag already exists: $TAG. Skipping to keep idempotent."
206-
exit 0
207+
echo "exists=true" >> "$GITHUB_OUTPUT"
208+
else
209+
echo "exists=false" >> "$GITHUB_OUTPUT"
207210
fi
208211
209212
- name: Commit and tag
210-
if: steps.bump.outputs.tag != '' && steps.dryrun.outputs.enabled != 'true' && steps.dryrun.outputs.enabled != 'true'
213+
if: steps.bump.outputs.tag != '' && steps.dryrun.outputs.enabled != 'true' && steps.tag_check.outputs.exists != 'true'
211214
env:
212215
TAG: ${{ steps.bump.outputs.tag }}
213216
run: |
214217
set -euo pipefail
215218
git config user.name "github-actions[bot]"
216219
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
217220
git add package.json package-lock.json || true
218-
git commit -m "release: ${TAG}"
221+
git commit -m "release: ${TAG} [skip release]"
219222
git tag "$TAG"
220-
git push origin main
221-
git push origin "$TAG"
223+
git push --atomic origin main "$TAG"
222224
223225
- name: Build changelog markdown
224226
id: changelog

0 commit comments

Comments
 (0)