Skip to content

Commit 50eddeb

Browse files
Edward-Knightindygreg
authored andcommitted
ci: provide "safe" versions of variables used for Docker image refs
GitHub user and repo names are in the form `^[\w.-]+$`, so we replace any periods as these are meaningful in a URI. The git ref is less restricted and is used in the image tag, so we replace anything outside `[a-z0-9_-]` with `_`. Both values are lowercased. Closes #184.
1 parent 477a991 commit 50eddeb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

.github/workflows/linux.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,27 @@ jobs:
7575
- name: Generate Dockerfiles
7676
run: |
7777
./build-linux.py --make-target empty
78+
repo_name=$(echo "${GITHUB_REPOSITORY,,}" | sed 's|\.|_|g')
79+
git_ref_name=$(echo "${GITHUB_REF_NAME,,}" | sed 's|[^a-z0-9_-]|_|g')
80+
echo "REPO_NAME=${repo_name}" >> "${GITHUB_ENV}"
81+
echo "GIT_REF_NAME=${git_ref_name}" >> "${GITHUB_ENV}"
7882
7983
- name: Build Image
8084
uses: docker/build-push-action@v4
8185
with:
8286
context: .
8387
file: build/${{ matrix.image }}.Dockerfile
84-
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
88+
labels: org.opencontainers.image.source=https://github.com/${{ env.REPO_NAME }}
8589
# Cache from/to the current branch of the current repo as the primary cache key.
8690
# Cache from the default branch of the current repo so branches can have cache hits.
8791
# Cache from the default branch of the canonical repo so forks can have cache hits.
8892
# Ignore errors on cache writes so CI of forks works without a valid GHCR config.
8993
cache-from: |
90-
type=registry,ref=ghcr.io/${{ github.repository }}:${{ matrix.image }}-${{ github.ref_name }}
91-
type=registry,ref=ghcr.io/${{ github.repository }}:${{ matrix.image }}-main
94+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-${{ env.GIT_REF_NAME }}
95+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-main
9296
type=registry,ref=ghcr.io/indygreg/python-build-standalone:${{ matrix.image }}-main
9397
cache-to: |
94-
type=registry,ref=ghcr.io/${{ github.repository }}:${{ matrix.image }}-${{ github.ref_name }},ignore-errors=true
98+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-${{ env.GIT_REF_NAME }},ignore-errors=true
9599
outputs: |
96100
type=docker,dest=build/image-${{ matrix.image }}.tar
97101

0 commit comments

Comments
 (0)