Skip to content

Commit

Permalink
fix: do not leave temporary tag when deployment fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Dec 22, 2024
1 parent 5234a74 commit 45c2c28
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/commit-changelog-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ jobs:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
if git rev-parse ${{ inputs.version-tag }} >/dev/null 2>&1; then
echo 'Tag ${{ inputs.version-tag }} already exists. Exiting...'
exit 1
fi
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
git tag -a ${{ inputs.version-tag }} -m "Temporary tag from workflow. REMOVE ME!"
git push --tags
- name: Get CHANGELOG
Expand All @@ -48,10 +53,14 @@ jobs:
echo '${{ steps.changelog-dry-run.outputs.changes }}'
echo '${{ steps.changelog-dry-run.outputs.changes }}' > "$GITHUB_STEP_SUMMARY"
- name: Remove temporary version tag
- name: Remove temporary version tag (even if changelog fails to generate)
if: always()
run: |
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
# if the tag message says "Temporary tag from workflow. REMOVE ME!", then remove it
if git show ${{ inputs.version-tag }} | grep -q "Temporary tag from workflow. REMOVE ME!"; then
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
fi
deploy:
if: ${{ inputs.dry-run == false }}
Expand All @@ -61,9 +70,14 @@ jobs:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
if git rev-parse ${{ inputs.version-tag }} >/dev/null 2>&1; then
echo 'Tag ${{ inputs.version-tag }} already exists. Exiting...'
exit 1
fi
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
git tag -a ${{ inputs.version-tag }} -m "Temporary tag from workflow. REMOVE ME!"
git push --tags
- name: Update CHANGELOG
Expand All @@ -76,10 +90,17 @@ jobs:
tag: ${{ inputs.version-tag }}
changelogFilePath: ${{ inputs.changelog-path }}

- name: Remove temporary version tag (even if changelog fails to generate)
if: always()
run: |
# if the tag message says "Temporary tag from workflow. REMOVE ME!", then remove it
if git show ${{ inputs.version-tag }} | grep -q "Temporary tag from workflow. REMOVE ME!"; then
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
fi
- name: Commit ${{ inputs.changelog-path }} and update tag
run: |
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
git add ${{ inputs.changelog-path }}
git commit -m "docs: update ${{ inputs.changelog-path }} for ${{ inputs.version-tag }} [skip ci]"
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
Expand Down

0 comments on commit 45c2c28

Please sign in to comment.