Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 38 additions & 64 deletions .github/workflows/build-plugin-with-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
permissions:
contents: write
pull-requests: write
actions: read # wordpress-playground-action verifies the artifact exists before linking

jobs:
build-plugin:
Expand Down Expand Up @@ -254,56 +255,28 @@ jobs:
path: ${{ env.REF_ZIP_FOLDER }}
if-no-files-found: error

- name: Resolve public plugin URLs for Playground
id: playground-zips
if: github.event.repository.private == false
run: |
PRIMARY_PLUGIN_ZIP_URL=""
REF_PLUGIN_ZIP_URL=""

if [ -n "${PRIMARY_ZIP_NAME:-}" ]; then
if [ "${{ github.event_name }}" = "release" ]; then
PRIMARY_PLUGIN_ZIP_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${{ github.event.release.tag_name }}/${PRIMARY_ZIP_NAME}"
else
PRIMARY_PLUGIN_ZIP_URL="https://nightly.link/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/${PRIMARY_ZIP_NAME_NO_EXT}.zip"
fi
fi

if [ "${{ steps.check_ref.outputs.need_ref_build }}" = "true" ] && [ -n "${REF_ZIP_NAME:-}" ]; then
if [ "${{ github.event_name }}" = "release" ]; then
REF_PLUGIN_ZIP_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${{ github.event.release.tag_name }}/${REF_ZIP_NAME}"
else
REF_PLUGIN_ZIP_URL="https://nightly.link/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/${REF_ZIP_NAME_NO_EXT}.zip"
fi
fi

echo "primary_plugin_zip_url=$PRIMARY_PLUGIN_ZIP_URL" >> "$GITHUB_OUTPUT"
echo "ref_plugin_zip_url=$REF_PLUGIN_ZIP_URL" >> "$GITHUB_OUTPUT"

- name: Build WordPress Playground links
if: github.event.repository.private == false
run: |
export PRIMARY_PLUGIN_ZIP_URL='${{ steps.playground-zips.outputs.primary_plugin_zip_url }}'
export REF_PLUGIN_ZIP_URL='${{ steps.playground-zips.outputs.ref_plugin_zip_url }}'

build_playground_url() {
local plugin_url="$1"
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"
}

PRIMARY_PLAYGROUND_URL=""
REF_PLAYGROUND_URL=""

if [ -n "$PRIMARY_PLUGIN_ZIP_URL" ]; then
PRIMARY_PLAYGROUND_URL="$(build_playground_url "$PRIMARY_PLUGIN_ZIP_URL")"
fi

if [ -n "$REF_PLUGIN_ZIP_URL" ]; then
REF_PLAYGROUND_URL="$(build_playground_url "$REF_PLUGIN_ZIP_URL")"
fi

echo "PRIMARY_PLAYGROUND_URL=$PRIMARY_PLAYGROUND_URL" >> "$GITHUB_ENV"
echo "REF_PLAYGROUND_URL=$REF_PLAYGROUND_URL" >> "$GITHUB_ENV"
# Playground links are built by pattonwebz/wordpress-playground-action, which
# resolves the uploaded artifact to a public nightly.link URL and assembles the
# blueprint.
#
# Only the primary build gets a link. Not run on `release`: releases carry the
# real zip as a release asset, and nightly.link only serves Actions artifacts.
# The ref (woocommerce) build gets no link either - `need_ref_build` is never
# true for a pull_request, so a ref link could only ever have surfaced in a
# manual-dispatch job log, never in the PR comment.
#
# plugin-slug is set explicitly rather than inferred: the action strips a
# version/hash suffix (accessibility-checker-1.47.0-123-abc1234 -> accessibility-checker)
# but would leave the whole "…-1.47.0-ref-woocommerce-abc1234" shape intact,
# so pinning it keeps the activation path correct regardless of artifact naming.
- name: Playground link (primary build)
id: playground_primary
if: steps.setref.outputs.skip_primary != 'true' && github.event_name != 'release'
uses: pattonwebz/wordpress-playground-action@v0
with:
artifact-name: ${{ env.PRIMARY_ZIP_NAME_NO_EXT }}
plugin-slug: accessibility-checker
github-token: ${{ secrets.GITHUB_TOKEN }}
Comment thread
pattonwebz marked this conversation as resolved.
Outdated

