Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Comment thread
desrosj marked this conversation as resolved.

- name: Recompress as a .gz file
run: tar -czf ${{ runner.temp }}/gutenberg.tar.gz . && mv ${{ runner.temp }}/gutenberg.tar.gz .
Expand All @@ -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 }}" \
Comment thread
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So would the MUTABLE_TAG be usable in gutenberg.sha in the wordpress-develop package.json?

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.

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
Expand Down
Loading