Skip to content

Commit 3e4b18f

Browse files
committed
ci: properly sanitize branch names for docker tags instead of hardcoding
1 parent 4a9f58e commit 3e4b18f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
timeout-minutes: 30
5555
needs: check-changes
5656
if: needs.check-changes.outputs.source-changed == 'true'
57+
outputs:
58+
sanitized-branch: ${{ steps.branch.outputs.sanitized }}
5759
strategy:
5860
fail-fast: false
5961
matrix:
@@ -76,6 +78,13 @@ jobs:
7678
- name: Set up Docker Buildx
7779
uses: docker/setup-buildx-action@v3
7880

81+
- name: Sanitize branch name
82+
id: branch
83+
run: |
84+
BRANCH_NAME="${{ github.ref_name }}"
85+
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9.-]/-/g')
86+
echo "sanitized=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT
87+
7988
- name: Log in to GitHub Container Registry
8089
uses: docker/login-action@v3
8190
with:
@@ -89,7 +98,7 @@ jobs:
8998
with:
9099
images: ghcr.io/nvidia/cutile-python/ci-py${{ matrix.python-version }}
91100
tags: |
92-
type=sha,prefix={{branch}}-
101+
type=sha,prefix=${{ steps.branch.outputs.sanitized }}-
93102
94103
- name: Check disk space before build
95104
run: df -h
@@ -143,7 +152,7 @@ jobs:
143152
if: needs.check-changes.outputs.source-changed == 'true'
144153
timeout-minutes: 30
145154
container:
146-
image: ghcr.io/nvidia/cutile-python/ci-py${{ matrix.python-version }}:${{ github.ref_name }}-${{ github.sha }}
155+
image: ghcr.io/nvidia/cutile-python/ci-py${{ matrix.python-version }}:pull-request-1-${{ github.sha }}
147156
credentials:
148157
username: ${{ github.actor }}
149158
password: ${{ secrets.GITHUB_TOKEN }}
@@ -176,7 +185,7 @@ jobs:
176185
if: always() && (needs.check-changes.outputs.source-changed == 'true' || needs.check-changes.outputs.docs-changed == 'true')
177186
timeout-minutes: 15
178187
container:
179-
image: ghcr.io/nvidia/cutile-python/ci-py3.10:${{ github.ref_name }}-${{ github.sha }}
188+
image: ghcr.io/nvidia/cutile-python/ci-py3.10:${{ needs.build-ci-images.outputs.sanitized-branch }}-${{ github.sha }}
180189
credentials:
181190
username: ${{ github.actor }}
182191
password: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)