Skip to content

Commit 560d978

Browse files
authored
Merge pull request #1603 from equalizedigital/william/no-issue/add-playground-link-support-when-building-zips-on-prs
Add handling to create playground links when creating zips for testing on a PR
2 parents d33e510 + 2b62b83 commit 560d978

1 file changed

Lines changed: 73 additions & 1 deletion

File tree

.github/workflows/build-plugin-with-ref.yml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,57 @@ jobs:
253253
path: ${{ env.REF_ZIP_FOLDER }}
254254
if-no-files-found: error
255255

256+
- name: Resolve public plugin URLs for Playground
257+
id: playground-zips
258+
if: github.event.repository.private == false
259+
run: |
260+
PRIMARY_PLUGIN_ZIP_URL=""
261+
REF_PLUGIN_ZIP_URL=""
262+
263+
if [ -n "${PRIMARY_ZIP_NAME:-}" ]; then
264+
if [ "${{ github.event_name }}" = "release" ]; then
265+
PRIMARY_PLUGIN_ZIP_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${{ github.event.release.tag_name }}/${PRIMARY_ZIP_NAME}"
266+
else
267+
PRIMARY_PLUGIN_ZIP_URL="https://nightly.link/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/${PRIMARY_ZIP_NAME_NO_EXT}.zip"
268+
fi
269+
fi
270+
271+
if [ "${{ steps.check_ref.outputs.need_ref_build }}" = "true" ] && [ -n "${REF_ZIP_NAME:-}" ]; then
272+
if [ "${{ github.event_name }}" = "release" ]; then
273+
REF_PLUGIN_ZIP_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${{ github.event.release.tag_name }}/${REF_ZIP_NAME}"
274+
else
275+
REF_PLUGIN_ZIP_URL="https://nightly.link/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/${REF_ZIP_NAME_NO_EXT}.zip"
276+
fi
277+
fi
278+
279+
echo "primary_plugin_zip_url=$PRIMARY_PLUGIN_ZIP_URL" >> "$GITHUB_OUTPUT"
280+
echo "ref_plugin_zip_url=$REF_PLUGIN_ZIP_URL" >> "$GITHUB_OUTPUT"
281+
282+
- name: Build WordPress Playground links
283+
if: github.event.repository.private == false
284+
run: |
285+
export PRIMARY_PLUGIN_ZIP_URL='${{ steps.playground-zips.outputs.primary_plugin_zip_url }}'
286+
export REF_PLUGIN_ZIP_URL='${{ steps.playground-zips.outputs.ref_plugin_zip_url }}'
287+
288+
build_playground_url() {
289+
local plugin_url="$1"
290+
python3 -c 'import base64,json,sys,urllib.parse; plugin_url=sys.argv[1]; blueprint={"landingPage":"/wp-admin/plugins.php","steps":[{"step":"login"},{"step":"installPlugin","pluginZipFile":{"resource":"url","url":plugin_url}},{"step":"activatePlugin","pluginPath":"accessibility-checker/accessibility-checker.php"}]}; blueprint_json=json.dumps(blueprint,separators=(",",":")); data_uri="data:application/json;base64,"+base64.b64encode(blueprint_json.encode("utf-8")).decode("ascii"); encoded_blueprint_url=urllib.parse.quote(data_uri,safe=""); print(f"https://playground.wordpress.net/?blueprint-url={encoded_blueprint_url}")' "$plugin_url"
291+
}
292+
293+
PRIMARY_PLAYGROUND_URL=""
294+
REF_PLAYGROUND_URL=""
295+
296+
if [ -n "$PRIMARY_PLUGIN_ZIP_URL" ]; then
297+
PRIMARY_PLAYGROUND_URL="$(build_playground_url "$PRIMARY_PLUGIN_ZIP_URL")"
298+
fi
299+
300+
if [ -n "$REF_PLUGIN_ZIP_URL" ]; then
301+
REF_PLAYGROUND_URL="$(build_playground_url "$REF_PLUGIN_ZIP_URL")"
302+
fi
303+
304+
echo "PRIMARY_PLAYGROUND_URL=$PRIMARY_PLAYGROUND_URL" >> "$GITHUB_ENV"
305+
echo "REF_PLAYGROUND_URL=$REF_PLAYGROUND_URL" >> "$GITHUB_ENV"
306+
256307
- name: Upload to release (both zips)
257308
if: github.event_name == 'release'
258309
uses: softprops/action-gh-release@v2
@@ -286,7 +337,17 @@ jobs:
286337
? `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts/${artifact.id}`
287338
: runUrl;
288339
289-
const body = `✅ Accessibility Checker build (primary only)\n\n- **Artifact**: [Download ${primaryName}.zip](${downloadUrl})\n- **Workflow run**: [View logs](${runUrl})`;
340+
const primaryPlaygroundUrl = process.env.PRIMARY_PLAYGROUND_URL;
341+
const primaryPlaygroundLine = primaryPlaygroundUrl
342+
? `\n- **Playground (primary)**: [Open with plugin preinstalled](${primaryPlaygroundUrl})`
343+
: `\n- **Playground (primary)**: Not available for this run (repository may be private or plugin ZIP URL is not publicly accessible).`;
344+
345+
const refPlaygroundUrl = process.env.REF_PLAYGROUND_URL;
346+
const refPlaygroundLine = refPlaygroundUrl
347+
? `\n- **Playground (ref)**: [Open with plugin preinstalled](${refPlaygroundUrl})`
348+
: '';
349+
350+
const body = `✅ Accessibility Checker build (primary only)\n\n- **Artifact**: [Download ${primaryName}.zip](${downloadUrl})\n- **Workflow run**: [View logs](${runUrl})${primaryPlaygroundLine}${refPlaygroundLine}`;
290351
await github.rest.issues.createComment({
291352
owner: context.repo.owner,
292353
repo: context.repo.repo,
@@ -319,10 +380,21 @@ jobs:
319380
echo "=== Build Summary ==="
320381
echo "Mode: ${{ steps.setref.outputs.mode }}"
321382
echo "Primary zip (empty ref): ${{ env.PRIMARY_ZIP_PATH }}"
383+
if [ -n "${PRIMARY_PLAYGROUND_URL:-}" ]; then
384+
echo "Playground (primary): ${PRIMARY_PLAYGROUND_URL}"
385+
else
386+
echo "Playground (primary): skipped (repo is private or URL unavailable)"
387+
fi
322388
if [ "${{ steps.check_ref.outputs.need_ref_build }}" = "true" ]; then
323389
echo "Ref zip (ref=${{ steps.setref.outputs.ref_param }}): ${{ env.REF_ZIP_PATH }}"
390+
if [ -n "${REF_PLAYGROUND_URL:-}" ]; then
391+
echo "Playground (ref): ${REF_PLAYGROUND_URL}"
392+
else
393+
echo "Playground (ref): skipped (repo is private or URL unavailable)"
394+
fi
324395
else
325396
echo "Ref zip: Not built"
397+
echo "Playground (ref): Not built"
326398
fi
327399
if [ "${{ github.event_name }}" = "release" ]; then
328400
echo "Uploaded to release: ${{ github.event.release.html_url }}"

0 commit comments

Comments
 (0)