Skip to content

Commit 6180818

Browse files
committed
refactor(git-push): make push and tag atomic
1 parent d914fac commit 6180818

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

release-git-push/action.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,29 @@ runs:
2020
steps:
2121
- name: Push git version
2222
shell: bash
23+
env:
24+
TAG: ${{ inputs.version }}
2325
run: |
26+
set -euo pipefail
2427
git config user.name "${{ inputs.git-user-name }}"
2528
git config user.email "${{ inputs.git-user-email }}"
2629
git add ${{ inputs.git-add-files }}
27-
# check if there are no changes at all
30+
31+
# Check if there are changes to commit
2832
if [ -z "$(git status --porcelain)" ]; then
2933
echo "No changes to commit"
30-
# check if current commit has no tag at all
34+
35+
# Check if current commit has no tag at all
3136
if [ -z "$(git tag --points-at HEAD)" ]; then
32-
git tag v${{ inputs.version }}
33-
git push origin HEAD v${{ inputs.version }}
37+
echo "Creating and pushing tag ${TAG}"
38+
git tag "${TAG}"
39+
git push --atomic origin HEAD "${TAG}"
3440
else
3541
echo "A tag already exists for this commit"
3642
fi
3743
else
38-
git commit -m "chore: bump version to v${{ inputs.version }}" -m "[skip ci]"
39-
git tag v${{ inputs.version }}
40-
git push origin HEAD v${{ inputs.version }}
44+
echo "Committing changes and pushing"
45+
git commit -m "chore: bump version to ${TAG}" -m "[skip ci]"
46+
git tag "${TAG}"
47+
git push --atomic origin HEAD "${TAG}"
4148
fi

0 commit comments

Comments
 (0)