From 4de1f890a5b980accb0f07780812ba916ce28642 Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Fri, 20 Nov 2026 08:51:48 +1100 Subject: [PATCH] Add a workflow to create release pull requests --- .github/workflows/create-release-pr.yml | 50 +++++++++++++++++++++++++ RELEASE.md | 8 +++- bin/release | 37 ++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/create-release-pr.yml create mode 100644 bin/release diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 0000000..90aed0c --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,50 @@ +name: Create release PR + +on: + workflow_dispatch: + inputs: + release_type: + description: Version bump to release + required: true + type: choice + options: + - patch + - minor + - major + +permissions: + contents: write + pull-requests: write + +jobs: + create-release-pr: + if: github.ref == 'refs/heads/trunk' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: trunk + + - name: Create release PR + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TYPE: ${{ inputs.release_type }} + run: | + git config user.name 'github-actions[bot]' + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + if [ "$(git rev-parse HEAD)" != "$GITHUB_SHA" ]; then + echo 'Trunk has moved. Start a new release PR run from trunk.' >&2 + exit 1 + fi + bash bin/release "$RELEASE_TYPE" + branch=$(git branch --show-current) + version=${branch#release/v} + + # Require the remote branch to be absent, even if Git could fast-forward it. + git push --force-with-lease="refs/heads/$branch:" origin "$branch" + + printf '## Description\n\nBump the plugin to %s.\n\n## Steps to Test\n\nConfirm both version fields match and the PR checks pass.\n' \ + "$version" > "$RUNNER_TEMP/release-pr.md" + gh pr create --base trunk --head "$branch" --title "Release $version" \ + --body-file "$RUNNER_TEMP/release-pr.md" diff --git a/RELEASE.md b/RELEASE.md index d6d2181..b1ebaf5 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,8 +2,12 @@ ## 1. Bump plugin version -1. When the version is ready for release, bump the version number in `vip-block-data-api.php`. Change plugin header and `WPCOMVIP__BLOCK_DATA_API__PLUGIN_VERSION` to match new version. -2. PR version changes (e.g. "Release 1.2.3") and merge to `trunk`. When a version change is detected, the `release` workflow will generate a new tag and release ZIP. +1. Run the **Create release PR** workflow from GitHub Actions, selecting `trunk` and a `patch`, `minor`, or `major` version bump. +2. Review the generated PR and approve its checks if GitHub prompts you. Merging it to `trunk` creates the tag and release ZIP. + +To prepare a release locally, run `bash bin/release patch` from the repository root on a clean `trunk` checkout. The script creates the branch and commits the version bump. Push the branch and open a PR when ready. + +If the workflow pushes a branch but fails to open the PR, check for an existing PR or open one from that branch. ## 2. Update integrations diff --git a/bin/release b/bin/release new file mode 100644 index 0000000..a876367 --- /dev/null +++ b/bin/release @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +plugin=vip-block-data-api.php +header_pattern='^([[:space:]]*\* Version: )([^[:space:]]+)([[:space:]]*)$' +constant_pattern="^([[:space:]]*define\( 'WPCOMVIP__BLOCK_DATA_API__PLUGIN_VERSION', ')([^']+)(' \);[[:space:]]*)$" +version=$(sed -nE "s/$header_pattern/\2/p" "$plugin") +defined_version=$(sed -nE "s/$constant_pattern/\2/p" "$plugin") +semver='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' + +if [[ ! $version =~ $semver || $version != "$defined_version" ]]; then + echo 'Expected matching stable major.minor.patch versions in the plugin header and constant' >&2 + exit 1 +fi + +IFS=. read -r major minor patch <<< "$version" +case "${1:-}" in + patch) patch=$((patch + 1)) ;; + minor) minor=$((minor + 1)); patch=0 ;; + major) major=$((major + 1)); minor=0; patch=0 ;; + *) echo 'Usage: bash bin/release patch|minor|major' >&2; exit 1 ;; +esac +next_version="$major.$minor.$patch" + +if [[ $(git branch --show-current) != trunk ]] || ! git diff --quiet || ! git diff --cached --quiet; then + echo 'Prepare releases from a clean trunk checkout' >&2 + exit 1 +fi + +git switch -c "release/v$next_version" +temporary=$(mktemp) +trap 'rm -f "$temporary"' EXIT +sed -E "s/$header_pattern/\1${next_version}\3/;s/$constant_pattern/\1${next_version}\3/" \ + "$plugin" > "$temporary" +cat "$temporary" > "$plugin" + +git commit -m "Release $next_version" -- "$plugin"