I am trying to check if a specific tag exists in a repository. Here is a simplified version of what I have tried so far.
Attempt 1:
name: Check for Tag
on: push
jobs:
check-tag:
runs-on: ubuntu-latest
steps:
- name: Check for Tag
run: |
TAG="0.1"
if git show-ref --tags --verify --quiet "refs/tags/${TAG}"; then
echo "Tag ${TAG} exists"
else
echo "Tag ${TAG} does not exist"
fi
Output: Tag 0.1 does not exist
However if i execute the following command on CLI, the tag exists
git show-ref --tags --verify
returns an exit code of 0
if the tag has been found.
Attempt 2:
name: Check for Tag
on: push
jobs:
check-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check for Tag
run: |
TAG="0.2"
git show-ref --tags --verify --quiet "refs/tags/${TAG}"
exit_code=$?
echo ${exit_code}
if [[ $exit_code -eq 0 ]]; then
echo "Tag ${TAG} exists"
else
echo "Tag ${TAG} does not exist"
fi
The workflow fails because 0.2
tag does not exist and returns 1 as exit code