Skip to content

Commit 85f46b5

Browse files
committed
ci: run build-test-push on all PRs and fix ghcr push auth
Fork PRs previously skipped the build-test-push job entirely, preventing contributors from getting build and test feedback. The GHCR push step used || between independent secrets: BOT_TOKEN || GITHUB_TOKEN and BOT_LOGIN || repository_owner. When only one BOT_* secret was set, credentials became a mismatched pair, causing a denied: denied authentication failure from ghcr.io. Changes: - Remove same-repo restriction from job condition so all PRs run the pipeline. - Use && to ensure both BOT_TOKEN and BOT_LOGIN must exist together to be used; otherwise fall back to the always- available GITHUB_TOKEN + github.repository_owner pair. - Expose BOT_TOKEN and BOT_LOGIN as env vars so they can be evaluated in the if: condition. - Allow GHCR push on fork PRs when bot credentials are available; skip only when GITHUB_TOKEN would be read-only (fork PR without BOT_TOKEN/BOT_LOGIN). - Use github.repository_owner as fallback username instead of github.actor to avoid confusion in org fork scenarios.
1 parent 6c0a19c commit 85f46b5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: pre-commit/action@v1.0.1
2626

2727
build-test-push:
28-
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
28+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'pull_request'
2929
runs-on: ubuntu-latest
3030
needs: pre-commit
3131
permissions:
@@ -62,6 +62,8 @@ jobs:
6262
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
6363
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
6464
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
65+
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
66+
BOT_LOGIN: ${{ secrets.BOT_LOGIN }}
6567
steps:
6668
# Image repo names have to be lowercase.
6769
- name: Lowercase image repository name
@@ -98,8 +100,9 @@ jobs:
98100
REGISTRY_USERNAME: ${{ env.DOCKERHUB_LOGIN }}
99101
run: ./hooks/push
100102
- name: Push Docker Image to GitHub Registry
103+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository || env.BOT_TOKEN && env.BOT_LOGIN
101104
env:
102105
REGISTRY_HOST: ghcr.io
103-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
104-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN || github.repository_owner }}
106+
REGISTRY_TOKEN: ${{ secrets.BOT_LOGIN && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
107+
REGISTRY_USERNAME: ${{ secrets.BOT_TOKEN && secrets.BOT_LOGIN || github.repository_owner }}
105108
run: ./hooks/push

0 commit comments

Comments
 (0)