Skip to content

Commit

Permalink
handle tag update properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstif committed Oct 29, 2019
1 parent 6e6ee5e commit 23a9053
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GitHub action that adds a lightweight git tag to the current workflow commit.
## Example usage

```yaml
uses: hole19/git-tag-action@v1
uses: hole19/git-tag-action@master
env:
TAG: v1.2.3
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
36 changes: 28 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,38 @@ if [[ -z "${GITHUB_TOKEN}" ]]; then
exit 1
fi

# check if tag already exists
tag_exists="false"
if [ $(git tag -l "$TAG") ]; then
tag_exists="true"
fi

# push the tag to github
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')

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

curl -s -X POST $git_refs_url \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
if $tag_exists
then
# update tag
curl -s -X PATCH "$git_refs_url/tags/$TAG" \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$TAG",
"sha": "$GITHUB_SHA",
"force": true
}
{
"sha": "$GITHUB_SHA",
"force": true
}
EOF
else
# create new tag
curl -s -X POST $git_refs_url \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$TAG",
"sha": "$GITHUB_SHA",
}
EOF
fi

0 comments on commit 23a9053

Please sign in to comment.