Skip to content
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

Workflows: Allow point releases after a new RC is out #32560

Merged
merged 9 commits into from
Jun 23, 2021
47 changes: 41 additions & 6 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,46 @@ concurrency:
cancel-in-progress: true

jobs:
compute-stable-branches:
name: Compute current and next stable release branches
runs-on: ubuntu-latest
outputs:
current_stable_branch: ${{ steps.get_branches.outputs.current_stable_branch }}
next_stable_branch: ${{ steps.get_branches.outputs.next_stable_branch }}
steps:
- name: Get current and next stable release branches
id: get_branches
run: |
curl \
-H "Accept: application/vnd.github.v3+json" \
-o latest.json \
"https://api.github.com/repos/${{ github.repository }}/releases/latest"
LATEST_STABLE_TAG=$(jq --raw-output '.tag_name' latest.json)
IFS='.' read LATEST_STABLE_MAJOR LATEST_STABLE_MINOR LATEST_STABLE_PATCH <<< "${LATEST_STABLE_TAG#v}"
echo "::set-output name=current_stable_branch::release/${LATEST_STABLE_MAJOR}.${LATEST_STABLE_MINOR}"
if [[ ${LATEST_STABLE_MINOR} == "9" ]]; then
echo "::set-output name=next_stable_branch::release/$((LATEST_STABLE_MAJOR + 1)).0"
else
echo "::set-output name=next_stable_branch::release/${LATEST_STABLE_MAJOR}.$((LATEST_STABLE_MINOR + 1))"
fi

bump-version:
name: Bump version
runs-on: ubuntu-latest
needs: compute-stable-branches
if: |
github.repository == 'WordPress/gutenberg' &&
github.event_name == 'workflow_dispatch' &&
github.ref == 'refs/heads/trunk' && (
github.event.inputs.version == 'rc' ||
github.event.inputs.version == 'stable'
github.event_name == 'workflow_dispatch' && (
(
github.ref == 'refs/heads/trunk' ||
endsWith( github.ref, needs.compute-stable-branches.outputs.next_stable_branch )
) && (
github.event.inputs.version == 'rc' ||
github.event.inputs.version == 'stable'
) || (
endsWith( github.ref, needs.compute-stable-branches.outputs.current_stable_branch ) &&
github.event.inputs.version == 'stable'
Comment on lines +58 to +59
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the crucial change: We're now also allowing to run this job from the "current stable branch", i.e. the branch the latest stable release belongs to (e.g. the release/10.8 branch, if the latest release is 10.8.2); but only to release a new stable (i.e. point) release (e.g. 10.8.3).

)
)
outputs:
old_version: ${{ steps.get_version.outputs.old_version }}
Expand Down Expand Up @@ -91,13 +122,17 @@ jobs:
sed -i "s/${{ steps.get_version.outputs.old_version }}/${VERSION}/g" gutenberg.php
sed -i "s/${{ steps.get_version.outputs.old_version }}/${VERSION}/g" readme.txt

- name: Commit the version bump
- name: Commit the version bump to the release branch
run: |
git add gutenberg.php package.json package-lock.json readme.txt
git commit -m "Bump plugin version to ${{ steps.get_version.outputs.new_version }}"
git push --set-upstream origin "${{ steps.get_version.outputs.release_branch }}"

- name: Cherry-pick to trunk
- name: Fetch trunk
if: ${{ github.ref != 'refs/heads/trunk' }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is the important change right? Preventing the cherry-pick if we don't use trunk as a base branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah no, not really, we were doing that before -- just using a different heuristic, i.e. by checking whether the version in trunk's package.json matched the one from the branch the workflow was triggered from 😬

However, we limited at the time which branches the workflow could be triggered to trunk only, so the check was a bit academic (and arguably a violation of the YAGNI pattern, that I hold so dear 😉).

run: git fetch --depth=1 origin trunk

- name: Cherry-pick the version bump commit to trunk
run: |
git checkout trunk
git pull
Expand Down