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

[Github-Actions-Workflows][Plugin-Release] Allow shipping a point-release for an older stable release #49082

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8cd1231
Allow point-releases for release branches that are not the latest any…
fullofcaffeine Mar 3, 2023
d685abb
Revert debug changes
fullofcaffeine Mar 14, 2023
8b939f8
Limit runs to `release/` branches
fullofcaffeine Apr 7, 2023
ff5c80f
Fix changelog directory interpolation
fullofcaffeine Apr 7, 2023
489aa70
Re-add debug changes for further testing
fullofcaffeine Apr 7, 2023
9dc4b39
Create only the tag when releasing an older point release, do not cre…
fullofcaffeine Apr 7, 2023
7438230
Implement guard against accidental trunk release of older point releases
fullofcaffeine Apr 15, 2023
237fd16
Attempt to fix "fetch" already defined error when running the script …
fullofcaffeine Apr 15, 2023
8934253
Simplify by not using node-fetch, or it will require installing the npm
fullofcaffeine Apr 15, 2023
0b06966
GH requires an user-agent
fullofcaffeine Apr 15, 2023
2cb1260
Improve var name and comments
fullofcaffeine Apr 18, 2023
1b0713b
Define func to set the output of the "compute-should-update-trunk" jo…
fullofcaffeine Apr 19, 2023
7ac820e
The core object should already be available as part of the github-scr…
fullofcaffeine Apr 19, 2023
b35880a
Rely only in the github ref from the published release and not the la…
fullofcaffeine Apr 19, 2023
a81bc68
Simplify further by moving the fetch core repo job to a step inside c…
fullofcaffeine Apr 19, 2023
60c465a
Fix/improve step/job ids
fullofcaffeine Apr 19, 2023
a370648
Fix typo
fullofcaffeine Apr 19, 2023
cd9bf15
Formatting fixes
fullofcaffeine Apr 19, 2023
e5e5764
Add missing outputs and a couple of other fixes
fullofcaffeine Apr 20, 2023
4297be6
A couple more fixes and a simplification of the compute_latest_versio…
fullofcaffeine Apr 20, 2023
014e2c6
Mock the build of the gutenberg.zip for debugging purposes, this comm…
fullofcaffeine Apr 21, 2023
dda3c46
Fix a couple of step names
fullofcaffeine Apr 21, 2023
cade53d
Re-add prelease attribute, was accidentally commented out
fullofcaffeine May 24, 2023
fe8b33c
Debug commit, please revert: mock the version number in the version repo
fullofcaffeine May 24, 2023
a37623b
Fix changelog fetching when uploading the SVN tag
fullofcaffeine May 25, 2023
ac78cac
Mock SVN version to 16.1.0
fullofcaffeine May 25, 2023
da46aba
Make the svn commit command verbose in order to debug network timeout…
fullofcaffeine May 25, 2023
b6a2f82
Revert "Make the svn commit command verbose in order to debug network…
fullofcaffeine May 25, 2023
86f4168
Optimize SVN tag addition in GitHub workflow
fullofcaffeine May 25, 2023
eae536a
Enhance safety checks in workflow to skip upload jobs for RC builds
fullofcaffeine May 26, 2023
d642211
Revert "Enhance safety checks in workflow to skip upload jobs for RC …
fullofcaffeine May 26, 2023
472262e
Skip upload jobs if release is an RC by checking the ref for a rc suffix
fullofcaffeine May 26, 2023
fae69ef
Revert build plugin mocking logic
fullofcaffeine Jun 1, 2023
6206fc7
Revert initial dev/debug changes
fullofcaffeine Jun 1, 2023
b2bde7d
Revert WP SVN repo version mock
fullofcaffeine Jun 1, 2023
73a5fc4
Add back if conditions that were accidentally removed
fullofcaffeine Jul 5, 2023
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
30 changes: 22 additions & 8 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
github.event.inputs.version == 'rc' ||
github.event.inputs.version == 'stable'
) || (
endsWith( github.ref, needs.compute-stable-branches.outputs.current_stable_branch ) &&
startsWith( github.ref, 'refs/heads/release/' ) &&
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
github.event.inputs.version == 'stable'
)
)
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
token: ${{ secrets.GUTENBERG_TOKEN }}
Copy link
Member Author

