Skip to content

gh-actions: push image to GHCR on internal PRs - #581

Merged
outdooracorn merged 1 commit into
mainfrom
push-image-on-member-prs
Nov 27, 2026
Merged

outdooracorn merged 1 commit into
mainfrom
push-image-on-member-prs

Conversation

@outdooracorn

Copy link
Copy Markdown
Member

This makes it easier to test changes in a development environment before they are merged.

Bug: T446336

This makes it easier to test changes in a development environment before they are merged.

Bug: T446336
@outdooracorn
outdooracorn requested a review from dati18 November 26, 2026 16:01
@outdooracorn outdooracorn self-assigned this Nov 26, 2026
name: Login to GitHub Container Registry
uses: docker/login-action@v4.6.0
if: github.event_name != 'pull_request'
# Don't run this step if the PR was created by Dependabot or from a forked repository

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this comment? The code is clear enough for me tho

@outdooracorn outdooracorn Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is beneficial.

It is not super obvious to me exactly which repository github.event.pull_request.head.repo.full_name and github.repository refer to. Is it the target repo (wbstack) or the source repo (e.g. wbstack or addshore).

It's also not immediately obvious why github.event.pull_request.head.repo.full_name == github.repository is included in the conditional. Having this comment adds that we don't want to do these steps on forked repositories.

Unless you think the comment is wrong, let's leave it in for this PR. If people want to update or delete it they can create another PR and we can discuss it there. 🙂

@outdooracorn outdooracorn Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I would really like to get this merged ASAP so that it is easier to test the MediaWiki image built for T446155 locally before it has been merged into main.

cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
push: ${{ github.event_name != 'pull_request' }}
# Don't push the image if the PR was created by Dependabot or from a forked repository
push: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarrow asked in the daily if github.event.pull_request.head.repo.full_name == github.repository was necessary, thinking that the image would be pushed to the container registry of the pull request source repository owner.

In the current setup, this step is always pushing to the pull request target repository owner's GHCR.

You can see by looking at the Docker meta step of this docker.build.yml workflow of external PR#573 that the tags in the JSON output is set to ["ghcr.io/wbstack/mediawiki:sha-439ecd7"] which is what the Build and push step uses.

I believe that github.repository_owner, which is the current value of the username of the Login to GitHub Container Registry step, is the owner of the repository where the workflow is running (i.e. wbstack).

The workflow permissions includes Packages: read so even if username of the Login to GitHub Container Registry step was set to the pull request source repository owner, I don't think the permissions exist for it to succeed.

name: Login to GitHub Container Registry
uses: docker/login-action@v4.6.0
if: github.event_name != 'pull_request'
# Don't run this step if the PR was created by Dependabot or from a forked repository

@outdooracorn outdooracorn Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is beneficial.

It is not super obvious to me exactly which repository github.event.pull_request.head.repo.full_name and github.repository refer to. Is it the target repo (wbstack) or the source repo (e.g. wbstack or addshore).

It's also not immediately obvious why github.event.pull_request.head.repo.full_name == github.repository is included in the conditional. Having this comment adds that we don't want to do these steps on forked repositories.

Unless you think the comment is wrong, let's leave it in for this PR. If people want to update or delete it they can create another PR and we can discuss it there. 🙂

@outdooracorn
outdooracorn merged commit 4be281b into main Nov 27, 2026
9 checks passed
@outdooracorn
outdooracorn deleted the push-image-on-member-prs branch November 27, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants