Skip to content

Commit 4908534

Browse files
authored
Add live playground links using woocommerce as inspiration (#347)
* Add live playground links using woocommerce as inspiration * Fix incorrect paths * Change name of plugin artifact * Attempting to make the playground url work * Drop the run id and simplify the versioning * Drop the run id and simplify the versioning * Use the uploaded artifact url as the blueprint url instead * Fix the name of the workflow and the formatting * Exclude the js file for generating playground links from the job * Run playground build job on all PRs * Remove the offending line from the playground job * Setup nodejs and php * Drop the colon * Correctly read the artifact url * Make the artifact url a string * Make the zip file valid * Corrected the artifact generation * Fix the link breakage, and match it to the playground proxy * Update the playground url * Fix the formatting * extra h * Remove uri encoding * Attempting to make the script redundant * Tweak the installing message * Fixing up the link * Trying to fix the link * uri encode the spaces * Forgot a character * Get the script working again to ensure comments are updated * Lint fix * Fix the url for playground * Replace composer.lock with the one from trunk * Attempting to reduce permissions that are risky * Turns out you need permission to write to a PR
1 parent e6693d4 commit 4908534

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build Live Branch
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- trunk
7+
paths-ignore:
8+
- 'docs/**'
9+
- 'examples/**'
10+
- 'bin/**'
11+
- '**/tests/**'
12+
- '**/*.md'
13+
- '.github/**'
14+
- '!.github/workflows/pr-build-live-branch.yml'
15+
- '!.github/workflows/scripts/generate-playground-blueprint.js'
16+
17+
concurrency:
18+
# Cancel concurrent jobs on pull_request but not push, by including the run_id in the concurrency group for the latter.
19+
group: build-${{ github.event_name == 'push' && github.run_id || 'pr' }}-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
env:
23+
FORCE_COLOR: 1
24+
25+
jobs:
26+
build:
27+
if: github.repository_owner == 'Automattic' && github.event.pull_request.draft == false && github.event.pull_request.user.login != 'github-actions[bot]'
28+
runs-on: ubuntu-latest
29+
permissions:
30+
pull-requests: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: '8.2'
40+
41+
- name: Setup Node.js
42+
uses: Automattic/vip-actions/nodejs-setup@trunk
43+
with:
44+
node-version-file: .nvmrc
45+
ignore-scripts: true
46+
47+
- name: Prepare plugin zips
48+
id: prepare
49+
run: |
50+
echo "Generating zip file..."
51+
cd "$GITHUB_WORKSPACE" || exit
52+
npm run plugin-zip
53+
echo "Generated zip file..."
54+
mkdir "$GITHUB_WORKSPACE/zips"
55+
mv remote-data-blocks.zip "$GITHUB_WORKSPACE/zips/remote-data-blocks.zip"
56+
echo "Moved zip file to zips directory..."
57+
mkdir "$GITHUB_WORKSPACE/unzips"
58+
echo "Created unzips directory..."
59+
unzip "$GITHUB_WORKSPACE/zips/remote-data-blocks.zip" -d "$GITHUB_WORKSPACE/unzips/remote-data-blocks"
60+
echo "Unzipped zip file..."
61+
62+
- name: Create playground artifact
63+
id: create-playground-artifact-step
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: remote-data-blocks-${{ github.event.pull_request.number }}
67+
path: unzips/remote-data-blocks
68+
retention-days: 7
69+
if-no-files-found: 'error'
70+
overwrite: true
71+
72+
- name: Comment on PR with WordPress Playground details
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const { run } = require('./.github/workflows/scripts/generate-playground-blueprint');
77+
run({ github, context });
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
async function run( { github, context } ) {
2+
const commentInfo = {
3+
owner: context.repo.owner,
4+
repo: context.repo.repo,
5+
issue_number: context.issue.number,
6+
};
7+
8+
const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
9+
let existingCommentId = null;
10+
11+
for ( const currentComment of comments ) {
12+
if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test this PR in' ) ) {
13+
existingCommentId = currentComment.id;
14+
break;
15+
}
16+
}
17+
18+
const body = `Test this PR in [WordPress Playground](https://wordpress-playground.atomicsites.blog/#{"landingPage":"/wp-admin/admin.php?page=remote-data-blocks-settings","features":{"networking":true},"login":true,"preferredVersions":{"php":"8.2","wp":"latest"},"steps":[{"step":"setSiteOptions","options":{"blogname":"Remote%20Data%20Blocks%20PR#${ context.issue.number }","blogdescription":"Explore%20the%20Remote%20Data%20Blocks%20plugin%20in%20a%20WordPress%20Playground"}},{"step":"defineWpConfigConsts","consts":{"USE_PLAYGROUND_CORS_PROXY":true}},{"step":"installPlugin","pluginData":{"caption":"Installing%20RDB","resource":"url","url":"https://wordpress-playground.atomicsites.blog/plugin-proxy.php?org=Automattic&repo=remote-data-blocks&workflow=Build%20Live%20Branch&artifact=remote-data-blocks-${ context.issue.number }&pr=${ context.issue.number }"},"options":{"activate":true,"targetFolderName":"remote-data-blocks"}}]}).`;
19+
20+
if ( existingCommentId ) {
21+
await github.rest.issues.updateComment( {
22+
owner: commentInfo.owner,
23+
repo: commentInfo.repo,
24+
comment_id: existingCommentId,
25+
body: body,
26+
} );
27+
} else {
28+
commentInfo.body = body;
29+
await github.rest.issues.createComment( commentInfo );
30+
}
31+
}
32+
33+
module.exports = { run };

0 commit comments

Comments
 (0)