Skip to content

Commit 750378f

Browse files
authored
Merge pull request #281 from wpengine/chore-pre-release-rewrite-iteration-7
chore: Refactor of pre-release process
2 parents 48ec379 + ce66416 commit 750378f

File tree

5 files changed

+133
-38
lines changed

5 files changed

+133
-38
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
---
44

55
chore: Initial beta release of hwp-previews.
6+

.changeset/proud-mayflies-sip.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
# This creates a release branch for a plugin when changes are pushed to the main branch.
3+
# We cannot commit to a protected branch directly, so we create a new branch to make these changes.
4+
name: Create Release Branch
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- "plugins/**"
12+
13+
permissions:
14+
contents: write # Allow actions to read and write repository contents
15+
pull-requests: write # Allow actions to create and manage pull requests
16+
actions: read # Allow actions to read repository metadata but not write to it
17+
18+
jobs:
19+
create-release-branch:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Set up PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: '8.2' # Note all plugins are compatible with PHP 8.2
33+
extensions: mbstring, json, zip
34+
35+
- name: Setup Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 18.x. # Min version required by the repo
39+
40+
- name: Setup pnpm
41+
uses: pnpm/action-setup@v3
42+
with:
43+
version: 10 # Min version required by the repo
44+
45+
- name: Get changed plugin directory
46+
id: plugin
47+
run: |
48+
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
49+
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
50+
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
51+
52+
- name: Validate plugin detection
53+
continue-on-error: false
54+
run: |
55+
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
56+
echo "Plugin directory does not exist"
57+
exit 1
58+
fi
59+
60+
- name: Install dependencies
61+
run: pnpm install
62+
63+
- name: Create release branch and apply changesets
64+
run: |
65+
# Create a unique branch name with timestamp
66+
BRANCH_NAME="release/${{ steps.plugin.outputs.plugin_slug }}-$(date +%Y%m%d-%H%M%S)"
67+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
68+
69+
# Create and switch to release branch
70+
git checkout -b "$BRANCH_NAME"
71+
72+
# Apply version bumps from changesets
73+
pnpm changeset version
74+
75+
# Configure git
76+
git config user.name "github-actions"
77+
git config user.email "[email protected]"
78+
79+
# Commit changes
80+
git add .
81+
if git diff --staged --quiet; then
82+
echo "No changes to commit"
83+
else
84+
git commit -m "chore: apply version bump from changesets for ${{ steps.plugin.outputs.plugin_slug }}"
85+
git push origin "$BRANCH_NAME"
86+
87+
# Create PR
88+
gh pr create \
89+
--title "Release: ${{ steps.plugin.outputs.plugin_slug }} version bump" \
90+
--body "Automated release PR for ${{ steps.plugin.outputs.plugin_slug }} plugin.
91+
92+
This PR applies version bumps from changesets. Once merged, it will trigger the pre-release creation workflow.
93+
94+
Plugin: ${{ steps.plugin.outputs.plugin_slug }}" \
95+
--base main \
96+
--head "$BRANCH_NAME"
97+
fi
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
name: Pre-release Tag
1+
# Part of create-release-branch.yml
2+
# Changesets are applied to the release branch instead of main as this is a production branch
3+
# Once merged, the PR should create the pre-release tag
4+
5+
name: Create Pre-release Tag
26

37
on:
4-
push:
8+
pull_request:
9+
types: [closed]
510
branches:
611
- main
712
paths:
813
- "plugins/**"
914

1015
permissions:
11-
contents: write # Allow actions to read and write repository contents
12-
actions: read # Allow actions to read repository metadata but not write
16+
contents: write
17+
actions: read
18+
1319
jobs:
1420
tag-pre-release:
21+
# Only run if PR was merged and branch name starts with 'release/'
22+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
1523
runs-on: ubuntu-latest
1624

1725
steps:
@@ -23,52 +31,38 @@ jobs:
2331
- name: Set up PHP
2432
uses: shivammathur/setup-php@v2
2533
with:
26-
php-version: '8.2'
34+
php-version: '8.2' # Note: All plugins are compatible with PHP 8.2
2735
extensions: mbstring, json, zip
2836

2937
- name: Setup Node.js
3038
uses: actions/setup-node@v4
3139
with:
32-
node-version: 18.x
40+
node-version: 18.x # Min version required by the repo
3341

3442
- name: Setup pnpm
3543
uses: pnpm/action-setup@v3
3644
with:
37-
version: 10
45+
version: 10 # Min version required by the repo
3846

3947
- name: Get changed plugin directory
4048
id: plugin
4149
run: |
42-
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
50+
# Get files changed in the merged PR
4351
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
52+
if [ -z "$plugin" ]; then
53+
# Fallback: extract from branch name if no plugin changes detected
54+
branch_name="${{ github.head_ref }}"
55+
plugin=$(echo "$branch_name" | sed 's/release\/\([^-]*\)-.*/\1/')
56+
fi
4457
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
4558
4659
- name: Validate plugin detection
47-
continue-on-error: false
4860
run: |
4961
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
50-
echo "Plugin directory does not exist"
62+
echo "Plugin directory does not exist: plugins/${{ steps.plugin.outputs.plugin_slug }}"
5163
exit 1
5264
fi
5365
54-
- name: Install dependencies
55-
run: pnpm install
56-
57-
- name: Apply version bumps from changesets
58-
run: pnpm changeset version
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
62-
- name: Commit updated package.json and changelogs
63-
run: |
64-
git config user.name "github-actions"
65-
git config user.email "[email protected]"
66-
git add .
67-
git commit -m "chore: apply version bump from changesets" || echo "No changes to commit"
68-
git push
69-
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
7266
- name: Read package metadata
7367
id: metadata
7468
run: |
@@ -95,26 +89,31 @@ jobs:
9589
echo "package_name=$package_name" >> $GITHUB_OUTPUT
9690
echo "package_version=$package_version" >> $GITHUB_OUTPUT
9791
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
98-
env:
99-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10092
10193
- name: Create Git tag
94+
continue-on-error: false
10295
run: |
10396
TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"
10497
10598
# Check if tag already exists
10699
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
107100
echo "Tag $TAG_NAME already exists. Skipping tag creation."
108-
exit 0
101+
echo "tag_exists=true" >> $GITHUB_ENV
102+
exit 1
109103
fi
110104
111105
git config user.name "github-actions"
112106
git config user.email "[email protected]"
113107
git tag "$TAG_NAME"
114108
git push origin "$TAG_NAME"
109+
echo "tag_exists=false" >> $GITHUB_ENV
110+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
115111
env:
116112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117113

114+
- name: Install dependencies
115+
run: pnpm install
116+
118117
- name: Run composer install
119118
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
120119
run: composer install --no-dev --optimize-autoloader
@@ -141,7 +140,7 @@ jobs:
141140
- name: Upload archive to GitHub Release
142141
uses: softprops/action-gh-release@v2
143142
with:
144-
tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
143+
tag_name: ${{ env.TAG_NAME }}
145144
name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
146145
prerelease: true
147146
files: |

plugins/hwp-previews/TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Testing HWP Previews
22

33
This plugin uses [Codeception](https://codeception.com/) with [WPBrowser](https://wpbrowser.wptestkit.dev/) for automated testing.
4-
Tests are organized into suites for unit, integration (wpunit), functional, and acceptance testing.
4+
Tests are organized into suites for integration (wpunit), functional, and acceptance testing.
55

66
---
77

0 commit comments

Comments
 (0)