From 758cab0c5f0019e2a51507f07ebdd0be556670be Mon Sep 17 00:00:00 2001 From: Rafael Meneses Date: Thu, 12 Nov 2026 09:34:59 -0300 Subject: [PATCH 1/4] ci: Add "Test the build" comment to pull requests Trying the code of a pull request meant checking the branch out and running the build locally. The only workflow that builds an installable zip, generate-zip.yml, runs on demand or for QIT, and nothing told a reviewer where to get its output. A reviewer without a development environment, a designer for example, had no way in at all. Build the zip on every pull request and post one comment, updated on each push, with the ways to try that build: - WordPress Playground: two links that open a store with WooCommerce and the build in the visitor's browser, one on the Square settings and one on the onboarding wizard. The Blueprint skips WooCommerce's setup wizard, opens the store, turns HPOS on and adds a sample product, so there is nothing to do by hand first. Signing in to Square has to redirect back to the site, and a site in a browser tab has no public address, so the comment says the previews cannot connect, take payments, sync products or receive webhooks. - Jetpack Beta and Jurassic Ninja: both are served by the Jetpack Beta Builder, which only takes builds from plugins registered with it. This plugin is not registered yet, so those two options and the webhook call are left out until the SQUARE_LIVE_BRANCH_SECRET secret exists. Nothing else has to change once it does. Jurassic Ninja redirects its create URL to its homepage for visitors who are not logged in, so that option says to log in first. The work is split in two jobs. The first runs the pull request's build scripts and its dependencies' install scripts with a read-only token and no secrets. The second holds the secret and the token that can comment, and runs no code from the pull request. Playground's artifact proxy picks a build by branch name, forks included, so a link cannot promise whose code it runs. The Blueprints carry no secret and the comment tells visitors not to enter Square tokens in a preview. The preview artifact is named after the run ID, so a link always installs the build of the run that wrote it, and is kept for 14 days because the links download it on every click. Pull requests from forks get a read-only token and cannot be commented on from a pull_request workflow. Their build information goes to the summary of the workflow run instead. The workflow lives under .github, which is export-ignored, so nothing here ships in the release zip. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/pr-build-live-branch.yml | 316 +++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 .github/workflows/pr-build-live-branch.yml diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml new file mode 100644 index 000000000..e4bf51828 --- /dev/null +++ b/.github/workflows/pr-build-live-branch.yml @@ -0,0 +1,316 @@ +name: Build PR for testing + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +# Two jobs on purpose: the first one runs the pull request's own code (its build scripts and its +# dependencies' install scripts), so it gets a read-only token and no secrets. The second one holds +# the Jetpack Beta Builder secret and the token that can comment, and runs nothing from the pull request. +jobs: + build-zip-file: + name: "Build the zip file" + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + outputs: + dev-version: ${{ steps.get-dev-version.outputs.DEV_VERSION }} + steps: + - name: "Checkout repository" + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - name: "Cache node_modules" + id: cache-node-modules + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 + env: + cache-name: cache-node-modules + with: + path: node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + + - name: "Setup node version and npm cache" + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: "Install Node dependencies" + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci --no-optional + + # The build is labelled as a pre-release of the next patch version, so it sorts above the + # current release and below the next one, and names the pull request and commit it was built from. + - name: "Get dev version" + id: get-dev-version + env: + PR_NUMBER: ${{ github.event.number }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + VERSION=$( sed -n 's/^ \* Version: //p' woocommerce-square.php | head -n1 ) + IFS=. read -r MAJOR MINOR PATCH <<<"$VERSION" + PATCH="${PATCH%%[!0-9]*}" + if [[ ! "$MAJOR" =~ ^[0-9]+$ || ! "$MINOR" =~ ^[0-9]+$ || ! "$PATCH" =~ ^[0-9]+$ ]]; then + echo "::error::Could not read the plugin version from woocommerce-square.php (found '$VERSION')." + exit 1 + fi + DEV_VERSION="${MAJOR}.${MINOR}.$(( PATCH + 1 ))-dev_PR-${PR_NUMBER}_commit-${PR_HEAD_SHA:0:7}" + echo "Current version found: $VERSION" >> "$GITHUB_STEP_SUMMARY" + echo "Dev version: $DEV_VERSION" >> "$GITHUB_STEP_SUMMARY" + echo "DEV_VERSION=$DEV_VERSION" >> "$GITHUB_OUTPUT" + + - name: "Bump dev version" + env: + DEV_VERSION: ${{ steps.get-dev-version.outputs.DEV_VERSION }} + run: | + # 'Version' header and WC_SQUARE_PLUGIN_VERSION constant in the plugin entry file. + sed -i.bak \ + -e "s/^ \* Version: .*$/ * Version: ${DEV_VERSION}/" \ + -e "s/define( 'WC_SQUARE_PLUGIN_VERSION', '[^']*' )/define( 'WC_SQUARE_PLUGIN_VERSION', '${DEV_VERSION}' )/" \ + woocommerce-square.php + + # 'Stable tag' header in readme.txt; the Jetpack Beta Builder reads it. + sed -i.bak "s/^Stable tag: .*$/Stable tag: ${DEV_VERSION}/" readme.txt + + rm -f woocommerce-square.php.bak readme.txt.bak + + # Fail here rather than ship a build that still carries the release version. + grep -qF " * Version: ${DEV_VERSION}" woocommerce-square.php + grep -qF "define( 'WC_SQUARE_PLUGIN_VERSION', '${DEV_VERSION}' )" woocommerce-square.php + grep -qF "Stable tag: ${DEV_VERSION}" readme.txt + + - name: "Build the plugin" + run: npm run build + + # The Jetpack Beta Builder expects the folder and the zip to be named `-dev`, so the + # build installs next to the released plugin on a tester's site instead of replacing it. + - name: "Update the structure of artifacts for Jetpack Beta Builder" + run: | + mkdir release + unzip -q woocommerce-square.zip -d release + cd release + mv woocommerce-square woocommerce-square-dev + zip -q -r "woocommerce-square-dev.zip" "woocommerce-square-dev/" + rm -fR "woocommerce-square-dev" + + - name: "Add file size notice" + run: | + echo ":information_source: Ignore the artifact size mentioned since GitHub calculates the size of the source folder instead of the zip file created." >> "$GITHUB_STEP_SUMMARY" + + - name: "Upload the zip file as an artifact" + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 + with: + name: plugins # Hard-coded value for Jetpack Beta Builder. + path: release + if-no-files-found: error + overwrite: true + # Only need to retain for a day since the Jetpack Beta Builder slurps it up to distribute. + retention-days: 1 + + # The Playground links in the PR comment download their artifact on every click, so this one is kept + # for longer. The run ID in the name ties the links to the build of one run: a later run that fails + # or is cancelled part-way cannot change what an earlier comment's links install. + - name: "Upload the zip file as an artifact for the Playground preview" + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 + with: + name: plugins-${{ github.run_id }} + path: release + if-no-files-found: error + overwrite: true + retention-days: 14 + + inform-zip-file: + name: "Inform the zip file" + needs: build-zip-file + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + pull-requests: write + steps: + # Options 1 and 2 of the comment are served by the Jetpack Beta Builder, which only takes builds + # from repositories registered with it, identified by this secret. Without the secret (it is not + # set until the plugin is registered, and pull requests from forks never receive secrets) the + # Beta Builder is not informed and the comment leaves those two options out. + - name: "Check whether the Jetpack Beta Builder is set up" + id: beta-builder + env: + SECRET: ${{ secrets.SQUARE_LIVE_BRANCH_SECRET }} + run: | + if [ -n "$SECRET" ]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "enabled=false" >> "$GITHUB_OUTPUT" + echo ":information_source: No Jetpack Beta Builder secret is available to this run, so the build is not sent to the Jetpack Beta Builder." >> "$GITHUB_STEP_SUMMARY" + fi + + - name: "Get plugin data for Jetpack Beta Builder" + id: get-plugin-data + if: steps.beta-builder.outputs.enabled == 'true' + env: + DEV_VERSION: ${{ needs.build-zip-file.outputs.dev-version }} + run: | + # Plugin data is passed as a JSON object. + PLUGIN_DATA=$( jq -cn --arg slug "woocommerce-square" --arg ver "$DEV_VERSION" '{ ( $slug ): { version: $ver } }' ) + echo "plugin-data=$PLUGIN_DATA" >> "$GITHUB_OUTPUT" + + - name: "Inform Jetpack Beta Builder webhook" + if: steps.beta-builder.outputs.enabled == 'true' + env: + SECRET: ${{ secrets.SQUARE_LIVE_BRANCH_SECRET }} + PLUGIN_DATA: ${{ steps.get-plugin-data.outputs.plugin-data }} + PR: ${{ github.event.number }} + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + run: | + # On `pull_request` events GITHUB_REF is `refs/pull//merge`, so the PR's branch name is + # sent explicitly: it is what Jetpack Beta and Jurassic Ninja look the build up by. + curl --silent --show-error --fail -L \ + --url "https://betadownload.jetpack.me/gh-action.php?run_id=$GITHUB_RUN_ID&pr=$PR&commit=$GITHUB_SHA" \ + --form-string "repo=$GITHUB_REPOSITORY" \ + --form-string "branch=$PR_HEAD_REF" \ + --form-string "plugins=$PLUGIN_DATA" \ + --form-string "secret=$SECRET" + + # WordPress Playground runs in the visitor's browser and can only fetch public URLs. + # Its artifact proxy serves this workflow's artifacts for the PR, looked up by workflow + # name - hence GITHUB_WORKFLOW rather than a literal that a rename would silently break. + # The build artifact wraps the plugin zip, so the Blueprints unzip it before installing. + # + # The proxy resolves the PR to its branch name and serves the newest build with that branch + # name, pull requests from forks included, so a link cannot promise whose code it runs. + # Never add a Blueprint that carries a secret, or a link that asks for credentials or tokens. + # + # The links are for reviewers with no development environment, so the store is set up for them: + # nothing is left to click through before the Square screens. If a pull request puts its UI + # behind an option or a feature flag, turn it on in STORE_SETUP in that same pull request. + - name: "Build the WordPress Playground preview links" + id: playground + env: + PR_NUMBER: ${{ github.event.number }} + run: | + # `read` returns non-zero when it reaches the end of the here-document, hence `|| true`. + read -r -d '' STORE_SETUP <<'PHP' || true + true ) ); + update_option( 'woocommerce_coming_soon', 'no' ); + + // Store orders the way a new store does (HPOS). WooCommerce creates the tables. + update_option( 'woocommerce_custom_orders_table_enabled', 'yes' ); + + // Square sends a new merchant to its onboarding wizard on the first admin page load. + // Mark that as done, so each link opens the screen it names. + update_option( 'wc_square_show_wizard_on_activation', true ); + + $product = new WC_Product_Simple(); + $product->set_name( 'Sample product' ); + $product->set_sku( 'sample-product' ); + $product->set_regular_price( '10' ); + $product->set_status( 'publish' ); + $product->save(); + PHP + + ARTIFACT_URL=$( jq -rn \ + --arg org "$GITHUB_REPOSITORY_OWNER" \ + --arg repo "${GITHUB_REPOSITORY#*/}" \ + --arg workflow "$GITHUB_WORKFLOW" \ + --arg pr "$PR_NUMBER" \ + --arg artifact "plugins-$GITHUB_RUN_ID" \ + '"https://playground.wordpress.net/plugin-proxy.php?org=\($org|@uri)&repo=\($repo|@uri)&workflow=\($workflow|@uri)&pr=\($pr|@uri)&artifact=\($artifact|@uri)"' ) + + BLUEPRINTS=$( jq -cn --arg artifact_url "$ARTIFACT_URL" --arg store_setup "$STORE_SETUP" ' + { + "$schema": "https://playground.wordpress.net/blueprint-schema.json", + preferredVersions: { php: "8.3", wp: "latest" }, + features: { networking: true }, + steps: [ + { step: "login", username: "admin" }, + { step: "installPlugin", pluginData: { resource: "wordpress.org/plugins", slug: "woocommerce" }, options: { activate: true } }, + { step: "runPHP", code: $store_setup }, + { step: "unzip", zipFile: { resource: "url", url: $artifact_url, caption: "Downloading the Square build for this PR" }, extractToPath: "/tmp/pr" }, + { step: "installPlugin", pluginData: { resource: "vfs", path: "/tmp/pr/woocommerce-square-dev.zip" }, options: { activate: true } } + ] + } as $base + | { + settings: ( $base + { landingPage: "/wp-admin/admin.php?page=wc-settings&tab=square" } ), + onboarding: ( $base + { landingPage: "/wp-admin/admin.php?page=woocommerce-square-onboarding" } ) + }' ) + + { + echo "settings_url=https://playground.wordpress.net/#$( jq -rn --argjson blueprints "$BLUEPRINTS" '$blueprints.settings|tojson|@uri' )" + echo "onboarding_url=https://playground.wordpress.net/#$( jq -rn --argjson blueprints "$BLUEPRINTS" '$blueprints.onboarding|tojson|@uri' )" + } >> "$GITHUB_OUTPUT" + + - name: "Write the information for the PR" + env: + BETA_BUILDER_ENABLED: ${{ steps.beta-builder.outputs.enabled }} + PLAYGROUND_SETTINGS_URL: ${{ steps.playground.outputs.settings_url }} + PLAYGROUND_ONBOARDING_URL: ${{ steps.playground.outputs.onboarding_url }} + PR_NUMBER: ${{ github.event.number }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + COMMENT_FILE: ${{ runner.temp }}/test-the-build.md + run: | + echo "### Test the build" > "$COMMENT_FILE" + + # The Playground option is numbered after the options before it, so the comment has no gap + # when the Jetpack Beta Builder options are left out. + PLAYGROUND_OPTION=1 + + if [ "$BETA_BUILDER_ENABLED" = "true" ]; then + PLAYGROUND_OPTION=3 + JN_BRANCH=$( jq -rn --arg ref "$PR_HEAD_REF" '$ref|@uri' ) + + cat >> "$COMMENT_FILE" <> "$COMMENT_FILE" < Settings > Square. + - :sparkles: [Open the onboarding wizard](${PLAYGROUND_ONBOARDING_URL}): the same store, on the wizard a new merchant sees first. + + :information_source: Neither can connect to Square: signing in to Square has to send you back to the site, and a site that runs in your browser tab has no public address to come back to. Without a connection the store cannot take payments, sync products or receive webhooks, so the previews show what a merchant sees before connecting. Do not enter Square access tokens or other credentials in a preview. The links stop working 14 days after the last build. + + --- + + Build info: + + - Latest commit: ${PR_HEAD_SHA} + - Build time: $( date -u "+%Y-%m-%d %H:%M:%S UTC" ) + + _Note: the build is updated when a new commit is pushed to this PR._ + EOF + + cat "$COMMENT_FILE" >> "$GITHUB_STEP_SUMMARY" + + # Pull requests from forks get a read-only token, so they cannot be commented on from here. + # Their build information is in the summary of the workflow run instead. + - name: "Add/update the information as a comment in the PR" + if: github.event.pull_request.head.repo.full_name == github.repository + uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 + with: + header: test-the-build + path: ${{ runner.temp }}/test-the-build.md From 5faf7810f15827f765f02da5ea9fc0bbaa3a4f09 Mon Sep 17 00:00:00 2001 From: Rafael Meneses Date: Thu, 12 Nov 2026 09:43:58 -0300 Subject: [PATCH 2/4] ci: Put the Jurassic Ninja login warning before the link The "Test the build" comment said under the Jurassic Ninja link that the reader has to be logged in. Jurassic Ninja redirects its create URL to its homepage for anyone who is not, so a reader who clicks first and reads second lands on a page that launches nothing and has no hint why. Say it before the link, as a warning, in the words the same comment uses in the other Woo extensions. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/pr-build-live-branch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml index e4bf51828..f56fb6068 100644 --- a/.github/workflows/pr-build-live-branch.yml +++ b/.github/workflows/pr-build-live-branch.yml @@ -279,9 +279,9 @@ jobs: #### Option 2. Jurassic Ninja - available for logged-in A12s - :rocket: [Launch a JN site with this branch and sample products](https://jurassic.ninja/create/?jetpack-beta&nojetpack&woocommerce&woocommerce-import-sample-data&branches.woocommerce-square=${JN_BRANCH}) :rocket: + :warning: Log in at [jurassic.ninja](https://jurassic.ninja/) first. Without a login, the link below takes you to the Jurassic Ninja homepage and no site is created. - :information_source: Log in to [Jurassic Ninja](https://jurassic.ninja/) first. If you are not logged in, the link takes you to its homepage instead of launching a site. + :rocket: [Launch a JN site with this branch and sample products](https://jurassic.ninja/create/?jetpack-beta&nojetpack&woocommerce&woocommerce-import-sample-data&branches.woocommerce-square=${JN_BRANCH}) :rocket: EOF fi From 1940a156c7f2067b94ea78e7080b0055ecdf8598 Mon Sep 17 00:00:00 2001 From: Rafael Meneses Date: Thu, 12 Nov 2026 09:49:37 -0300 Subject: [PATCH 3/4] ci: Keep all three options in the "Test the build" comment The comment left Jetpack Beta and Jurassic Ninja out while the plugin is not registered with the Jetpack Beta Builder, and renumbered WordPress Playground as Option 1. A reader who knows the comment from another Woo extension could not tell whether those two options were missing by mistake, unsupported, or waiting on something. Always write the same three options in the same order. While the workflow has no SQUARE_LIVE_BRANCH_SECRET, Options 1 and 2 keep their heading and say that they are not available yet and what they need, with no link, since a link could not work. Each option that does work now also says what its limit is for this plugin: Jetpack Beta runs the build with the settings and the Square connection the site already has, so it belongs on a test site; a Jurassic Ninja site starts without a Square connection. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/pr-build-live-branch.yml | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml index f56fb6068..2e2d09e1b 100644 --- a/.github/workflows/pr-build-live-branch.yml +++ b/.github/workflows/pr-build-live-branch.yml @@ -137,7 +137,8 @@ jobs: # Options 1 and 2 of the comment are served by the Jetpack Beta Builder, which only takes builds # from repositories registered with it, identified by this secret. Without the secret (it is not # set until the plugin is registered, and pull requests from forks never receive secrets) the - # Beta Builder is not informed and the comment leaves those two options out. + # Beta Builder is not informed, and the comment says under those two options that they are + # not available yet and what they need, instead of showing links that cannot work. - name: "Check whether the Jetpack Beta Builder is set up" id: beta-builder env: @@ -262,12 +263,9 @@ jobs: run: | echo "### Test the build" > "$COMMENT_FILE" - # The Playground option is numbered after the options before it, so the comment has no gap - # when the Jetpack Beta Builder options are left out. - PLAYGROUND_OPTION=1 - + # The comment always has the same three options, in the same order. An option that cannot + # work for this build keeps its heading and says why, without a link. if [ "$BETA_BUILDER_ENABLED" = "true" ]; then - PLAYGROUND_OPTION=3 JN_BRANCH=$( jq -rn --arg ref "$PR_HEAD_REF" '$ref|@uri' ) cat >> "$COMMENT_FILE" <> "$COMMENT_FILE" <> "$COMMENT_FILE" < Settings > Square. - :sparkles: [Open the onboarding wizard](${PLAYGROUND_ONBOARDING_URL}): the same store, on the wizard a new merchant sees first. From 04fa8c0d2c9c234950b15cf93918887c87b3868c Mon Sep 17 00:00:00 2001 From: Rafael Meneses Date: Thu, 12 Nov 2026 13:43:26 -0300 Subject: [PATCH 4/4] ci: Remove the Jetpack Beta and Jurassic Ninja options from the "Test the build" comment The comment listed three options. Jetpack Beta and Jurassic Ninja were rendered as "Not available yet", because both install a pull request's build through the Jetpack Beta Builder and this plugin is not registered with it. The workflow also carried the steps for them: a webhook call behind a repository secret that does not exist, a second artifact named for the Beta Builder, and a `-dev` folder name and `Stable tag` bump that only the Beta Builder reads. A section that only says an option is unavailable gives a reviewer nothing to click, and steps wired to a missing secret are dead code. Show only what works today: the WordPress Playground previews, under a heading that names them instead of "Option 3". Drop the Beta Builder steps, the extra artifact and the secret reference. The remaining artifact now holds the zip exactly as `npm run build` produces it, so the Blueprints install `woocommerce-square.zip`. The two jobs stay separate: the first runs the pull request's code with a read-only token, the second holds the token that can comment. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/pr-build-live-branch.yml | 136 ++------------------- 1 file changed, 11 insertions(+), 125 deletions(-) diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml index 2e2d09e1b..639c7467c 100644 --- a/.github/workflows/pr-build-live-branch.yml +++ b/.github/workflows/pr-build-live-branch.yml @@ -10,8 +10,8 @@ concurrency: permissions: {} # Two jobs on purpose: the first one runs the pull request's own code (its build scripts and its -# dependencies' install scripts), so it gets a read-only token and no secrets. The second one holds -# the Jetpack Beta Builder secret and the token that can comment, and runs nothing from the pull request. +# dependencies' install scripts), so it gets a read-only token. The second one holds the token that +# can comment, and runs nothing from the pull request. jobs: build-zip-file: name: "Build the zip file" @@ -19,8 +19,6 @@ jobs: timeout-minutes: 15 permissions: contents: read - outputs: - dev-version: ${{ steps.get-dev-version.outputs.DEV_VERSION }} steps: - name: "Checkout repository" uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -76,52 +74,23 @@ jobs: -e "s/define( 'WC_SQUARE_PLUGIN_VERSION', '[^']*' )/define( 'WC_SQUARE_PLUGIN_VERSION', '${DEV_VERSION}' )/" \ woocommerce-square.php - # 'Stable tag' header in readme.txt; the Jetpack Beta Builder reads it. - sed -i.bak "s/^Stable tag: .*$/Stable tag: ${DEV_VERSION}/" readme.txt - - rm -f woocommerce-square.php.bak readme.txt.bak + rm -f woocommerce-square.php.bak # Fail here rather than ship a build that still carries the release version. grep -qF " * Version: ${DEV_VERSION}" woocommerce-square.php grep -qF "define( 'WC_SQUARE_PLUGIN_VERSION', '${DEV_VERSION}' )" woocommerce-square.php - grep -qF "Stable tag: ${DEV_VERSION}" readme.txt - name: "Build the plugin" run: npm run build - # The Jetpack Beta Builder expects the folder and the zip to be named `-dev`, so the - # build installs next to the released plugin on a tester's site instead of replacing it. - - name: "Update the structure of artifacts for Jetpack Beta Builder" - run: | - mkdir release - unzip -q woocommerce-square.zip -d release - cd release - mv woocommerce-square woocommerce-square-dev - zip -q -r "woocommerce-square-dev.zip" "woocommerce-square-dev/" - rm -fR "woocommerce-square-dev" - - - name: "Add file size notice" - run: | - echo ":information_source: Ignore the artifact size mentioned since GitHub calculates the size of the source folder instead of the zip file created." >> "$GITHUB_STEP_SUMMARY" - - - name: "Upload the zip file as an artifact" - uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 - with: - name: plugins # Hard-coded value for Jetpack Beta Builder. - path: release - if-no-files-found: error - overwrite: true - # Only need to retain for a day since the Jetpack Beta Builder slurps it up to distribute. - retention-days: 1 - - # The Playground links in the PR comment download their artifact on every click, so this one is kept - # for longer. The run ID in the name ties the links to the build of one run: a later run that fails - # or is cancelled part-way cannot change what an earlier comment's links install. + # The Playground links in the PR comment download this artifact on every click, so it is kept + # for 14 days. The run ID in the name ties the links to the build of one run: a later run that + # fails or is cancelled part-way cannot change what an earlier comment's links install. - name: "Upload the zip file as an artifact for the Playground preview" uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 with: name: plugins-${{ github.run_id }} - path: release + path: woocommerce-square.zip if-no-files-found: error overwrite: true retention-days: 14 @@ -134,50 +103,6 @@ jobs: permissions: pull-requests: write steps: - # Options 1 and 2 of the comment are served by the Jetpack Beta Builder, which only takes builds - # from repositories registered with it, identified by this secret. Without the secret (it is not - # set until the plugin is registered, and pull requests from forks never receive secrets) the - # Beta Builder is not informed, and the comment says under those two options that they are - # not available yet and what they need, instead of showing links that cannot work. - - name: "Check whether the Jetpack Beta Builder is set up" - id: beta-builder - env: - SECRET: ${{ secrets.SQUARE_LIVE_BRANCH_SECRET }} - run: | - if [ -n "$SECRET" ]; then - echo "enabled=true" >> "$GITHUB_OUTPUT" - else - echo "enabled=false" >> "$GITHUB_OUTPUT" - echo ":information_source: No Jetpack Beta Builder secret is available to this run, so the build is not sent to the Jetpack Beta Builder." >> "$GITHUB_STEP_SUMMARY" - fi - - - name: "Get plugin data for Jetpack Beta Builder" - id: get-plugin-data - if: steps.beta-builder.outputs.enabled == 'true' - env: - DEV_VERSION: ${{ needs.build-zip-file.outputs.dev-version }} - run: | - # Plugin data is passed as a JSON object. - PLUGIN_DATA=$( jq -cn --arg slug "woocommerce-square" --arg ver "$DEV_VERSION" '{ ( $slug ): { version: $ver } }' ) - echo "plugin-data=$PLUGIN_DATA" >> "$GITHUB_OUTPUT" - - - name: "Inform Jetpack Beta Builder webhook" - if: steps.beta-builder.outputs.enabled == 'true' - env: - SECRET: ${{ secrets.SQUARE_LIVE_BRANCH_SECRET }} - PLUGIN_DATA: ${{ steps.get-plugin-data.outputs.plugin-data }} - PR: ${{ github.event.number }} - PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} - run: | - # On `pull_request` events GITHUB_REF is `refs/pull//merge`, so the PR's branch name is - # sent explicitly: it is what Jetpack Beta and Jurassic Ninja look the build up by. - curl --silent --show-error --fail -L \ - --url "https://betadownload.jetpack.me/gh-action.php?run_id=$GITHUB_RUN_ID&pr=$PR&commit=$GITHUB_SHA" \ - --form-string "repo=$GITHUB_REPOSITORY" \ - --form-string "branch=$PR_HEAD_REF" \ - --form-string "plugins=$PLUGIN_DATA" \ - --form-string "secret=$SECRET" - # WordPress Playground runs in the visitor's browser and can only fetch public URLs. # Its artifact proxy serves this workflow's artifacts for the PR, looked up by workflow # name - hence GITHUB_WORKFLOW rather than a literal that a rename would silently break. @@ -238,7 +163,7 @@ jobs: { step: "installPlugin", pluginData: { resource: "wordpress.org/plugins", slug: "woocommerce" }, options: { activate: true } }, { step: "runPHP", code: $store_setup }, { step: "unzip", zipFile: { resource: "url", url: $artifact_url, caption: "Downloading the Square build for this PR" }, extractToPath: "/tmp/pr" }, - { step: "installPlugin", pluginData: { resource: "vfs", path: "/tmp/pr/woocommerce-square-dev.zip" }, options: { activate: true } } + { step: "installPlugin", pluginData: { resource: "vfs", path: "/tmp/pr/woocommerce-square.zip" }, options: { activate: true } } ] } as $base | { @@ -253,54 +178,15 @@ jobs: - name: "Write the information for the PR" env: - BETA_BUILDER_ENABLED: ${{ steps.beta-builder.outputs.enabled }} PLAYGROUND_SETTINGS_URL: ${{ steps.playground.outputs.settings_url }} PLAYGROUND_ONBOARDING_URL: ${{ steps.playground.outputs.onboarding_url }} - PR_NUMBER: ${{ github.event.number }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} COMMENT_FILE: ${{ runner.temp }}/test-the-build.md run: | - echo "### Test the build" > "$COMMENT_FILE" - - # The comment always has the same three options, in the same order. An option that cannot - # work for this build keeps its heading and says why, without a link. - if [ "$BETA_BUILDER_ENABLED" = "true" ]; then - JN_BRANCH=$( jq -rn --arg ref "$PR_HEAD_REF" '$ref|@uri' ) - - cat >> "$COMMENT_FILE" <> "$COMMENT_FILE" <> "$COMMENT_FILE" < "$COMMENT_FILE" < Settings > Square. - :sparkles: [Open the onboarding wizard](${PLAYGROUND_ONBOARDING_URL}): the same store, on the wizard a new merchant sees first.