Skip to content

Commit d4943d7

Browse files
authored
Merge pull request #273 from wpengine/chore-setup-release-workflow-iteration-1
chore: Initial PR for creating pre-release tags for a plugin
2 parents 1ac12c4 + 69cdb6a commit d4943d7

File tree

8 files changed

+15097
-973
lines changed

8 files changed

+15097
-973
lines changed

.changeset/config.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
],
77
"commit": false,
88
"linked": [],
9-
"access": "public",
9+
"access": "restricted",
1010
"baseBranch": "main",
1111
"updateInternalDependencies": "patch",
12-
"ignore": [
13-
"docs/",
14-
"examples/",
15-
"packages/"
16-
],
12+
"ignore": [],
1713
"packages": [
1814
"plugins/*"
19-
]
15+
],
16+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
17+
"onlyUpdatePeerDependentsWhenOutOfRange": true
18+
}
2019
}

.changeset/slimy-pugs-rush.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hwp-previews/wordpress-plugin": patch
3+
---
4+
5+
chore: Initial release of hwp-previews beta release.
6+

.github/workflows/e2e-test.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ on:
55
branches:
66
- main
77
paths:
8-
- "plugins/hwp-previews/**"
8+
- 'plugins/hwp-previews/**.php'
9+
- 'plugins/hwp-previews/**.js'
10+
- 'plugins/hwp-previews/**.css'
11+
- 'plugins/hwp-previews/**.json'
12+
913
pull_request:
1014
branches:
1115
- main
@@ -29,9 +33,12 @@ jobs:
2933
- name: Install dependencies
3034
run: npm ci
3135

32-
- name: Install composer
33-
run: composer install
34-
working-directory: plugins/hwp-previews
36+
- name: Setup PHP with Cached Composer
37+
uses: ./.github/actions/setup-php-composer
38+
with:
39+
php-version: 8.2
40+
working-directory: plugins/hwp-previews
41+
composer-options: '--no-progress --optimize-autoloader --no-dev'
3542

3643
- name: Install playwright browsers
3744
run: npx playwright install --with-deps

.github/workflows/pre-release.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Pre-release Tag
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "plugins/**"
9+
10+
permissions:
11+
contents: write # Allow actions to read and write repository contents
12+
actions: read # Allow actions to read repository metadata but not write
13+
jobs:
14+
tag-pre-release:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: '8.2'
27+
extensions: mbstring, json, zip
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 18.x
33+
34+
- name: Setup pnpm
35+
uses: pnpm/action-setup@v3
36+
with:
37+
version: 8
38+
39+
- name: Get changed plugin directory
40+
id: plugin
41+
run: |
42+
git fetch --prune --unshallow
43+
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
44+
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
45+
46+
- name: Validate plugin detection
47+
run: |
48+
if [ -z "${{ steps.plugin.outputs.plugin_slug }}" ]; then
49+
echo "No plugin detected in changes"
50+
exit 1
51+
fi
52+
53+
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
54+
echo "Plugin directory does not exist"
55+
exit 1
56+
fi
57+
58+
- name: Install dependencies
59+
run: pnpm install
60+
61+
- name: Apply version bumps from changesets
62+
run: pnpm changeset version
63+
64+
- name: Commit updated package.json and changelogs
65+
run: |
66+
git config user.name "github-actions"
67+
git config user.email "[email protected]"
68+
git add .
69+
git commit -m "chore: apply version bump from changesets" || echo "No changes to commit"
70+
git push
71+
72+
- name: Read package metadata
73+
id: metadata
74+
run: |
75+
PLUGIN_DIR="plugins/${{ steps.plugin.outputs.plugin_slug }}"
76+
77+
if [ ! -f "$PLUGIN_DIR/package.json" ]; then
78+
echo "package.json not found in $PLUGIN_DIR"
79+
exit 1
80+
fi
81+
82+
package_name=$(jq -r '.name // empty' "$PLUGIN_DIR/package.json")
83+
package_version=$(jq -r '.version // empty' "$PLUGIN_DIR/package.json")
84+
85+
if [ -z "$package_name" ] || [ "$package_name" = "null" ] || [ "$package_name" = "empty" ]; then
86+
echo "Missing or invalid name in $PLUGIN_DIR/package.json"
87+
exit 1
88+
fi
89+
90+
if [ -z "$package_version" ] || [ "$package_version" = "null" ] || [ "$package_version" = "empty" ]; then
91+
echo "Missing or invalid version in $PLUGIN_DIR/package.json"
92+
exit 1
93+
fi
94+
95+
echo "package_name=$package_name" >> $GITHUB_OUTPUT
96+
echo "package_version=$package_version" >> $GITHUB_OUTPUT
97+
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
98+
99+
- name: Create Git tag
100+
run: |
101+
TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"
102+
103+
# Check if tag already exists
104+
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
105+
echo "Tag $TAG_NAME already exists. Skipping tag creation."
106+
exit 0
107+
fi
108+
109+
git config user.name "github-actions"
110+
git config user.email "[email protected]"
111+
git tag "$TAG_NAME"
112+
git push origin "$TAG_NAME"
113+
114+
- name: Run composer install
115+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
116+
run: composer install --no-dev --optimize-autoloader
117+
118+
- name: Validate composer setup
119+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
120+
run: |
121+
composer validate --no-check-publish --no-check-lock
122+
123+
- name: Create plugin archive
124+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
125+
run: |
126+
mkdir -p plugin-build
127+
composer archive --format=zip --file="plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip"
128+
129+
# Verify archive was created
130+
if [ ! -f "plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" ]; then
131+
echo "Failed to create plugin archive"
132+
exit 1
133+
fi
134+
135+
echo "Archive created successfully: $(ls -lh plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip)"
136+
137+
- name: Upload archive to GitHub Release
138+
uses: softprops/action-gh-release@v2
139+
with:
140+
tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
141+
name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
142+
prerelease: true
143+
files: |
144+
${{ steps.metadata.outputs.PLUGIN_DIR }}/plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip
145+
env:
146+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)