From 286781175a134beb23c41e49174840dad03c2b2c Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 08:44:44 +0100 Subject: [PATCH 1/8] Try it --- .github/workflows/playground-merged.yml | 2 +- .github/workflows/playground.yml | 21 +++++++++++++++++++-- .wordpress-org/blueprints/playground.json | 3 +-- README.md | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/playground-merged.yml b/.github/workflows/playground-merged.yml index 0a129e50a..5cb421ffc 100644 --- a/.github/workflows/playground-merged.yml +++ b/.github/workflows/playground-merged.yml @@ -42,5 +42,5 @@ jobs: with: message: | **Test merged PR on Playground** - [Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }}) + [Test this pull request on the Playground](https://playground.progressplanner.com/#${{ steps.blueprint.outputs.blueprint }}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index cdfc5863c..d9846aabe 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -78,16 +78,33 @@ jobs: run: | set -euxo pipefail ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" + PR_LABELS='${{ toJson(github.event.pull_request.labels) }}' # Use Node.js to parse, modify, and stringify the JSON BLUEPRINT=$(node -e " const fs = require('fs'); const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); + + // Replace the current plugin with artifact URL blueprint.plugins = blueprint.plugins.map(plugin => plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin ); + + // Extract plugin slugs from PR labels that start with 'plugin:' + const prLabels = JSON.parse(process.env.PR_LABELS || '[]'); + const pluginSlugs = prLabels + .filter(label => label.name && label.name.startsWith('plugin:')) + .map(label => label.name.replace(/^plugin:/, '')); + + // Add plugin slugs to the plugins array (avoid duplicates) + pluginSlugs.forEach(slug => { + if (!blueprint.plugins.includes(slug)) { + blueprint.plugins.push(slug); + } + }); + console.log(JSON.stringify(blueprint)); - ") + " PR_LABELS="$PR_LABELS") # Base64 encode the blueprint ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0) @@ -109,5 +126,5 @@ jobs: with: message: | **Test on Playground** - [Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }}) + [Test this pull request on the Playground](https://playground.progressplanner.com/#${{ steps.blueprint.outputs.blueprint }}) or [download the zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip) diff --git a/.wordpress-org/blueprints/playground.json b/.wordpress-org/blueprints/playground.json index f1e183750..e570e5a5d 100644 --- a/.wordpress-org/blueprints/playground.json +++ b/.wordpress-org/blueprints/playground.json @@ -4,8 +4,7 @@ "networking": true }, "plugins": [ - "progress-planner", - "wordpress-seo" + "progress-planner" ], "steps": [ { diff --git a/README.md b/README.md index 6b6e782e5..783055156 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![WordPress Plugin Rating](https://img.shields.io/wordpress/plugin/stars/progress-planner.svg)](https://wordpress.org/support/plugin/progress-planner/reviews/) [![GitHub](https://img.shields.io/github/license/ProgressPlanner/progress-planner.svg)](https://github.com/ProgressPlanner/progress-planner/blob/main/LICENSE) -[![Try Progress Planner on the WordPress playground](https://img.shields.io/badge/Try%20Progress%20Planner%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3DProgressPlanner/progress-planner) +[![Try Progress Planner on the WordPress playground](https://img.shields.io/badge/Try%20Progress%20Planner%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.progressplanner.com/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3DProgressPlanner/progress-planner) # Progress Planner From 5ea345eb41cb4bf87f79fd805415c616d6048be8 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 08:49:28 +0100 Subject: [PATCH 2/8] Re-run when a label is added --- .github/workflows/playground.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index d9846aabe..c0f537c51 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -2,6 +2,7 @@ name: Playground Comment on: pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] jobs: playground: From 9d65358ccf8355c30dba46d5ed50c1c5176cdb41 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 09:47:38 +0100 Subject: [PATCH 3/8] Switch to WP playground, add some debug --- .github/workflows/playground-merged.yml | 2 +- .github/workflows/playground.yml | 4 +++- README.md | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playground-merged.yml b/.github/workflows/playground-merged.yml index 5cb421ffc..0a129e50a 100644 --- a/.github/workflows/playground-merged.yml +++ b/.github/workflows/playground-merged.yml @@ -42,5 +42,5 @@ jobs: with: message: | **Test merged PR on Playground** - [Test this pull request on the Playground](https://playground.progressplanner.com/#${{ steps.blueprint.outputs.blueprint }}) + [Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index c0f537c51..87b344b80 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -99,6 +99,8 @@ jobs: // Add plugin slugs to the plugins array (avoid duplicates) pluginSlugs.forEach(slug => { + console.log('slug', slug); + console.log('blueprint.plugins', blueprint.plugins); if (!blueprint.plugins.includes(slug)) { blueprint.plugins.push(slug); } @@ -127,5 +129,5 @@ jobs: with: message: | **Test on Playground** - [Test this pull request on the Playground](https://playground.progressplanner.com/#${{ steps.blueprint.outputs.blueprint }}) + [Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }}) or [download the zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip) diff --git a/README.md b/README.md index 783055156..6b6e782e5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![WordPress Plugin Rating](https://img.shields.io/wordpress/plugin/stars/progress-planner.svg)](https://wordpress.org/support/plugin/progress-planner/reviews/) [![GitHub](https://img.shields.io/github/license/ProgressPlanner/progress-planner.svg)](https://github.com/ProgressPlanner/progress-planner/blob/main/LICENSE) -[![Try Progress Planner on the WordPress playground](https://img.shields.io/badge/Try%20Progress%20Planner%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.progressplanner.com/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3DProgressPlanner/progress-planner) +[![Try Progress Planner on the WordPress playground](https://img.shields.io/badge/Try%20Progress%20Planner%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3DProgressPlanner/progress-planner) # Progress Planner From fe89b5a6e8e85949b4c66d20c6f75d33d5b75680 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 09:51:14 +0100 Subject: [PATCH 4/8] github.event.pull_request.labels is only populated on labeled and unlabeled events. On opened, synchronize, or reopened, it may be empty or missing, work around that --- .github/workflows/playground.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index 87b344b80..ea78f38b2 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -79,7 +79,12 @@ jobs: run: | set -euxo pipefail ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" - PR_LABELS='${{ toJson(github.event.pull_request.labels) }}' + + # Fetch PR labels from GitHub API + PR_LABELS_JSON=$(curl -s \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/labels") # Use Node.js to parse, modify, and stringify the JSON BLUEPRINT=$(node -e " @@ -92,22 +97,30 @@ jobs: ); // Extract plugin slugs from PR labels that start with 'plugin:' - const prLabels = JSON.parse(process.env.PR_LABELS || '[]'); + const prLabelsJson = process.env.PR_LABELS_JSON || '[]'; + let prLabels = []; + try { + prLabels = JSON.parse(prLabelsJson); + } catch (e) { + console.error('Error parsing PR labels JSON:', e); + console.error('Raw JSON:', prLabelsJson); + } + console.log('PR Labels:', JSON.stringify(prLabels, null, 2)); + const pluginSlugs = prLabels .filter(label => label.name && label.name.startsWith('plugin:')) .map(label => label.name.replace(/^plugin:/, '')); + console.log('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); // Add plugin slugs to the plugins array (avoid duplicates) pluginSlugs.forEach(slug => { - console.log('slug', slug); - console.log('blueprint.plugins', blueprint.plugins); if (!blueprint.plugins.includes(slug)) { blueprint.plugins.push(slug); } }); console.log(JSON.stringify(blueprint)); - " PR_LABELS="$PR_LABELS") + " PR_LABELS_JSON="$PR_LABELS_JSON") # Base64 encode the blueprint ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0) From 435d428d8a346dfaf24e415246c165bd5a4437cc Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 09:53:37 +0100 Subject: [PATCH 5/8] Switching to the GitHub CLI (gh) to fetch PR labels, which is simpler and more reliable --- .github/workflows/playground.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index ea78f38b2..1de823a99 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -76,15 +76,14 @@ jobs: - name: Prepare blueprint with artifact link id: blueprint + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -euxo pipefail ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" - # Fetch PR labels from GitHub API - PR_LABELS_JSON=$(curl -s \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/labels") + # Fetch PR labels using GitHub CLI + PR_LABELS_JSON=$(gh pr view ${{ github.event.number }} --json labels --jq '.labels' || echo '[]') # Use Node.js to parse, modify, and stringify the JSON BLUEPRINT=$(node -e " From e9f3c72c0cf524281830757c0b3332e8d0f5d74b Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 19 Dec 2025 09:56:11 +0100 Subject: [PATCH 6/8] Try another fix --- .github/workflows/playground.yml | 76 ++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index 1de823a99..b5b893faa 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -84,42 +84,50 @@ jobs: # Fetch PR labels using GitHub CLI PR_LABELS_JSON=$(gh pr view ${{ github.event.number }} --json labels --jq '.labels' || echo '[]') + echo "Fetched PR labels: $PR_LABELS_JSON" + + # Write PR labels to temp file to avoid shell quoting issues + echo "$PR_LABELS_JSON" > /tmp/pr_labels.json + + # Write Node.js script to temp file + cat > /tmp/prepare_blueprint.js <<'SCRIPT_END' +const fs = require('fs'); +const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); + +// Replace the current plugin with artifact URL +blueprint.plugins = blueprint.plugins.map(plugin => + plugin === process.env.REPO_NAME ? process.env.ARTIFACT_URL : plugin +); + +// Read PR labels from temp file +let prLabels = []; +try { + const prLabelsJson = fs.readFileSync('/tmp/pr_labels.json', 'utf8').trim(); + console.log('Raw PR labels JSON:', prLabelsJson); + prLabels = JSON.parse(prLabelsJson); +} catch (e) { + console.error('Error parsing PR labels JSON:', e); + console.error('Error details:', e.message); +} +console.log('PR Labels:', JSON.stringify(prLabels, null, 2)); + +const pluginSlugs = prLabels + .filter(label => label.name && label.name.startsWith('plugin:')) + .map(label => label.name.replace(/^plugin:/, '')); +console.log('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); + +// Add plugin slugs to the plugins array (avoid duplicates) +pluginSlugs.forEach(slug => { + if (!blueprint.plugins.includes(slug)) { + blueprint.plugins.push(slug); + } +}); + +console.log(JSON.stringify(blueprint)); +SCRIPT_END # Use Node.js to parse, modify, and stringify the JSON - BLUEPRINT=$(node -e " - const fs = require('fs'); - const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); - - // Replace the current plugin with artifact URL - blueprint.plugins = blueprint.plugins.map(plugin => - plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin - ); - - // Extract plugin slugs from PR labels that start with 'plugin:' - const prLabelsJson = process.env.PR_LABELS_JSON || '[]'; - let prLabels = []; - try { - prLabels = JSON.parse(prLabelsJson); - } catch (e) { - console.error('Error parsing PR labels JSON:', e); - console.error('Raw JSON:', prLabelsJson); - } - console.log('PR Labels:', JSON.stringify(prLabels, null, 2)); - - const pluginSlugs = prLabels - .filter(label => label.name && label.name.startsWith('plugin:')) - .map(label => label.name.replace(/^plugin:/, '')); - console.log('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); - - // Add plugin slugs to the plugins array (avoid duplicates) - pluginSlugs.forEach(slug => { - if (!blueprint.plugins.includes(slug)) { - blueprint.plugins.push(slug); - } - }); - - console.log(JSON.stringify(blueprint)); - " PR_LABELS_JSON="$PR_LABELS_JSON") + BLUEPRINT=$(REPO_NAME='${{ github.event.repository.name }}' ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" node /tmp/prepare_blueprint.js) # Base64 encode the blueprint ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0) From b571a5a07cd9f7f9700562621935ba175e42d87a Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Fri, 29 May 2026 09:18:00 +0200 Subject: [PATCH 7/8] Fix Playground link: send blueprint debug logs to stderr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The success-path console.log debug statements wrote to stdout, which BLUEPRINT=$(node ...) captured along with the actual blueprint JSON. The resulting base64 payload decoded to "PR Labels: []\nPlugin slugs: []\n{...}" — invalid JSON that playground.wordpress.net could not parse, breaking the preview link. Switch the three debug logs to console.error so only the blueprint JSON lands on stdout. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/playground.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index b5b893faa..ee9556ee1 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -103,18 +103,18 @@ blueprint.plugins = blueprint.plugins.map(plugin => let prLabels = []; try { const prLabelsJson = fs.readFileSync('/tmp/pr_labels.json', 'utf8').trim(); - console.log('Raw PR labels JSON:', prLabelsJson); + console.error('Raw PR labels JSON:', prLabelsJson); prLabels = JSON.parse(prLabelsJson); } catch (e) { console.error('Error parsing PR labels JSON:', e); console.error('Error details:', e.message); } -console.log('PR Labels:', JSON.stringify(prLabels, null, 2)); +console.error('PR Labels:', JSON.stringify(prLabels, null, 2)); const pluginSlugs = prLabels .filter(label => label.name && label.name.startsWith('plugin:')) .map(label => label.name.replace(/^plugin:/, '')); -console.log('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); +console.error('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); // Add plugin slugs to the plugins array (avoid duplicates) pluginSlugs.forEach(slug => { From 83f9663f82905f9b88a4dca31264d24fdd56a28a Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Tue, 1 Dec 2026 14:32:06 +0100 Subject: [PATCH 8/8] Fix the Playground workflow file and share the blueprint script The Node script was inlined through a heredoc starting at column 0, which ends the YAML `run: |` block. GitHub could not parse playground.yml, so no preview has run on this branch since December. - Move the blueprint logic to .github/scripts/playground-blueprint.js; it only prints the blueprint on stdout, so logs never leak into the link. - Use the same script in playground-merged.yml, so merged-PR previews also get the plugin: plugins now that wordpress-seo is no longer in playground.json by default. - Only re-run on label changes for plugin:* labels, and keep one preview run per PR (concurrency, cancel in progress). Co-Authored-By: Claude Opus 5.5 Signed-off-by: Filip Ilic --- .github/scripts/playground-blueprint.js | 48 ++++++++++++++++++ .github/workflows/playground-merged.yml | 16 +++--- .github/workflows/playground.yml | 66 +++++++------------------ 3 files changed, 73 insertions(+), 57 deletions(-) create mode 100644 .github/scripts/playground-blueprint.js diff --git a/.github/scripts/playground-blueprint.js b/.github/scripts/playground-blueprint.js new file mode 100644 index 000000000..07cf452d5 --- /dev/null +++ b/.github/scripts/playground-blueprint.js @@ -0,0 +1,48 @@ +/** + * Builds the Playground blueprint for PR preview links. + * + * Usage: node .github/scripts/playground-blueprint.js + * + * Env: + * REPO_NAME - plugin slug in playground.json to replace with the zip URL. + * PR_LABELS - JSON array of PR labels ({ name }). Every `plugin:` + * label adds that WordPress.org plugin to the preview. + * + * Prints the blueprint JSON on stdout; diagnostics go to stderr so they + * never end up inside the link. + */ +const fs = require( 'fs' ); + +const zipUrl = process.argv[ 2 ]; +if ( ! zipUrl ) { + console.error( 'Usage: playground-blueprint.js ' ); + process.exit( 1 ); +} + +const blueprint = JSON.parse( + fs.readFileSync( '.wordpress-org/blueprints/playground.json', 'utf8' ) +); + +blueprint.plugins = blueprint.plugins.map( ( plugin ) => + plugin === process.env.REPO_NAME ? zipUrl : plugin +); + +let labels = []; +try { + labels = JSON.parse( process.env.PR_LABELS || '[]' ); +} catch ( e ) { + console.error( `Could not parse PR labels, adding no extra plugins: ${ e.message }` ); +} + +for ( const { name } of labels ) { + if ( typeof name !== 'string' || ! name.startsWith( 'plugin:' ) ) { + continue; + } + const slug = name.slice( 'plugin:'.length ).trim(); + if ( slug && ! blueprint.plugins.includes( slug ) ) { + blueprint.plugins.push( slug ); + } +} + +console.error( `Playground plugins: ${ blueprint.plugins.join( ', ' ) }` ); +process.stdout.write( JSON.stringify( blueprint ) ); diff --git a/.github/workflows/playground-merged.yml b/.github/workflows/playground-merged.yml index 0a129e50a..80d02c919 100644 --- a/.github/workflows/playground-merged.yml +++ b/.github/workflows/playground-merged.yml @@ -18,19 +18,15 @@ jobs: - name: Prepare blueprint with artifact link id: blueprint + env: + REPO_NAME: ${{ github.event.repository.name }} + # Same plugin: labels as the PR preview (playground.yml). + PR_LABELS: ${{ toJSON(github.event.pull_request.labels) }} run: | - set -euxo pipefail + set -euo pipefail ARTIFACT_URL="${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip" - # Use Node.js to parse, modify, and stringify the JSON - BLUEPRINT=$(node -e " - const fs = require('fs'); - const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); - blueprint.plugins = blueprint.plugins.map(plugin => - plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin - ); - console.log(JSON.stringify(blueprint)); - ") + BLUEPRINT=$(node .github/scripts/playground-blueprint.js "$ARTIFACT_URL") # Base64 encode the blueprint ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0) diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index ee9556ee1..32f9b0bff 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -2,10 +2,21 @@ name: Playground Comment on: pull_request: + # labeled/unlabeled: a `plugin:` label changes which plugins the + # preview installs, so the link has to be rebuilt without a new commit. types: [opened, synchronize, reopened, labeled, unlabeled] +# One preview per PR: a newer run (new commit or label) replaces a running one. +concurrency: + group: playground-${{ github.event.number }} + cancel-in-progress: true + jobs: playground: + # Other labels (e.g. "needs review") don't change the preview. + if: >- + (github.event.action != 'labeled' && github.event.action != 'unlabeled') + || startsWith(github.event.label.name, 'plugin:') runs-on: ubuntu-latest permissions: contents: read @@ -78,56 +89,17 @@ jobs: id: blueprint env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO_NAME: ${{ github.event.repository.name }} run: | - set -euxo pipefail + set -euo pipefail ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" - # Fetch PR labels using GitHub CLI - PR_LABELS_JSON=$(gh pr view ${{ github.event.number }} --json labels --jq '.labels' || echo '[]') - echo "Fetched PR labels: $PR_LABELS_JSON" - - # Write PR labels to temp file to avoid shell quoting issues - echo "$PR_LABELS_JSON" > /tmp/pr_labels.json - - # Write Node.js script to temp file - cat > /tmp/prepare_blueprint.js <<'SCRIPT_END' -const fs = require('fs'); -const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); - -// Replace the current plugin with artifact URL -blueprint.plugins = blueprint.plugins.map(plugin => - plugin === process.env.REPO_NAME ? process.env.ARTIFACT_URL : plugin -); - -// Read PR labels from temp file -let prLabels = []; -try { - const prLabelsJson = fs.readFileSync('/tmp/pr_labels.json', 'utf8').trim(); - console.error('Raw PR labels JSON:', prLabelsJson); - prLabels = JSON.parse(prLabelsJson); -} catch (e) { - console.error('Error parsing PR labels JSON:', e); - console.error('Error details:', e.message); -} -console.error('PR Labels:', JSON.stringify(prLabels, null, 2)); - -const pluginSlugs = prLabels - .filter(label => label.name && label.name.startsWith('plugin:')) - .map(label => label.name.replace(/^plugin:/, '')); -console.error('Plugin slugs:', JSON.stringify(pluginSlugs, null, 2)); - -// Add plugin slugs to the plugins array (avoid duplicates) -pluginSlugs.forEach(slug => { - if (!blueprint.plugins.includes(slug)) { - blueprint.plugins.push(slug); - } -}); - -console.log(JSON.stringify(blueprint)); -SCRIPT_END - - # Use Node.js to parse, modify, and stringify the JSON - BLUEPRINT=$(REPO_NAME='${{ github.event.repository.name }}' ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" node /tmp/prepare_blueprint.js) + # Read labels live: on a synchronize run the preview must keep the + # plugin: labels added earlier. + PR_LABELS=$(gh pr view "${{ github.event.number }}" --repo "${{ github.repository }}" --json labels --jq '.labels' || echo '[]') + export PR_LABELS + + BLUEPRINT=$(node .github/scripts/playground-blueprint.js "$ARTIFACT_URL") # Base64 encode the blueprint ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0)