-
-
Notifications
You must be signed in to change notification settings - Fork 85
172 lines (146 loc) · 6.07 KB
/
Copy pathpr-build-test.yml
File metadata and controls
172 lines (146 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: PR Build and Playground Test
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**'
- '.github/workflows/pr-build-test.yml'
permissions:
contents: read
pull-requests: write
jobs:
build:
name: Build Plugin for Testing
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: '8.2'
extensions: mysqli, mbstring, xml, zip
tools: composer
- name: Install dependencies
run: |
npm ci
composer install
- name: Build plugin
env:
MU_CLIENT_ID: ${{ secrets.MU_CLIENT_ID }}
MU_CLIENT_SECRET: ${{ secrets.MU_CLIENT_SECRET }}
run: npm run build
- name: Prepare artifact for upload
id: artifact
run: |
# Find the built zip file
ARCHIVE_PATH=$(ls -t ultimate-multisite*.zip | head -1)
ARCHIVE_NAME=$(basename "$ARCHIVE_PATH" .zip)
# Extract the zip so GitHub Actions will zip it once (not double-zip)
mkdir -p artifact-temp
unzip -q "$ARCHIVE_PATH" -d artifact-temp
# The extracted folder should contain the plugin
PLUGIN_DIR=$(ls -d artifact-temp/ultimate-multisite* | head -1)
echo "path=$PLUGIN_DIR" >> $GITHUB_OUTPUT
echo "name=$ARCHIVE_NAME" >> $GITHUB_OUTPUT
echo "Prepared artifact: $PLUGIN_DIR as $ARCHIVE_NAME"
- name: Upload build artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: ${{ steps.artifact.outputs.name }}
path: ${{ steps.artifact.outputs.path }}
retention-days: 30
- name: Generate nightly.link URL
id: nightlylink
run: |
# Create public download URL using nightly.link
# nightly.link will automatically add .zip extension
NIGHTLY_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ steps.artifact.outputs.name }}.zip"
echo "url=$NIGHTLY_URL" >> $GITHUB_OUTPUT
echo "Public artifact URL: $NIGHTLY_URL"
- name: Create Playground Blueprint
id: blueprint
run: |
# Create a blueprint JSON for WordPress Playground
cat > pr-blueprint.json <<'EOF'
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"meta": {
"author": "Ultimate Multisite",
"title": "Ultimate Multisite PR #${{ github.event.pull_request.number }} Test",
"description": "Test build from PR #${{ github.event.pull_request.number }}"
},
"landingPage": "/wp-admin/network/admin.php?page=wp-ultimo-setup",
"preferredVersions": {
"php": "8.3",
"wp": "latest"
},
"phpExtensionBundles": ["kitchen-sink"],
"features": {
"networking": true
},
"plugins": [
{
"resource": "url",
"url": "PLUGIN_URL_PLACEHOLDER"
}
],
"steps": [
{
"step": "enableMultisite"
},
{
"step": "wp-cli",
"command": "wp site create --slug=site01"
},
{
"step": "wp-cli",
"command": "wp plugin activate ultimate-multisite --network"
},
{
"step": "login",
"username": "admin",
"password": "password"
}
]
}
EOF
# Replace placeholder with actual nightly.link URL
sed -i "s|PLUGIN_URL_PLACEHOLDER|${{ steps.nightlylink.outputs.url }}|g" pr-blueprint.json
# URL encode the blueprint for Playground
BLUEPRINT_JSON=$(cat pr-blueprint.json | jq -c .)
BLUEPRINT_ENCODED=$(echo "$BLUEPRINT_JSON" | jq -sRr @base64)
PLAYGROUND_URL="https://playground.wordpress.net/#${BLUEPRINT_ENCODED}"
echo "url=$PLAYGROUND_URL" >> $GITHUB_OUTPUT
echo "Playground URL generated"
- name: Comment on PR
# Fork PRs don't have write access to the base repo — skip gracefully.
# The build artifact is still uploaded and accessible via the Actions run URL.
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const comment = `## 🔨 Build Complete - Ready for Testing!
### 📦 Download Build Artifact (Recommended)
Download the zip build, upload to WordPress and test:
- **Build:** \`${{ steps.artifact.outputs.name }}\`
- **[⬇️ Download from GitHub Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**
- **[⬇️ Download without Github Account (nightly.link)](${{ steps.nightlylink.outputs.url }})**
### 🌐 Test in WordPress Playground (Very Experimental)
Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.
**[🚀 Launch in Playground](${{ steps.blueprint.outputs.url }})**
Login credentials: \`admin\` / \`password\`
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});