Skip to content

Commit 977407a

Browse files
committed
ci: drop FranzDiebold/github-env-vars-action #9641
This drops the `FranzDiebold/github-env-vars-action` in favor of native GH-Actions replacement patterns available. ghcr.io (and other container registries for that matter) do not allow mix-case image names, so when a the repo is forked by a user with a mixed case username, or when reused in a repo with a mixed case repo name, the Docker image tagging step fails. To fix this, there is now a custom bash step that saves the lowercase username and repo-name to the step-output, and reuse them in tagging steps. This is essentially what `FranzDiebold/github-env-vars-action` action did, but doing so manually allows more control and visibility, as well as dropping an action that reduces surface area if the third party action is comproised. Related: [#9639](http://team.linkorb.com/cards/9639).
1 parent 841489e commit 977407a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

.github/workflows/production.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ jobs:
2020
- php8
2121

2222
steps:
23-
- name: GitHub Environment Variables Action
24-
uses: FranzDiebold/github-env-vars-action@v2
23+
- name: Convert repository name and owner to lowercase
24+
id: repo_info
25+
shell: bash
26+
run: |
27+
REPO_FULL_NAME="${{ github.repository }}"
28+
OWNER_LOWER=$(echo "$REPO_FULL_NAME" | cut -d'/' -f1 | tr '[:upper:]' '[:lower:]')
29+
REPO_LOWER=$(echo "$REPO_FULL_NAME" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
30+
31+
echo "CI_REPOSITORY_OWNER_SLUG=$OWNER_LOWER" >> "$GITHUB_OUTPUT"
32+
echo "CI_REPOSITORY_NAME_SLUG=$REPO_LOWER" >> "$GITHUB_OUTPUT"
33+
echo "CI_REPOSITORY_FULL_NAME_SLUG=${OWNER_LOWER}/${REPO_LOWER}" >> "$GITHUB_OUTPUT"
2534
2635
- name: Shallow clone code
2736
uses: actions/checkout@v4
@@ -32,7 +41,7 @@ jobs:
3241
uses: docker/login-action@v3
3342
with:
3443
registry: ghcr.io
35-
username: ${{ env.CI_REPOSITORY_OWNER_SLUG }}
44+
username: ${{ github.repository_owner }} #ghcr logins allow mixed case usernames
3645
password: ${{ secrets.GITHUB_TOKEN }}
3746

3847
- name: Build the container image
@@ -49,35 +58,33 @@ jobs:
4958
severity: 'CRITICAL,HIGH'
5059

5160
- name: Retag new image with latest tag so we can push the scanned version
52-
run: docker image tag php-docker-base:trivytemp ghcr.io/${{ env.CI_REPOSITORY_OWNER_SLUG }}/${{ env.CI_REPOSITORY_NAME }}:${{ matrix.php }}
61+
run: docker image tag php-docker-base:trivytemp ghcr.io/${{ steps.repo_info.outputs.CI_REPOSITORY_FULL_NAME_SLUG }}:${{ matrix.php }}
5362

5463
- name: Push with commit ${{ matrix.php }} tag
55-
run: docker push ghcr.io/${{ env.CI_REPOSITORY_OWNER_SLUG }}/${{ env.CI_REPOSITORY_NAME }}:${{ matrix.php }}
64+
run: docker push ghcr.io/${{ steps.repo_info.outputs.CI_REPOSITORY_FULL_NAME_SLUG }}:${{ matrix.php }}
5665

5766
#review containers
5867
- name: Build the review container image
59-
run: docker build . --tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:${{ matrix.php }}-review --file Dockerfile.${{ matrix.php }}-review
60-
- name: Push with commit *-review tag
61-
run: docker push ghcr.io/${{ env.CI_REPOSITORY_OWNER_SLUG }}/${{ env.CI_REPOSITORY_NAME }}:${{ matrix.php }}-review
68+
run: docker build . --tag ghcr.io/${{ steps.repo_info.outputs.CI_REPOSITORY_FULL_NAME_SLUG }}:${{ matrix.php }}-review --file Dockerfile.${{ matrix.php }}-review
6269

70+
- name: Push with commit *-review tag
71+
run: docker push ghcr.io/${{ steps.repo_info.outputs.CI_REPOSITORY_FULL_NAME_SLUG }}:${{ matrix.php }}-review
6372

6473
cleanup:
6574
needs: [build]
6675
runs-on: ubuntu-latest
6776
steps:
68-
- name: GitHub Environment Variables Action
69-
uses: FranzDiebold/github-env-vars-action@v2
7077

7178
- name: Login to Container Registry ghcr.io
7279
uses: docker/login-action@v3
7380
with:
7481
registry: ghcr.io
75-
username: ${{ env.CI_REPOSITORY_OWNER_SLUG }}
82+
username: ${{ github.repository_owner }} #ghcr logins allow mixed case usernames
7683
password: ${{ secrets.GITHUB_TOKEN }}
7784

7885
- name: Delete old versions of the package, keeping a few of the newest
7986
uses: actions/delete-package-versions@v5
8087
with:
81-
package-name: ${{ env.CI_REPOSITORY_NAME }}
88+
package-name: ${{ github.event.repository.name }}
8289
package-type: container
8390
min-versions-to-keep: 8

0 commit comments

Comments
 (0)