- name: Upload to release (both zips)
if: github.event_name == 'release'
Expand All @@ -319,6 +292,10 @@ jobs:
- name: Comment on PR with primary build details
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
# Routed through env: rather than interpolated into the script body - a
# ${{ }} substitution lands in the JS source text before Node parses it.
PRIMARY_PLAYGROUND_URL: ${{ steps.playground_primary.outputs.playground-url }}
with:
script: |
const prNumber = context.payload.pull_request.number;
Expand All @@ -341,14 +318,9 @@ jobs:
const primaryPlaygroundUrl = process.env.PRIMARY_PLAYGROUND_URL;
const primaryPlaygroundLine = primaryPlaygroundUrl
? `\n- **Playground (primary)**: [Open with plugin preinstalled](${primaryPlaygroundUrl})`
: `\n- **Playground (primary)**: Not available for this run (repository may be private or plugin ZIP URL is not publicly accessible).`;

const refPlaygroundUrl = process.env.REF_PLAYGROUND_URL;
const refPlaygroundLine = refPlaygroundUrl
? `\n- **Playground (ref)**: [Open with plugin preinstalled](${refPlaygroundUrl})`
: '';
: `\n- **Playground (primary)**: Not available for this run.`;

const body = `✅ Accessibility Checker build (primary only)\n\n- **Artifact**: [Download ${primaryName}.zip](${downloadUrl})\n- **Workflow run**: [View logs](${runUrl})${primaryPlaygroundLine}${refPlaygroundLine}`;
const body = `✅ Accessibility Checker build (primary only)\n\n- **Artifact**: [Download ${primaryName}.zip](${downloadUrl})\n- **Workflow run**: [View logs](${runUrl})${primaryPlaygroundLine}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -377,25 +349,27 @@ jobs:
}

- name: Summary
env:
PRIMARY_PLAYGROUND_URL: ${{ steps.playground_primary.outputs.playground-url }}
MODE: ${{ steps.setref.outputs.mode }}
SKIP_PRIMARY: ${{ steps.setref.outputs.skip_primary }}
run: |
echo "=== Build Summary ==="
echo "Mode: ${{ steps.setref.outputs.mode }}"
echo "Primary zip (empty ref): ${{ env.PRIMARY_ZIP_PATH }}"
if [ -n "${PRIMARY_PLAYGROUND_URL:-}" ]; then
echo "Playground (primary): ${PRIMARY_PLAYGROUND_URL}"
elif [ "${MODE}" = "release" ]; then
echo "Playground (primary): not built (releases ship the zip as a release asset)"
elif [ "${SKIP_PRIMARY}" = "true" ]; then
echo "Playground (primary): not built (this dispatch passed a ref param, so only the ref zip was built)"
else
echo "Playground (primary): skipped (repo is private or URL unavailable)"
echo "Playground (primary): not built for this run"
fi
if [ "${{ steps.check_ref.outputs.need_ref_build }}" = "true" ]; then
echo "Ref zip (ref=${{ steps.setref.outputs.ref_param }}): ${{ env.REF_ZIP_PATH }}"
if [ -n "${REF_PLAYGROUND_URL:-}" ]; then
echo "Playground (ref): ${REF_PLAYGROUND_URL}"
else
echo "Playground (ref): skipped (repo is private or URL unavailable)"
fi
else
echo "Ref zip: Not built"
echo "Playground (ref): Not built"
fi
if [ "${{ github.event_name }}" = "release" ]; then
echo "Uploaded to release: ${{ github.event.release.html_url }}"
Expand Down
Loading