Skip to content

Commit

Permalink
fixes tag if there are no existing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungstudios committed Aug 10, 2022
1 parent 3840ec2 commit 153314e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ LABEL "repository"="https://github.com/anothrNick/github-tag-action"
LABEL "homepage"="https://github.com/anothrNick/github-tag-action"
LABEL "maintainer"="Nick Sjostrom"

COPY entrypoint.sh /entrypoint.sh

RUN apk update && apk add bash git curl jq && npm install -g semver

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
12 changes: 10 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ git fetch --tags
tagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+$"
preTagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$"

tag=""

# get latest tag that looks like a semver (with or without v)
case "$tag_context" in
*repo*)
taglist="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$tagFmt")"
tag="$(semver $taglist | tail -n 1)"
if [ ! -z "$taglist" ]
then
tag="$(semver $taglist | tail -n 1)"
fi

pre_taglist="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$preTagFmt")"
pre_tag="$(semver "$pre_taglist" | tail -n 1)"
;;
*branch*)
taglist="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$tagFmt")"
tag="$(semver $taglist | tail -n 1)"
if [ ! -z "$taglist" ]
then
tag="$(semver $taglist | tail -n 1)"
fi

pre_taglist="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$preTagFmt")"
pre_tag=$(semver "$pre_taglist" | tail -n 1)
Expand Down

0 comments on commit 153314e

Please sign in to comment.