Skip to content

Commit

Permalink
check if tag exists in the remote repo as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cardinalby committed Jul 9, 2020
1 parent 67be507 commit adb9d80
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ if [[ -z "${GITHUB_TOKEN}" ]]; then
exit 1
fi

# check if tag already exists
# get GitHub API endpoints prefix
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')

# check if tag already exists in the cloned repo
tag_exists="false"
if [ $(git tag -l "$TAG") ]; then
tag_exists="true"
fi
else
# check if tag exists in the remote repo
getReferenceStatus=$(curl "$git_refs_url/tags/$TAG" \
-H "Authorization: token $GITHUB_TOKEN" \
--write-out "%{http_code}" -s -o /dev/null)

# push the tag to github
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
if [ "$getReferenceStatus" = '200' ]; then
tag_exists="true"
fi
fi

echo "**pushing tag $tag to repo $GITHUB_REPOSITORY"
echo "**pushing tag $TAG to repo $GITHUB_REPOSITORY"

if $tag_exists
then
Expand All @@ -36,7 +45,7 @@ then
EOF
else
# create new tag
curl -s -X POST $git_refs_url \
curl -s -X POST "$git_refs_url" \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
Expand Down

0 comments on commit adb9d80

Please sign in to comment.