Skip to content

Commit

Permalink
[Github-Actions-Workflows][Plugin-Release] Allow shipping a point-rel…
Browse files Browse the repository at this point in the history
…ease for an older stable release (#49082)

* Allow point-releases for release branches that are not the latest anymore

And other minor improvements

* Revert debug changes

Revert changes I made in order to test end-to-end from a test fork.

* Limit runs to `release/` branches

Co-authored-by: Bernie Reiter <ockham@raz.or.at>

* Fix changelog directory interpolation

Co-authored-by: Bernie Reiter <ockham@raz.or.at>

* Re-add debug changes for further testing

* Create only the tag when releasing an older point release, do not create a branch anymore

* Implement guard against accidental trunk release of older point releases

This refactors the upload zip workflow and add some version arithmetic to make sure the right version is uploaded depending:
- what is the current version set as latest -- this signals that a trunk release could be imminent, but is not enough to define it
- what is the current version in the WP core repo (real latest released version) -- this is compared with the published version and if it's greater than this version + the version was set as latest in GH, then it is a trunk release
- If the conditions above are false, then it's a tag release.

See the source for more details.

* Attempt to fix "fetch" already defined error when running the script in the GH actions env

* Simplify by not using node-fetch, or it will require installing the npm

* GH requires an user-agent

* Improve var name and comments

* Define func to set the output of the "compute-should-update-trunk" job and improve its name

* The core object should already be available as part of the github-scripts package

* Rely only in the github ref from the published release and not the latest tag, restructure the workflow to make it easier to debug and simplify it by using shell commands/script instead of JS

* Simplify further by moving the fetch core repo job to a step inside compute_should_update_trunk

* Fix/improve step/job ids

* Fix typo

* Formatting fixes

Auto-format with the RedHat YAML extension in vscode.

* Add missing outputs and a couple of other fixes

* A couple more fixes and a simplification of the compute_latest_version step

* Mock the build of the gutenberg.zip for debugging purposes, this commit should be reverted before merging!

* Fix a couple of step names

* Re-add prelease attribute, was accidentally commented out

* Debug commit, please revert: mock the version number in the version repo

* Fix changelog fetching when uploading the SVN tag

* Mock SVN version to 16.1.0

* Make the svn commit command verbose in order to debug network timeout issues while testing

* Revert "Make the svn commit command verbose in order to debug network timeout issues while testing"

This reverts commit da46aba.

* Optimize SVN tag addition in GitHub workflow

This commit significantly optimizes the process of adding a new tag to the SVN repository in our GitHub Workflow.

Previously, our process involved checking out the entire tags directory from the SVN repository, which led to increased execution time and failure points when the tags directory was filled with numerous versions.

We've resolved this issue by leveraging the svn import command, which allows us to directly add a new directory to the tags directory without checking out the existing directories first. This results in faster and more reliable workflow execution, particularly when dealing with repositories that have accumulated many tagged versions.

The changes made include:

    Removing the step to checkout Gutenberg tags from the WP.org plugin repository.
    Adding a new step that uses the svn import command to directly add a new version directory to the SVN repository. This is achieved without the need to checkout all existing directories under tags/.
    Removing the step to checkout the new Gutenberg tag as it's not needed anymore.

* Enhance safety checks in workflow to skip upload jobs for RC builds

This commit enhances the conditional checks within the 'upload' and 'upload-tag' jobs in our GitHub Actions workflows.

Previously, the jobs were executed based solely on the 'prerelease' flag of the release. However, there could be situations where this flag is accidentally set to 'false' for a Release Candidate (RC).

To avoid such mishaps, the conditions have been extended to check for the '-rc' suffix in the version string as well. This ensures that even if the 'prerelease' flag is incorrectly marked as 'false', the 'upload' and 'upload-tag' jobs are still skipped for RCs, thus preventing any unintended release of RC builds.

* Revert "Enhance safety checks in workflow to skip upload jobs for RC builds"

This reverts commit eae536a.

* Skip upload jobs if release is an RC by checking the ref for a rc suffix

This makes sure we don't upload RCs as trunk or tag even if the deployer accidentally unchecks the "Set as prerelease" flag.

* Revert build plugin mocking logic

Effectively reverts changes in 014e2c6.

* Revert initial dev/debug changes

Reverts changes from 489aa70. If further testing is needed, revert the changes here again.

* Revert WP SVN repo version mock

Revert changes from fe8b33c.

* Add back if conditions that were accidentally removed

Removed in 014e2c6.

I accidentally removed it instead of commenting out, so I forgot to reactivate it.

The problem was that due to the amount of changes later, I couldn't just revert this commit.

---------

Co-authored-by: Bernie Reiter <ockham@raz.or.at>
  • Loading branch information
fullofcaffeine and ockham authored Jul 5, 2023
1 parent f3da267 commit 68fa80a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .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/' ) &&
github.event.inputs.version == 'stable'
)
)
Expand Down
119 changes: 107 additions & 12 deletions .github/workflows/upload-release-to-plugin-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,66 @@ on:
types: [published]

jobs:
compute-should-update-trunk:
name: Decide if trunk or tag
runs-on: ubuntu-latest
# Skip this job if the release is a release candidate. This will in turn skip
# the upload jobs, which are only relevant for non-RC releases.
# We first check if the release is a prerelease, and then if the ref contains
# the string "rc". The latter is fallback in case the deployer accidentally
# unchecks the "This is a pre-release" checkbox in the release UI.
if: |
!github.event.release.prerelease && !contains(github.ref, 'rc')
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/')
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 $?
}
# 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 +81,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 Down Expand Up @@ -95,11 +152,12 @@ jobs:
path: ./changelog.txt

upload:
name: Upload Gutenberg Plugin
name: Publish as trunk (and tag)
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' && github.event.release.assets[0]
env:
PLUGIN_REPO_URL: 'https://plugins.svn.wordpress.org/gutenberg'
STABLE_VERSION_REGEX: '[0-9]\+\.[0-9]\+\.[0-9]\+\s*'
Expand All @@ -109,11 +167,7 @@ jobs:

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 +184,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: |
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 +213,44 @@ 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:
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.assets[0]
env:
PLUGIN_REPO_URL: 'https://plugins.svn.wordpress.org/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: 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 "$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" "$VERSION/readme.txt"
- name: Download Changelog Artifact
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
with:
name: changelog trunk
path: ${{ github.event.release.name }}

- name: Add the new version directory and commit changes to the SVN repository
run: |
svn import "$VERSION" "$PLUGIN_REPO_URL/tags/$VERSION" -m "Committing version $VERSION" \
--no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"

1 comment on commit 68fa80a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 68fa80a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5467583352
📝 Reported issues:

Please sign in to comment.