From 4dbb647fef8258663e2f80d68058f77d552132e7 Mon Sep 17 00:00:00 2001 From: Cam Hutchison Date: Tue, 28 Nov 2023 11:57:23 +1100 Subject: [PATCH] Sanitize version/ref_name for use as docker label Docker labels/tags can contain only alphanumeric chars, underscores, periods and hyphens and must start with alphanumeric or underscores. So we convert all invalid chars to hyphens and strip leading invalid chars. Also collapse runs of hyphens to a single hyphen. Technically we do not need to strip the leading chars as we construct the label with the version as a suffix, but it would look a little weird if we didn't and allows us to use the version as a pure tag if we want to later. --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 514da8c..d6d6273 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -40,6 +40,7 @@ jobs: echo "No version or ref_name set" >&2 exit 1 fi + V="$(echo "$V" | sed -e 's/[^A-Za-z0-9_.-]/-/g' -e 's/--*/-/g' -e 's/^[^A-Za-z0-9_]*//')" echo "V=$V" >> "$GITHUB_ENV" - name: Assume AWS ECR Push Role uses: aws-actions/configure-aws-credentials@010d0da01d0b5a38af31e9c3470dbfdabdecca3a # v4.0.1