Skip to content

Commit 7f8780c

Browse files
chakru-resteban
authored andcommitted
build: support tag computation from branch with slash in name (#13636)
1 parent 8f7f6de commit 7f8780c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

.github/scripts/docker_helpers.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ export SHORT_SHA=$(get_short_sha)
1414
echo "SHORT_SHA: $SHORT_SHA"
1515

1616
function get_tag {
17-
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG},g" -e 's,refs/tags/,,g' -e 's,refs/heads/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g')
17+
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG},g" -e 's,refs/tags/,,g' -e 's,refs/heads/,,g' -e 's,refs/heads/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g' -e 's,/,-,g')
1818
}
1919

2020
function get_tag_slim {
21-
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g')
21+
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g' -e 's,/,-,g')
2222
}
2323

2424
function get_tag_full {
25-
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g')
25+
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g' -e 's,/,-,g')
2626
}
2727

2828
function get_python_docker_release_v() {
2929
echo "$(echo "${GITHUB_REF}" | \
3030
sed -e "s,refs/heads/${MAIN_BRANCH},1\!0.0.0+docker.${SHORT_SHA},g" \
31+
-e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \
3132
-e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \
3233
-e 's,refs/tags/v\([0-9a-zA-Z.]*\).*,\1+docker,g' \
3334
-e 's,refs/pull/\([0-9]*\).*,1!0.0.0+docker.pr\1,g' \
35+
-e 's,/,-,g'
3436
)"
3537
}
3638
# To run these, set TEST_DOCKER_HELPERS=1 and then copy the function + test cases into a bash shell.
@@ -40,6 +42,23 @@ if [ ${TEST_DOCKER_HELPERS:-0} -eq 1 ]; then
4042
GITHUB_REF="refs/tags/v0.1.2.1-test" get_python_docker_release_v # '0.1.2.1'
4143
GITHUB_REF="refs/tags/v0.1.2rc1-test" get_python_docker_release_v # '0.1.2rc1'
4244
GITHUB_REF="refs/heads/branch-name" get_python_docker_release_v # '1!0.0.0+docker.branch-name'
45+
GITHUB_REF="refs/heads/releases/branch-name" get_python_docker_release_v # 1!0.0.0+docker.releases-branch-name'
46+
47+
GITHUB_REF="refs/tags/v0.1.2rc1" get_tag # '0.1.2rc1'
48+
GITHUB_REF="refs/tags/v0.1.2rc1" get_tag_slim # '0.1.2rc1-slim'
49+
GITHUB_REF="refs/tags/v0.1.2rc1" get_tag_full # '0.1.2rc1-full'
50+
51+
GITHUB_REF="refs/pull/4788/merge" get_tag # 'pr4788'
52+
GITHUB_REF="refs/pull/4788/merge" get_tag_slim # 'pr4788-slim'
53+
GITHUB_REF="refs/pull/4788/merge" get_tag_full # 'pr4788-full'
54+
55+
GITHUB_REF="refs/heads/branch-name" get_tag # 'branch-name'
56+
GITHUB_REF="refs/heads/branch-name" get_tag_slim # 'branch-name-slim'
57+
GITHUB_REF="refs/heads/branch-name" get_tag_full # 'branch-name-full'
58+
59+
GITHUB_REF="refs/heads/releases/branch-name" get_tag # 'releases-branch-name'
60+
GITHUB_REF="refs/heads/releases/branch-name" get_tag_slim # 'releases-branch-name-slim'
61+
GITHUB_REF="refs/heads/releases/branch-name" get_tag_full # 'releases-branch-name-full'
4362
fi
4463

4564
function get_unique_tag {

0 commit comments

Comments
 (0)