Skip to content

Commit fd346bf

Browse files
authored
Merge pull request #1 from nimblehq/feature/tag-master-as-latest
Extract correct branch_tag for master branch and tags
2 parents 7ae4541 + 27dc4b2 commit fd346bf

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Branch tag action
22

3-
This action returns the valid docker image tag name by extracting the branch from branch name or tag ref and replacing `/` by `-` using [Shell Parameter Expansion](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html)
3+
This action returns the valid docker image tag name by extracting the branch from branch or tag ref and replacing `/` by `-` using [Shell Parameter Expansion](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html)
44

55
```
6-
#refs/heads/feature/add-new-action -> feature-add-new-action
6+
refs/heads/feature/add-new-action -> feature-add-new-action
7+
refs/tags/1.0.0 -> 1.0.0
8+
refs/heads/master -> latest
79
```
810

911
## Inputs

entrypoint.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#!/bin/sh -l
22

3-
BRANCH_NAME="${1#refs/heads/}"
3+
REF="${1#refs/}"
4+
BRANCH_NAME="${REF#heads/}"
5+
TAG_NAME="${REF#tags/}"
46

5-
# shellcheck disable=SC2039
6-
BRANCH_TAG="${BRANCH_NAME/\//-}"
7+
if [[ $BRANCH_NAME == master ]]; then
8+
BRANCH_TAG=latest
9+
elif [[ $TAG_NAME != $REF ]]; then
10+
BRANCH_TAG=$TAG_NAME
11+
else
12+
BRANCH_TAG="${BRANCH_NAME//\//-}"
13+
fi
714

815
echo "::set-env name=BRANCH_TAG::$BRANCH_TAG"
916
echo "::set-output name=branch_tag::$BRANCH_TAG"

0 commit comments

Comments
 (0)