Skip to content
Merged
Show file tree
Hide file tree
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: 50 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 6 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -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"