From 052c393f162456aaa9e44f5ccf2aaf76e36f8e4e Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 00:35:52 +0100 Subject: [PATCH 1/8] ci: a preview theme for each pull request of a Shopify theme, which Fulldev Sites shows Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 109 ++++++++++++++++++++++++++++ README.md | 2 + 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/theme-preview.yml diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml new file mode 100644 index 0000000..d6799c3 --- /dev/null +++ b/.github/workflows/theme-preview.yml @@ -0,0 +1,109 @@ +# A preview theme for each pull request of a Shopify theme, which Fulldev +# Sites shows as that version's preview and where its bar edits the branch. +# Each push to an open pull request from the same repository mirrors the +# branch to an unpublished theme named after it (Sites's branches are +# cms/, which the bar reads from the theme's name) and reports the +# theme's preview link as the commit status fulldev/theme-preview/. +# Closing the pull request deletes the theme. A store holds at most 20 +# themes; a push past that fails and reports so. +# +# The caller runs on pull_request (opened, synchronize, reopened, closed), +# grants `contents: read` and `statuses: write`, and passes the store and +# the repository secret SHOPIFY_CLI_THEME_TOKEN: a Theme Access password +# of that store. +name: Theme preview + +on: + workflow_call: + inputs: + store: + description: The store's myshopify.com address. + required: true + type: string + path: + description: The theme's folder in the repository. + type: string + default: . + runner: + type: string + default: blacksmith-2vcpu-ubuntu-2404 + secrets: + SHOPIFY_CLI_THEME_TOKEN: + required: true + +permissions: + contents: read + statuses: write + +jobs: + preview: + name: Theme preview + # A fork's pull request gets no secrets, and its branch is not Sites's. + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ${{ vars.CI_RUNNER || (github.event.repository.private == false && 'ubuntu-24.04') || inputs.runner }} + timeout-minutes: 15 + concurrency: + group: theme-preview-${{ github.repository }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + env: + SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }} + SHOPIFY_FLAG_STORE: ${{ inputs.store }} + BRANCH: ${{ github.head_ref }} + SHA: ${{ github.event.pull_request.head.sha }} + NUMBER: ${{ github.event.pull_request.number }} + GH_TOKEN: ${{ github.token }} + steps: + - name: Checkout the pull request's head + if: ${{ github.event.action != 'closed' }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + - name: Install Shopify CLI + run: npm install --global --no-audit --no-fund @shopify/cli@3 + - name: Find the branch's preview theme + id: theme + run: | + # Shopify takes a theme name of at most 50 characters. + name="${BRANCH:0:50}" + echo "name=$name" >> "$GITHUB_OUTPUT" + id=$(shopify theme list --json | jq -r --arg name "$name" \ + '[.[] | select(.name == $name and .role == "unpublished")][0].id // empty') + echo "id=$id" >> "$GITHUB_OUTPUT" + - name: Report building + if: ${{ github.event.action != 'closed' }} + run: | + gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ + -f state=pending -f context="fulldev/theme-preview/$NUMBER" \ + -f description="Building the preview theme" > /dev/null + - name: Push the branch to its preview theme + if: ${{ github.event.action != 'closed' }} + working-directory: ${{ inputs.path }} + env: + NAME: ${{ steps.theme.outputs.name }} + ID: ${{ steps.theme.outputs.id }} + run: | + if [ -n "$ID" ]; then + shopify theme push --theme "$ID" --json > "$RUNNER_TEMP/push.json" + else + shopify theme push --unpublished --theme "$NAME" --json > "$RUNNER_TEMP/push.json" + fi + url=$(jq -r '.theme.preview_url // empty' "$RUNNER_TEMP/push.json") + if [ -z "$url" ]; then + echo "Shopify CLI answered no preview link." >&2 + exit 1 + fi + gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ + -f state=success -f context="fulldev/theme-preview/$NUMBER" \ + -f target_url="$url" -f description="Preview theme ready" > /dev/null + - name: Report a failed push + if: ${{ failure() && github.event.action != 'closed' }} + run: | + gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ + -f state=failure -f context="fulldev/theme-preview/$NUMBER" \ + -f description="The preview theme did not update" > /dev/null + - name: Delete the preview theme + if: ${{ github.event.action == 'closed' && steps.theme.outputs.id != '' }} + env: + ID: ${{ steps.theme.outputs.id }} + run: shopify theme delete --theme "$ID" --force diff --git a/README.md b/README.md index a4be5b0..6f811bb 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push mirrors the branch to an unpublished theme named after it, reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request deletes the theme. The caller runs on `pull_request` (opened, synchronize, reopened, closed) with `contents: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. + Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. ```yaml From e926065d0f7cb2ce2f19d7bbc28b941884ad533b Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 00:57:15 +0100 Subject: [PATCH 2/8] ci: preview themes are named after their pull request, follow a retarget, and pin Shopify CLI 5.0.0 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 54 ++++++++++++++++++----------- README.md | 2 +- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index d6799c3..217a899 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -1,16 +1,19 @@ # A preview theme for each pull request of a Shopify theme, which Fulldev # Sites shows as that version's preview and where its bar edits the branch. -# Each push to an open pull request from the same repository mirrors the -# branch to an unpublished theme named after it (Sites's branches are -# cms/, which the bar reads from the theme's name) and reports the -# theme's preview link as the commit status fulldev/theme-preview/. -# Closing the pull request deletes the theme. A store holds at most 20 +# Each push to an open pull request into the default branch, from the same +# repository, mirrors the branch to an unpublished theme named after the +# pull request, "# " (Sites's branches are cms/, which +# the bar reads from the end of the name), and reports the theme's preview +# link as the commit status fulldev/theme-preview/. Only a theme of +# that exact name is updated or deleted, so a merchant's own themes and +# other pull requests' previews stay. Closing the pull request, or moving +# it to another base branch, deletes the theme. A store holds at most 20 # themes; a push past that fails and reports so. # -# The caller runs on pull_request (opened, synchronize, reopened, closed), -# grants `contents: read` and `statuses: write`, and passes the store and -# the repository secret SHOPIFY_CLI_THEME_TOKEN: a Theme Access password -# of that store. +# The caller runs on pull_request (opened, synchronize, reopened, edited, +# closed) without a branch filter, grants `contents: read` and +# `statuses: write`, and passes the store and the repository secret +# SHOPIFY_CLI_THEME_TOKEN: a Theme Access password of that store. name: Theme preview on: @@ -38,8 +41,11 @@ permissions: jobs: preview: name: Theme preview - # A fork's pull request gets no secrets, and its branch is not Sites's. - if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + # A fork's pull request gets no secrets, and its branch is not Sites's; + # an edit counts only where it moved the pull request to another base. + if: >- + ${{ github.event.pull_request.head.repo.full_name == github.repository && + (github.event.action != 'edited' || github.event.changes.base) }} runs-on: ${{ vars.CI_RUNNER || (github.event.repository.private == false && 'ubuntu-24.04') || inputs.runner }} timeout-minutes: 15 concurrency: @@ -51,33 +57,39 @@ jobs: BRANCH: ${{ github.head_ref }} SHA: ${{ github.event.pull_request.head.sha }} NUMBER: ${{ github.event.pull_request.number }} + # A preview while open and into the default branch; else none. + WANTED: ${{ github.event.action != 'closed' && github.event.pull_request.base.ref == github.event.repository.default_branch }} GH_TOKEN: ${{ github.token }} steps: - name: Checkout the pull request's head - if: ${{ github.event.action != 'closed' }} + if: ${{ env.WANTED == 'true' }} uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 22 - name: Install Shopify CLI - run: npm install --global --no-audit --no-fund @shopify/cli@3 - - name: Find the branch's preview theme + run: npm install --global --no-audit --no-fund @shopify/cli@5.0.0 + - name: Find the pull request's preview theme id: theme run: | # Shopify takes a theme name of at most 50 characters. - name="${BRANCH:0:50}" + name="#$NUMBER $BRANCH" + name="${name:0:50}" echo "name=$name" >> "$GITHUB_OUTPUT" id=$(shopify theme list --json | jq -r --arg name "$name" \ - '[.[] | select(.name == $name and .role == "unpublished")][0].id // empty') + '[.themes[] | select(.name == $name and .role == "unpublished")][0].id // empty') echo "id=$id" >> "$GITHUB_OUTPUT" - name: Report building - if: ${{ github.event.action != 'closed' }} + if: ${{ env.WANTED == 'true' }} run: | gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=pending -f context="fulldev/theme-preview/$NUMBER" \ -f description="Building the preview theme" > /dev/null - name: Push the branch to its preview theme - if: ${{ github.event.action != 'closed' }} + if: ${{ env.WANTED == 'true' }} working-directory: ${{ inputs.path }} env: NAME: ${{ steps.theme.outputs.name }} @@ -88,7 +100,7 @@ jobs: else shopify theme push --unpublished --theme "$NAME" --json > "$RUNNER_TEMP/push.json" fi - url=$(jq -r '.theme.preview_url // empty' "$RUNNER_TEMP/push.json") + url=$(jq -r '.theme.previewUrl // empty' "$RUNNER_TEMP/push.json") if [ -z "$url" ]; then echo "Shopify CLI answered no preview link." >&2 exit 1 @@ -97,13 +109,13 @@ jobs: -f state=success -f context="fulldev/theme-preview/$NUMBER" \ -f target_url="$url" -f description="Preview theme ready" > /dev/null - name: Report a failed push - if: ${{ failure() && github.event.action != 'closed' }} + if: ${{ failure() && env.WANTED == 'true' }} run: | gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=failure -f context="fulldev/theme-preview/$NUMBER" \ -f description="The preview theme did not update" > /dev/null - name: Delete the preview theme - if: ${{ github.event.action == 'closed' && steps.theme.outputs.id != '' }} + if: ${{ env.WANTED != 'true' && steps.theme.outputs.id != '' }} env: ID: ${{ steps.theme.outputs.id }} run: shopify theme delete --theme "$ID" --force diff --git a/README.md b/README.md index 6f811bb..3578ade 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push mirrors the branch to an unpublished theme named after it, reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request deletes the theme. The caller runs on `pull_request` (opened, synchronize, reopened, closed) with `contents: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only a theme of that exact name is ever changed. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From 257ff073dd8fb54d3bae5e79cde095223fc094c0 Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 01:08:55 +0100 Subject: [PATCH 3/8] ci: a preview job reads its pull request as it is now, so a rerun of an older one changes nothing Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 40 ++++++++++++++++++++++------- README.md | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index 217a899..37d4973 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -11,8 +11,8 @@ # themes; a push past that fails and reports so. # # The caller runs on pull_request (opened, synchronize, reopened, edited, -# closed) without a branch filter, grants `contents: read` and -# `statuses: write`, and passes the store and the repository secret +# closed) without a branch filter, grants `contents: read`, +# `pull-requests: read` and `statuses: write`, and passes the store and the repository secret # SHOPIFY_CLI_THEME_TOKEN: a Theme Access password of that store. name: Theme preview @@ -36,6 +36,7 @@ on: permissions: contents: read + pull-requests: read statuses: write jobs: @@ -57,22 +58,43 @@ jobs: BRANCH: ${{ github.head_ref }} SHA: ${{ github.event.pull_request.head.sha }} NUMBER: ${{ github.event.pull_request.number }} - # A preview while open and into the default branch; else none. - WANTED: ${{ github.event.action != 'closed' && github.event.pull_request.base.ref == github.event.repository.default_branch }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} GH_TOKEN: ${{ github.token }} steps: + # The pull request as it is now, not as the event left it, as a rerun + # of an older job would: a preview while it is open into the default + # branch at this head, none once closed or moved, and nothing where a + # newer push runs its own job. + - name: Read the pull request + id: now + run: | + pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER") + state=$(jq -r .state <<< "$pr") + base=$(jq -r .base.ref <<< "$pr") + head=$(jq -r .head.sha <<< "$pr") + if [ "$state" != open ] || [ "$base" != "$DEFAULT_BRANCH" ]; then + act=delete + elif [ "$head" = "$SHA" ]; then + act=push + else + act=none + fi + echo "act=$act" >> "$GITHUB_OUTPUT" - name: Checkout the pull request's head - if: ${{ env.WANTED == 'true' }} + if: ${{ steps.now.outputs.act == 'push' }} uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + if: ${{ steps.now.outputs.act != 'none' }} with: node-version: 22 - name: Install Shopify CLI + if: ${{ steps.now.outputs.act != 'none' }} run: npm install --global --no-audit --no-fund @shopify/cli@5.0.0 - name: Find the pull request's preview theme + if: ${{ steps.now.outputs.act != 'none' }} id: theme run: | # Shopify takes a theme name of at most 50 characters. @@ -83,13 +105,13 @@ jobs: '[.themes[] | select(.name == $name and .role == "unpublished")][0].id // empty') echo "id=$id" >> "$GITHUB_OUTPUT" - name: Report building - if: ${{ env.WANTED == 'true' }} + if: ${{ steps.now.outputs.act == 'push' }} run: | gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=pending -f context="fulldev/theme-preview/$NUMBER" \ -f description="Building the preview theme" > /dev/null - name: Push the branch to its preview theme - if: ${{ env.WANTED == 'true' }} + if: ${{ steps.now.outputs.act == 'push' }} working-directory: ${{ inputs.path }} env: NAME: ${{ steps.theme.outputs.name }} @@ -109,13 +131,13 @@ jobs: -f state=success -f context="fulldev/theme-preview/$NUMBER" \ -f target_url="$url" -f description="Preview theme ready" > /dev/null - name: Report a failed push - if: ${{ failure() && env.WANTED == 'true' }} + if: ${{ failure() && steps.now.outputs.act == 'push' }} run: | gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=failure -f context="fulldev/theme-preview/$NUMBER" \ -f description="The preview theme did not update" > /dev/null - name: Delete the preview theme - if: ${{ env.WANTED != 'true' && steps.theme.outputs.id != '' }} + if: ${{ steps.now.outputs.act == 'delete' && steps.theme.outputs.id != '' }} env: ID: ${{ steps.theme.outputs.id }} run: shopify theme delete --theme "$ID" --force diff --git a/README.md b/README.md index 3578ade..8068583 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only a theme of that exact name is ever changed. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only a theme of that exact name is ever changed. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From 576ceb543bad1b0a713b220bc6ed632de3f9baad Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 01:28:29 +0100 Subject: [PATCH 4/8] ci: a preview theme is the one its pull request's own status names, and jobs queue Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 32 +++++++++++++++++++++-------- README.md | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index 37d4973..8a0d117 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -4,9 +4,9 @@ # repository, mirrors the branch to an unpublished theme named after the # pull request, "# " (Sites's branches are cms/, which # the bar reads from the end of the name), and reports the theme's preview -# link as the commit status fulldev/theme-preview/. Only a theme of -# that exact name is updated or deleted, so a merchant's own themes and -# other pull requests' previews stay. Closing the pull request, or moving +# link as the commit status fulldev/theme-preview/. Only the theme +# that status names is updated or deleted, so a merchant's own themes and +# other pull requests' previews, also another repository's, stay. Closing the pull request, or moving # it to another base branch, deletes the theme. A store holds at most 20 # themes; a push past that fails and reports so. # @@ -49,9 +49,11 @@ jobs: (github.event.action != 'edited' || github.event.changes.base) }} runs-on: ${{ vars.CI_RUNNER || (github.event.repository.private == false && 'ubuntu-24.04') || inputs.runner }} timeout-minutes: 15 + # Each job waits its turn, none cancelled, and reads the pull request + # once it runs, so an older one never stops the newest. concurrency: group: theme-preview-${{ github.repository }}-${{ github.event.pull_request.number }} - cancel-in-progress: true + queue: max env: SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }} SHOPIFY_FLAG_STORE: ${{ inputs.store }} @@ -99,10 +101,24 @@ jobs: run: | # Shopify takes a theme name of at most 50 characters. name="#$NUMBER $BRANCH" - name="${name:0:50}" - echo "name=$name" >> "$GITHUB_OUTPUT" - id=$(shopify theme list --json | jq -r --arg name "$name" \ - '[.themes[] | select(.name == $name and .role == "unpublished")][0].id // empty') + echo "name=${name:0:50}" >> "$GITHUB_OUTPUT" + # The theme this pull request's own last preview status named, so + # a merchant's theme, or another repository's preview on the same + # store, is never taken; none once the store no longer has it. + id="" + for sha in $(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/commits?per_page=100" --jq 'reverse | .[].sha'); do + url=$(gh api "repos/$GITHUB_REPOSITORY/commits/$sha/statuses?per_page=100" | + jq -r --arg context "fulldev/theme-preview/$NUMBER" \ + '[.[] | select(.context == $context and .state == "success")][0].target_url // empty') + if [ -n "$url" ]; then + id=$(sed -n 's/.*preview_theme_id=\([0-9]*\).*/\1/p' <<< "$url") + break + fi + done + if [ -n "$id" ] && ! shopify theme list --json | jq -e --arg id "$id" \ + '.themes[] | select((.id | tostring) == $id and .role == "unpublished")' > /dev/null; then + id="" + fi echo "id=$id" >> "$GITHUB_OUTPUT" - name: Report building if: ${{ steps.now.outputs.act == 'push' }} diff --git a/README.md b/README.md index 8068583..5ad5376 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only a theme of that exact name is ever changed. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only the theme its own last status names is ever changed, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From 00eaa35e44643e7855bd25388447337c5e51561d Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 01:39:00 +0100 Subject: [PATCH 5/8] ci: a preview theme is known by its pull request's and repository's name, also after a rebase Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 41 +++++++++++++---------------- README.md | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index 8a0d117..d1d9581 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -2,11 +2,12 @@ # Sites shows as that version's preview and where its bar edits the branch. # Each push to an open pull request into the default branch, from the same # repository, mirrors the branch to an unpublished theme named after the -# pull request, "# " (Sites's branches are cms/, which -# the bar reads from the end of the name), and reports the theme's preview -# link as the commit status fulldev/theme-preview/. Only the theme -# that status names is updated or deleted, so a merchant's own themes and -# other pull requests' previews, also another repository's, stay. Closing the pull request, or moving +# pull request and the repository, "# " (Sites's +# branches are cms/, which the bar reads from the end of the name), and +# reports the theme's preview link as the commit status +# fulldev/theme-preview/. Only that pull request's theme is updated +# or deleted, so a merchant's own themes and other pull requests' previews, +# also another repository's on the same store, stay. Closing the pull request, or moving # it to another base branch, deletes the theme. A store holds at most 20 # themes; a push past that fails and reports so. # @@ -99,26 +100,20 @@ jobs: if: ${{ steps.now.outputs.act != 'none' }} id: theme run: | + # The pull request's preview is the unpublished theme whose name + # starts with "# ", this repository's, so a + # rebase, a renamed branch or another repository's preview on the + # same store never changes which one it is. A failed list fails + # the job rather than make a second theme. + tag=$(printf '%s' "$GITHUB_REPOSITORY_ID" | sha1sum | cut -c1-3) + prefix="#$NUMBER $tag " + name="$prefix$BRANCH" # Shopify takes a theme name of at most 50 characters. - name="#$NUMBER $BRANCH" echo "name=${name:0:50}" >> "$GITHUB_OUTPUT" - # The theme this pull request's own last preview status named, so - # a merchant's theme, or another repository's preview on the same - # store, is never taken; none once the store no longer has it. - id="" - for sha in $(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/commits?per_page=100" --jq 'reverse | .[].sha'); do - url=$(gh api "repos/$GITHUB_REPOSITORY/commits/$sha/statuses?per_page=100" | - jq -r --arg context "fulldev/theme-preview/$NUMBER" \ - '[.[] | select(.context == $context and .state == "success")][0].target_url // empty') - if [ -n "$url" ]; then - id=$(sed -n 's/.*preview_theme_id=\([0-9]*\).*/\1/p' <<< "$url") - break - fi - done - if [ -n "$id" ] && ! shopify theme list --json | jq -e --arg id "$id" \ - '.themes[] | select((.id | tostring) == $id and .role == "unpublished")' > /dev/null; then - id="" - fi + shopify theme list --json > "$RUNNER_TEMP/themes.json" + id=$(jq -r --arg prefix "$prefix" \ + '[.themes[] | select(.role == "unpublished" and (.name | startswith($prefix)))][0].id // empty' \ + "$RUNNER_TEMP/themes.json") echo "id=$id" >> "$GITHUB_OUTPUT" - name: Report building if: ${{ steps.now.outputs.act == 'push' }} diff --git a/README.md b/README.md index 5ad5376..b69bb30 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only the theme its own last status names is ever changed, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request and the repository (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only that pull request's theme is ever changed, also after a rebase, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From c92bd8f3029bf95c1112f78cdc5c62116541a2cc Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 02:16:44 +0100 Subject: [PATCH 6/8] ci: a removed preview takes its link with it, two matching themes fail the job, and no token skips Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 28 ++++++++++++++++++++++------ README.md | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index d1d9581..f81647d 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -71,6 +71,11 @@ jobs: - name: Read the pull request id: now run: | + if [ -z "$SHOPIFY_CLI_THEME_TOKEN" ]; then + echo "::notice::No secret SHOPIFY_CLI_THEME_TOKEN, so no preview theme." + echo "act=none" >> "$GITHUB_OUTPUT" + exit 0 + fi pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER") state=$(jq -r .state <<< "$pr") base=$(jq -r .base.ref <<< "$pr") @@ -103,18 +108,23 @@ jobs: # The pull request's preview is the unpublished theme whose name # starts with "# ", this repository's, so a # rebase, a renamed branch or another repository's preview on the - # same store never changes which one it is. A failed list fails - # the job rather than make a second theme. + # same store never changes which one it is. A failed list, or two + # themes with the prefix, fail the job rather than guess. The name + # keeps a Sites branch's cms/ whole up to pull request #9999. tag=$(printf '%s' "$GITHUB_REPOSITORY_ID" | sha1sum | cut -c1-3) prefix="#$NUMBER $tag " name="$prefix$BRANCH" # Shopify takes a theme name of at most 50 characters. echo "name=${name:0:50}" >> "$GITHUB_OUTPUT" shopify theme list --json > "$RUNNER_TEMP/themes.json" - id=$(jq -r --arg prefix "$prefix" \ - '[.themes[] | select(.role == "unpublished" and (.name | startswith($prefix)))][0].id // empty' \ + ids=$(jq -r --arg prefix "$prefix" \ + '.themes[] | select(.role == "unpublished" and (.name | startswith($prefix))) | .id' \ "$RUNNER_TEMP/themes.json") - echo "id=$id" >> "$GITHUB_OUTPUT" + if [ "$(grep -c . <<< "$ids")" -gt 1 ]; then + echo "More than one theme starts with \"$prefix\"." >&2 + exit 1 + fi + echo "id=$ids" >> "$GITHUB_OUTPUT" - name: Report building if: ${{ steps.now.outputs.act == 'push' }} run: | @@ -147,8 +157,14 @@ jobs: gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=failure -f context="fulldev/theme-preview/$NUMBER" \ -f description="The preview theme did not update" > /dev/null + # Its link goes with it, so a pull request reopened at this commit + # shows no dead preview before its new one. - name: Delete the preview theme if: ${{ steps.now.outputs.act == 'delete' && steps.theme.outputs.id != '' }} env: ID: ${{ steps.theme.outputs.id }} - run: shopify theme delete --theme "$ID" --force + run: | + shopify theme delete --theme "$ID" --force + gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ + -f state=error -f context="fulldev/theme-preview/$NUMBER" \ + -f description="Preview theme removed" > /dev/null diff --git a/README.md b/README.md index b69bb30..9e97d55 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request and the repository (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only that pull request's theme is ever changed, also after a rebase, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without them it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request and the repository (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only that pull request's theme is ever changed, also after a rebase, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without either it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From 8ecbb2e1b2fa4170876319d58db51a1b27aa8d8e Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 02:20:52 +0100 Subject: [PATCH 7/8] ci: previews run on pull_request_target, so a conflicted pull request keeps its preview and loses it on close; the token is optional; a rerun takes a dead link away Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 29 ++++++++++++++++++++--------- README.md | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index f81647d..e0ee6f9 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -11,8 +11,11 @@ # it to another base branch, deletes the theme. A store holds at most 20 # themes; a push past that fails and reports so. # -# The caller runs on pull_request (opened, synchronize, reopened, edited, -# closed) without a branch filter, grants `contents: read`, +# The caller runs on pull_request_target (opened, synchronize, reopened, +# edited, closed) without a branch filter, since GitHub skips pull_request +# workflows while a pull request has a merge conflict; the job only uploads +# the branch's files to Shopify, never runs them, and only for a branch of +# the same repository, grants `contents: read`, # `pull-requests: read` and `statuses: write`, and passes the store and the repository secret # SHOPIFY_CLI_THEME_TOKEN: a Theme Access password of that store. name: Theme preview @@ -32,8 +35,9 @@ on: type: string default: blacksmith-2vcpu-ubuntu-2404 secrets: + # Without it the job skips, saying so. SHOPIFY_CLI_THEME_TOKEN: - required: true + required: false permissions: contents: read @@ -157,14 +161,21 @@ jobs: gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=failure -f context="fulldev/theme-preview/$NUMBER" \ -f description="The preview theme did not update" > /dev/null - # Its link goes with it, so a pull request reopened at this commit - # shows no dead preview before its new one. - name: Delete the preview theme if: ${{ steps.now.outputs.act == 'delete' && steps.theme.outputs.id != '' }} env: ID: ${{ steps.theme.outputs.id }} + run: shopify theme delete --theme "$ID" --force + # Its link goes with it, also on a rerun after the theme went, so a + # pull request reopened at this commit shows no dead preview. + - name: Take the preview's link away + if: ${{ steps.now.outputs.act == 'delete' }} run: | - shopify theme delete --theme "$ID" --force - gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ - -f state=error -f context="fulldev/theme-preview/$NUMBER" \ - -f description="Preview theme removed" > /dev/null + state=$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/statuses" | + jq -r --arg context "fulldev/theme-preview/$NUMBER" \ + '[.[] | select(.context == $context)][0].state // empty') + if [ "$state" = success ]; then + gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ + -f state=error -f context="fulldev/theme-preview/$NUMBER" \ + -f description="Preview theme removed" > /dev/null + fi diff --git a/README.md b/README.md index 9e97d55..f6c32a6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Live URL tests run after deployment, outside the build command. Product scenario Keep repository auto-merge disabled except for content publishers and Dependabot. For CloudCannon's Publish button, a same-repository `preview` PR from `cloudcannon[bot]`, Review turns on GitHub's auto-merge with a merge commit once its checks and previews pass, and fails when GitHub refuses it; its job needs `contents: write` and `pull-requests: write`, and the repository both settings. Fulldev Sites publishes a content PR by asking GitHub to merge it once its required checks pass. Code PRs are merged by their agent. -A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request and the repository (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only that pull request's theme is ever changed, also after a rebase, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request` (opened, synchronize, reopened, edited, closed) without a branch filter, with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without either it skips. +A Shopify theme repository gets a preview theme per pull request from [the Theme preview workflow](.github/workflows/theme-preview.yml): each push to a pull request into the default branch mirrors the branch to an unpublished theme named after the pull request and the repository (`# `), reports its preview link as the commit status `fulldev/theme-preview/`, which Fulldev Sites shows as that version's preview, and closing the pull request or moving it to another base deletes the theme; only that pull request's theme is ever changed, also after a rebase, never a merchant's theme or another repository's preview on the same store; jobs of one pull request queue and each reads the pull request as it is when it runs. The caller runs on `pull_request_target` (opened, synchronize, reopened, edited, closed) without a branch filter, as GitHub skips `pull_request` workflows while a pull request has a merge conflict (the job only uploads a same-repository branch's files, never runs them), with `contents: read`, `pull-requests: read` and `statuses: write`, and needs the repository variable `SHOPIFY_STORE` (the store's myshopify.com address) and the secret `SHOPIFY_CLI_THEME_TOKEN`, a Theme Access password of that store. Without either it skips. Dependabot's routine npm updates merge by themselves through [the Dependabot action](.github/actions/dependabot): websites and the Astro and Vite templates call it from a `Dependabot` workflow on `pull_request_target`, which runs the default branch's file and never checks out the PR. Each run first turns off auto-merge from an earlier run, then turns on GitHub's squash auto-merge again only when the default branch requires `Check / Check` and `Review` (without them auto-merge would merge at once, even when red), every update is a patch step or a minor step from 1.0 up, every commit is Dependabot's and signed by GitHub, and nothing under `.github/` changes. GitHub then merges once the required checks pass. Majors, minors below 1.0, pre-releases, other ecosystems and anything else stay for a person, because checks do not catch visual changes. The organization's GitHub App token (`RELEASE_APP_CLIENT_ID`, `RELEASE_APP_PRIVATE_KEY`) turns it on, so the merge starts the workflows on main; without both in the repository, or without the app installed there, the job fails and nothing merges. The repository needs Allow auto-merge. Any workflow in a repository that gets the key can mint the app's tokens, so share it only with these repositories, or keep it in an environment that only `main` may use, which `pull_request_target` runs count as. From 600df50d87f3299149c3e323a16750ebb4c0dfaf Mon Sep 17 00:00:00 2001 From: Sil Veltman Date: Thu, 26 Nov 2026 02:26:09 +0100 Subject: [PATCH 8/8] ci: the link is read on every page of statuses, as Sites reads it; the header reads plainly Co-Authored-By: Claude Opus 5.5 --- .github/workflows/theme-preview.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/theme-preview.yml b/.github/workflows/theme-preview.yml index e0ee6f9..5c8a20b 100644 --- a/.github/workflows/theme-preview.yml +++ b/.github/workflows/theme-preview.yml @@ -15,9 +15,10 @@ # edited, closed) without a branch filter, since GitHub skips pull_request # workflows while a pull request has a merge conflict; the job only uploads # the branch's files to Shopify, never runs them, and only for a branch of -# the same repository, grants `contents: read`, -# `pull-requests: read` and `statuses: write`, and passes the store and the repository secret -# SHOPIFY_CLI_THEME_TOKEN: a Theme Access password of that store. +# the same repository. The caller grants `contents: read`, +# `pull-requests: read` and `statuses: write`, and passes the store and the +# repository secret SHOPIFY_CLI_THEME_TOKEN: a Theme Access password of that +# store. name: Theme preview on: @@ -171,9 +172,11 @@ jobs: - name: Take the preview's link away if: ${{ steps.now.outputs.act == 'delete' }} run: | - state=$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/statuses" | - jq -r --arg context "fulldev/theme-preview/$NUMBER" \ - '[.[] | select(.context == $context)][0].state // empty') + # This workflow's newest status of the context, on every page, as + # Sites reads it. + state=$(gh api --paginate "repos/$GITHUB_REPOSITORY/commits/$SHA/statuses?per_page=100" | + jq -s -r --arg context "fulldev/theme-preview/$NUMBER" \ + '[add[] | select(.context == $context and .creator.login == "github-actions[bot]")][0].state // empty') if [ "$state" = success ]; then gh api "repos/$GITHUB_REPOSITORY/statuses/$SHA" \ -f state=error -f context="fulldev/theme-preview/$NUMBER" \