Skip to content

Commit fa25a9c

Browse files
authored
Merge pull request #619 from ProgressPlanner/jdv/improve-playground-workflow
Improve playground workflow
2 parents 48562df + d07c88a commit fa25a9c

4 files changed

Lines changed: 147 additions & 17 deletions

File tree

.github/workflows/playground-merged.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,35 @@ jobs:
1010
if: github.event.pull_request.merged == true
1111
runs-on: ubuntu-latest
1212
permissions:
13+
contents: read
1314
pull-requests: write
15+
actions: read
1416
steps:
17+
- name: Prepare blueprint with artifact link
18+
id: blueprint
19+
run: |
20+
set -euxo pipefail
21+
ARTIFACT_URL="${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip"
22+
23+
# Use Node.js to parse, modify, and stringify the JSON
24+
BLUEPRINT=$(node -e "
25+
const fs = require('fs');
26+
const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8'));
27+
blueprint.plugins = blueprint.plugins.map(plugin =>
28+
plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin
29+
);
30+
console.log(JSON.stringify(blueprint));
31+
")
32+
33+
# Base64 encode the blueprint
34+
ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0)
35+
36+
echo "blueprint=$ENCODED_BLUEPRINT" >> "$GITHUB_OUTPUT"
37+
38+
# Comment with a Playground link that installs from the artifact ZIP
1539
- uses: mshick/add-pr-comment@v2
1640
with:
1741
message: |
1842
**Test merged PR on Playground**
19-
[Test this pull request on the Playground](https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3D${{ github.repository }}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip).
43+
[Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }})
44+
or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip)

.github/workflows/playground.yml

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,89 @@ on:
44
pull_request:
55

66
jobs:
7-
test:
7+
playground:
88
runs-on: ubuntu-latest
99
permissions:
10+
contents: read
1011
pull-requests: write
12+
actions: read
13+
1114
steps:
15+
- uses: actions/checkout@v4
16+
17+
# Prepare a folder named exactly like the repo as the plugin root.
18+
# If the repo already has such a folder (common for WP plugins), use it.
19+
# Otherwise, stage one and copy root files into it (excluding CI junk).
20+
- name: Prepare plugin folder
21+
id: prep
22+
run: |
23+
set -euxo pipefail
24+
REPO="${{ github.event.repository.name }}"
25+
if [ -d "$REPO" ]; then
26+
# Plugin already lives in a subfolder named like the repo
27+
echo "PKG_DIR=$REPO" >> "$GITHUB_OUTPUT"
28+
else
29+
# Create a clean staging dir to avoid copying into itself
30+
STAGE="${REPO}-pkg"
31+
mkdir -p "$STAGE/$REPO"
32+
rsync -a \
33+
--exclude='.git' \
34+
--exclude='.github' \
35+
--exclude='node_modules' \
36+
--exclude="${STAGE}" \
37+
./ "$STAGE/$REPO/"
38+
echo "PKG_DIR=$STAGE/$REPO" >> "$GITHUB_OUTPUT"
39+
40+
fi
41+
42+
- name: Update plugin version with PR number
43+
run: |
44+
set -euxo pipefail
45+
PLUGIN_FILE="${{ steps.prep.outputs.PKG_DIR }}/${{ github.event.repository.name }}.php"
46+
PR_NUMBER="${{ github.event.number }}"
47+
48+
# Extract current version and add PR number
49+
CURRENT_VERSION=$(grep -o "Version:[[:space:]]*[0-9.]*" "$PLUGIN_FILE" | sed 's/Version:[[:space:]]*//')
50+
NEW_VERSION="${CURRENT_VERSION} - PR ${PR_NUMBER}"
51+
52+
# Replace the version line
53+
sed -i "s/Version:[[:space:]]*[0-9.]*/Version: ${NEW_VERSION}/" "$PLUGIN_FILE"
54+
55+
- name: Prepare blueprint with artifact link
56+
id: blueprint
57+
run: |
58+
set -euxo pipefail
59+
ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip"
60+
61+
# Use Node.js to parse, modify, and stringify the JSON
62+
BLUEPRINT=$(node -e "
63+
const fs = require('fs');
64+
const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8'));
65+
blueprint.plugins = blueprint.plugins.map(plugin =>
66+
plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin
67+
);
68+
console.log(JSON.stringify(blueprint));
69+
")
70+
71+
# Base64 encode the blueprint
72+
ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0)
73+
74+
echo "blueprint=$ENCODED_BLUEPRINT" >> "$GITHUB_OUTPUT"
75+
76+
# Upload the FOLDER (not a .zip). The artifact service zips it for us,
77+
# keeping the top-level folder name inside the archive.
78+
- name: Upload plugin artifact
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: ${{ github.event.repository.name }}
82+
path: ${{ steps.prep.outputs.PKG_DIR }}
83+
# Optional: faster uploads for already-compressed assets
84+
compression-level: 0
85+
86+
# Comment with a Playground link that installs from the artifact ZIP
1287
- uses: mshick/add-pr-comment@v2
1388
with:
1489
message: |
1590
**Test on Playground**
16-
[Test this pull request on the Playground](https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3D${{ github.repository }}%26branch%3D${{ github.head_ref }}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip).
91+
[Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }})
92+
or [download the zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip)
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
2-
"landingPage": "\/wp-admin\/admin.php?page=progress-planner",
3-
"steps": [
4-
{
5-
"step": "login",
6-
"username": "admin",
7-
"password": "password"
8-
},
9-
{
10-
"step": "defineWpConfigConsts",
11-
"consts": {
12-
"IS_PLAYGROUND_PREVIEW": true
13-
}
14-
}
15-
]
2+
"landingPage": "/wp-admin/admin.php?page=progress-planner",
3+
"features": {
4+
"networking": true
5+
},
6+
"plugins": [
7+
"progress-planner"
8+
],
9+
"steps": [
10+
{
11+
"step": "login"
12+
}
13+
]
1614
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"landingPage": "/wp-admin/admin.php?page=progress-planner",
3+
"features": {
4+
"networking": true
5+
},
6+
"plugins": [
7+
"progress-planner",
8+
"wordpress-seo"
9+
],
10+
"steps": [
11+
{
12+
"step": "login"
13+
},
14+
{
15+
"step": "setSiteOptions",
16+
"options": {
17+
"wpseo": "a:5:{s:22:\"show_onboarding_notice\";b:0;s:36:\"dismiss_configuration_workout_notice\";b:1;s:18:\"first_time_install\";b:0;s:34:\"activation_redirect_timestamp_free\";i:1652258756;s:34:\"should_redirect_after_install_free\";b:0;}"
18+
}
19+
},
20+
{
21+
"step": "defineWpConfigConsts",
22+
"consts": {
23+
"IS_PLAYGROUND_PREVIEW": true,
24+
"WPSEO_PREMIUM_FILE": "override",
25+
"WPSEO_PREMIUM_VERSION": "24.8.1",
26+
"YOAST_ENVIRONMENT": "development",
27+
"WP_ENVIRONMENT_TYPE": "development"
28+
}
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)