Choose a reason for hiding this comment

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

I will revert this change before merging (from GITHUB_TOKEN -> GUTENBERG_TOKEN).

token: ${{ secrets.GITHUB_TOKEN }}

- name: Compute old and new version
id: get_version
Expand Down Expand Up @@ -164,18 +164,25 @@ jobs:

steps:
- name: Checkout code
# The following is debug code, should be reverted before merging. See commit that added this for more info.
if: false
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ needs.bump-version.outputs.release_branch || github.ref }}

- name: Use desired version of Node.js
# The following is debug code, should be reverted before merging. See commit that added this for more info.
if: false
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: '.nvmrc'
cache: npm

- name: Build Gutenberg plugin ZIP file
run: ./bin/build-plugin-zip.sh
# The following is debug code, should be reverted before merging. See commit that added this for more info.
run: |
echo 'Stable tag: V.V.V' > readme.txt
zip -j gutenberg.zip readme.txt
env:
NO_CHECKS: 'true'

Expand All @@ -186,7 +193,10 @@ jobs:
path: ./gutenberg.zip

- name: Build release notes draft
if: ${{ needs.bump-version.outputs.new_version }}
# Debug: if we want fast runs, then this should be disabled as this won't
# work if the real plugin isn't built (becuase npm install is needed to install
# some needed packages that the `other:changelog` task uses`).
if: false
env:
VERSION: ${{ needs.bump-version.outputs.new_version }}
run: |
Expand All @@ -202,7 +212,8 @@ jobs:
fi

- name: Upload release notes artifact
if: ${{ needs.bump-version.outputs.new_version }}
# The following is debug code, should be reverted before merging. See commit that added this for more info.
if: false
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: release-notes
Expand Down Expand Up @@ -271,6 +282,8 @@ jobs:
name: gutenberg-plugin

- name: Download Release Notes Artifact
# The following is debug code, should be reverted before merging. See commit that added this for more info.
if: false
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
with:
name: release-notes
Expand All @@ -285,8 +298,9 @@ jobs:
release_name: ${{ steps.get_release_version.outputs.version }}
commitish: ${{ needs.bump-version.outputs.release_branch || github.ref }}
draft: true
prerelease: ${{ contains(needs.bump-version.outputs.new_version, 'rc') }}
body_path: release-notes.txt
# The following is debug code, should be reverted before merging. See commit that added this for more info.
# prerelease: ${{ contains(needs.bump-version.outputs.new_version, 'rc') }}
# body_path: release-notes.txt

- name: Upload Release Asset
id: upload-release-asset
Expand All @@ -304,7 +318,7 @@ jobs:
runs-on: ubuntu-latest
environment: WordPress packages
needs: [bump-version, build]
if: ${{ endsWith( needs.bump-version.outputs.new_version, '-rc.1' ) }}
if: ${{ false }}
steps:
- name: Checkout (for CLI)
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand Down
123 changes: 109 additions & 14 deletions .github/workflows/upload-release-to-plugin-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,58 @@ on:
types: [published]

jobs:
compute-should-update-trunk:
name: Decide if trunk or tag
runs-on: ubuntu-latest
outputs:
should_update_trunk: ${{ steps.compute_should_update_trunk.outputs.should_update_trunk }}

