From 45c2c2895756b4573bb23dff199e8d56cfbe42c0 Mon Sep 17 00:00:00 2001 From: Kiyoon Kim Date: Sun, 22 Dec 2024 09:13:17 +0900 Subject: [PATCH] fix: do not leave temporary tag when deployment fails --- .../commit-changelog-and-release.yml | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/commit-changelog-and-release.yml b/.github/workflows/commit-changelog-and-release.yml index f60531f..d607ae5 100644 --- a/.github/workflows/commit-changelog-and-release.yml +++ b/.github/workflows/commit-changelog-and-release.yml @@ -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 @@ -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 }} @@ -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 @@ -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 }}