Skip to content

Commit e4e34ed

Browse files
committed
Sanitize branch tags for Docker builds
1 parent e7b6d3b commit e4e34ed

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/setup-java@v4
3030
with:
3131
distribution: temurin
32-
java-version: "21"
32+
java-version: '21'
3333

3434
- name: Cache Maven repository
3535
uses: actions/cache@v4
@@ -66,7 +66,10 @@ jobs:
6666
PRIMARY_TAG="$IMAGE:sha-$SHORT_SHA"
6767
6868
if [[ "${GITHUB_REF_TYPE}" == "branch" ]]; then
69-
SAFE_BRANCH=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-')
69+
SAFE_BRANCH=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g; s/-\{2,\}/-/g; s/^-//; s/-$//')
70+
if [[ -z "$SAFE_BRANCH" ]]; then
71+
SAFE_BRANCH="sha-$SHORT_SHA"
72+
fi
7073
TAGS="$TAGS\n$IMAGE:branch-$SAFE_BRANCH"
7174
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
7275
VERSION=${{ steps.version.outputs.sanitized }}

0 commit comments

Comments
 (0)