steps:
- name: Fetch latest version in the WP core repo
id: compute_latest_version_in_core_repo
run: |
latest_version_in_core_repo=$(curl -s 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request\[slug\]=gutenberg' | jq -r '.version')
echo "Latest Core Repo version: $latest_version_in_core_repo"
echo "version=$latest_version_in_core_repo" >> $GITHUB_OUTPUT

- name: Decide if it is a trunk or tag update
id: compute_should_update_trunk
env:
GITHUB_REF: ${{ github.ref }}
run: |
latestPublishedVersion=$(echo "$GITHUB_REF" | sed -E 's/refs\/tags\/(v?)([0-9.]+)/\2/')
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
latestVersionInCoreRepo="${{ steps.compute_latest_version_in_core_repo.outputs.version }}"

# Determines if the first version string is greater than the second version string.
#
# Params:
# $1 - The first version string to compare, which may have an optional leading "v".
# $2 - The second version string to compare, which may have an optional leading "v".
#
# Return values:
# 0 - The first version string is greater than the second version string.
# 1 - The first version string is less than or equal to the second version string.
is_first_version_greater_than_second() {
v1=${1#v}
v2=${2#v}
dpkg --compare-versions "$v1" gt "$v2"
return $?
}
Comment on lines +38 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely not for this PR, but in a follow-up, can we maybe replace this with the semver npm? I'm already using it in a few places in the build-plugin workflow (e.g.) to compute version numbers, and it also supports comparison

semver.gt('1.2.3', '9.8.7') // false
semver.lt('1.2.3', '9.8.7') // true

(and cleanup: semver.clean(' =v1.2.3 ') // '1.2.3').

(dpkg is a Debian/Ubuntu tool IIRC, and I've tried to avoid bash-isms and other dependencies as much as possible in order to make local testing of individual steps from workflows at least a bit easier across platforms -- including MacOS.)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. I'll take note of that for a follow-up 👍🏻


# Only update trunk *if* the published release's version in Github is GREATER
# than the version currently published in the WP plugins repo. If not, then it
# will upload it as a new tag.
shouldUpdateTrunk=false
if is_first_version_greater_than_second "$latestPublishedVersion" "$latestVersionInCoreRepo"; then
shouldUpdateTrunk=true
fi

echo "Should update trunk: $shouldUpdateTrunk"
echo "should_update_trunk=$shouldUpdateTrunk" >> $GITHUB_OUTPUT

get-release-branch:
name: Get release branch name
runs-on: ubuntu-latest
if: github.event.release.assets[0]
outputs:
release_branch: ${{ steps.get_release_branch.outputs.release_branch }}

Expand All @@ -25,7 +73,8 @@ jobs:
update-changelog:
name: Update Changelog on ${{ matrix.branch }} branch
runs-on: ubuntu-latest
if: github.event.release.assets[0]
if: |
github.event.release.assets[0]
needs: get-release-branch
env:
TAG: ${{ github.event.release.tag_name }}
Expand All @@ -42,7 +91,7 @@ jobs:
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ matrix.branch }}
token: ${{ secrets.GUTENBERG_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update the Changelog to include the release notes
run: |
Expand Down Expand Up @@ -95,25 +144,23 @@ jobs:
path: ./changelog.txt

upload:
name: Upload Gutenberg Plugin
name: Publish as trunk (and tag)
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
environment: wp.org plugin
needs: update-changelog
if: ${{ !github.event.release.prerelease && github.event.release.assets[0] }}
needs: [compute-should-update-trunk, update-changelog]
if: |
needs.compute-should-update-trunk.outputs.should_update_trunk == 'true' &&
Copy link
Member

Choose a reason for hiding this comment

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

Nice! 👍

!github.event.release.prerelease && github.event.release.assets[0]
env:
PLUGIN_REPO_URL: 'https://plugins.svn.wordpress.org/gutenberg'
PLUGIN_REPO_URL: 'http://caffeine.ngrok.io/svn/gutenberg'
STABLE_VERSION_REGEX: '[0-9]\+\.[0-9]\+\.[0-9]\+\s*'
SVN_USERNAME: ${{ secrets.svn_username }}
SVN_PASSWORD: ${{ secrets.svn_password }}
VERSION: ${{ github.event.release.name }}

steps:
- name: Check out Gutenberg trunk from WP.org plugin repo
run: svn checkout "$PLUGIN_REPO_URL/trunk"

- name: Get previous stable version
id: get_previous_stable_version
run: echo "stable_version=$(awk -F ':\ ' '$1 == "Stable tag" {print $2}' ./trunk/readme.txt)" >> $GITHUB_OUTPUT
run: svn checkout "$PLUGIN_REPO_URL/trunk" --username "$SVN_USERNAME" --password "$SVN_PASSWORD"

- name: Delete everything
working-directory: ./trunk
Expand All @@ -130,8 +177,8 @@ jobs:
- name: Replace the stable tag placeholder with the existing stable tag on the SVN repository
env:
STABLE_TAG_PLACEHOLDER: 'Stable tag: V\.V\.V'
STABLE_TAG: 'Stable tag: ${{ steps.get_previous_stable_version.outputs.stable_version }}'
run: sed -i "s/${STABLE_TAG_PLACEHOLDER}/${STABLE_TAG}/g" ./trunk/readme.txt
run: |
Copy link
Member Author

Choose a reason for hiding this comment

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

Before, STABLE_TAG was based on the value of steps.get_previous_stable_version.outputs.stable_version, which for me looked a bit confusing, given the get_previous_stable_version step -- we actually want the current latest version, and not the previous, and we can get that from the VERSION env variable, defined as an env variable for the job and passed as part of the payload for the release event.

sed -i "s/$STABLE_TAG_PLACEHOLDER/Stable tag: $VERSION/g" ./trunk/readme.txt

- name: Download Changelog Artifact
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
Expand Down Expand Up @@ -159,3 +206,51 @@ jobs:
sed -i "s/Stable tag: ${STABLE_VERSION_REGEX}/Stable tag: ${VERSION}/g" ./readme.txt
svn commit -m "Releasing version $VERSION" \
--no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"

upload-tag:
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
name: Publish as tag
runs-on: ubuntu-latest
environment: wp.org plugin
needs: [compute-should-update-trunk, update-changelog]
if: |
needs.compute-should-update-trunk.outputs.should_update_trunk == 'false' &&
!github.event.release.prerelease && github.event.release.assets[0]
env:
PLUGIN_REPO_URL: 'http://caffeine.ngrok.io/svn/gutenberg'
STABLE_VERSION_REGEX: '[0-9]\+\.[0-9]\+\.[0-9]\+\s*'
SVN_USERNAME: ${{ secrets.svn_username }}
SVN_PASSWORD: ${{ secrets.svn_password }}
VERSION: ${{ github.event.release.name }}

steps:
- name: Check out Gutenberg tags from WP.org plugin repo
run: svn checkout "$PLUGIN_REPO_URL/tags" --username "$SVN_USERNAME" --password "$SVN_PASSWORD"

- name: Download and unzip Gutenberg plugin asset into tags folder
env:
PLUGIN_URL: ${{ github.event.release.assets[0].browser_download_url }}
run: |
# do the magic here
curl -L -o gutenberg.zip $PLUGIN_URL
unzip gutenberg.zip -d tags/$VERSION
rm gutenberg.zip

- name: Replace the stable tag placeholder with the existing stable tag on the SVN repository
env:
STABLE_TAG_PLACEHOLDER: 'Stable tag: V\.V\.V'
run: |
sed -i "s/$STABLE_TAG_PLACEHOLDER/Stable tag: $VERSION/g" ./tags/$VERSION/readme.txt

- name: Download Changelog Artifact
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
with:
name: changelog for tags
path: tags/${{ github.event.release.name }}

- name: Commit the content changes
working-directory: ./tags
run: |
svn st | grep '^?' | awk '{print $2}' | xargs -r svn add
svn st | grep '^!' | awk '{print $2}' | xargs -r svn rm
svn commit -m "Committing version $VERSION" \
--no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"