-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Improve GHCR asset publishing and expand trigger events to include pull_request
#78211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,7 +263,14 @@ jobs: | |
| always() && | ||
| needs.build.outputs.job_status == 'success' && | ||
| github.repository == 'WordPress/gutenberg' && | ||
| github.event_name == 'push' | ||
| ( | ||
| github.event_name == 'push' || | ||
| github.event_name == 'workflow_dispatch' || | ||
| ( | ||
| github.event_name == 'pull_request' && | ||
| github.event.pull_request.head.repo.full_name == github.repository | ||
| ) | ||
| ) | ||
|
|
||
| steps: | ||
| - name: Download build artifact | ||
|
|
@@ -275,8 +282,12 @@ jobs: | |
| run: unzip gutenberg.zip && rm gutenberg.zip | ||
|
|
||
| # Noting the hash helps keep track of the commit the zip was built from. | ||
| # For pull_request events, github.sha is the ephemeral merge commit; use the PR head SHA instead | ||
| # so the recorded value points to a real, branch-reachable commit. | ||
| - name: Add a file for tracking the SHA value used. | ||
| run: echo "${{ github.sha }}" > .gutenberg-hash | ||
| env: | ||
| SOURCE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
| run: echo "$SOURCE_SHA" > .gutenberg-hash | ||
|
|
||
| - name: Recompress as a .gz file | ||
| run: tar -czf ${{ runner.temp }}/gutenberg.tar.gz . && mv ${{ runner.temp }}/gutenberg.tar.gz . | ||
|
|
@@ -297,12 +308,41 @@ jobs: | |
| # Container Registry. The organization name is WordPress, so ${{ github.repository }} causes an error. | ||
| # See https://github.com/orgs/community/discussions/27086 for more info. | ||
| - name: Push built plugin .tar.gz file to GitHub Container Registry | ||
| env: | ||
| SOURCE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
| run: | | ||
| oras push "ghcr.io/wordpress/gutenberg/gutenberg-wp-develop-build:${{ github.sha }}" \ | ||
| oras push "ghcr.io/wordpress/gutenberg/gutenberg-wp-develop-build:${SOURCE_SHA}" \ | ||
| "gutenberg.tar.gz:application/gzip" \ | ||
| --annotation "org.opencontainers.image.description=Gutenberg plugin build for commit ${{ github.sha }}" \ | ||
| --annotation "org.opencontainers.image.description=Gutenberg plugin build for commit ${SOURCE_SHA}" \ | ||
| --annotation "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \ | ||
|
desrosj marked this conversation as resolved.
|
||
| --annotation "org.opencontainers.image.revision=${{ github.sha }}" | ||
| --annotation "org.opencontainers.image.revision=${SOURCE_SHA}" | ||
|
|
||
| # Compute the mutable tag from the event. GitHub Actions expressions can't do string replacement, | ||
| # so the branch-name-to-tag conversion (release/19.5 -> release-19.5) must happen in bash. | ||
| - name: Determine mutable tag | ||
| id: mutable_tag | ||
| env: | ||
| EVENT_NAME: ${{ github.event_name }} | ||
| GITHUB_REF: ${{ github.ref }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| if [[ "$EVENT_NAME" == "pull_request" ]]; then | ||
| TAG="pr-${PR_NUMBER}" | ||
| else | ||
| BRANCH="${GITHUB_REF#refs/heads/}" | ||
| TAG="${BRANCH//\//-}" | ||
| fi | ||
| TAG="$(echo "$TAG" | tr '[:upper:]' '[:lower:]')" | ||
| echo "value=${TAG}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Add a mutable tag alongside the SHA tag so developers can pull "the latest build for this stream" | ||
| # (e.g. :trunk, :pr-12345, :release-19.5) without needing to update a pinned SHA. | ||
| - name: Add mutable tag for the built plugin | ||
| env: | ||
| SOURCE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
| MUTABLE_TAG: ${{ steps.mutable_tag.outputs.value }} | ||
| run: | | ||
| oras tag "ghcr.io/wordpress/gutenberg/gutenberg-wp-develop-build:${SOURCE_SHA}" "${MUTABLE_TAG}" | ||
|
Comment on lines
+338
to
+345
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So would the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right! I've created WordPress/wordpress-develop#11809 to show how I picture this working from a consumer standpoint. |
||
|
|
||
| revert-version-bump: | ||
| name: Revert version bump if build failed | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.