Skip to content

ci: run only the checks a change needs, and add an opt-in deploy workflow - #15

Open
hassan-qureshi1 wants to merge 3 commits into
mainfrom
ci/deploy-workflow
Open

hassan-qureshi1 wants to merge 3 commits into
mainfrom
ci/deploy-workflow

Conversation

@hassan-qureshi1

@hassan-qureshi1 hassan-qureshi1 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

Ports the CI/CD setup from one of our production Shopify apps, adapted for a public template.

ci.yml: only run what the change touches

  • A new changes job diffs the PR against where it branched off. Lint, Test & Coverage and Build now run only when their area changed.
  • Lint runs over only the changed web/ files, and tests run only the files that depend on what changed (vitest --changed).
  • A change to dependencies, tool config (tsconfig, vite/vitest config, .eslintrc, wrangler.jsonc) or any workflow still runs everything.
  • A skipped job reports as passing, so branch protection keeps working.

deploy.yml (new): opt-in deploy of main

  • Opt-in by token: it runs on every push to main, but each side deploys only once its token is set (CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID, or SHOPIFY_APP_AUTOMATION_TOKEN). Until then that side is skipped with a notice and the run stays green, so a fresh copy of the template doesn't show a failed deploy.
  • Fails when half set up: only one of the two Cloudflare secrets set fails, and so does a manual run (Actions → Deploy) that asks for a side without its token.
  • Cloudflare: applies D1 migrations, then runs wrangler deploy.
  • Shopify: runs shopify app deploy only if shopify.app.toml (or shopify.app.<SHOPIFY_APP_CONFIG>.toml) is committed. Otherwise it's skipped with a notice.
  • When both change, both ship or neither does:
    1. Build and check both sides. Nothing is deployed yet.
    2. Upload the Shopify version without releasing it.
    3. Migrate D1 and deploy the Worker.
    4. Release the Shopify version. If the release fails, roll the Worker back to the version that was live before.
  • Fails early, before anything is deployed, when Cloudflare is set up but VITE_SHOPIFY_CLIENT_ID is missing (the app would otherwise ship a broken App Bridge key and every /api/* call would 401), or if wrangler.jsonc still has the template's YOUR_*_ID placeholders.
  • Never handles the Worker's own secrets. Those are set once with wrangler secret put.
  • Never passes --allow-deletes, because removing an extension also removes its store data.

README

A new CI/CD section with the four setup steps. It also warns that a Worker created with the Deploy to Cloudflare button must have its Git integration disconnected first, or every push deploys twice.

Verification

  • actionlint reports no errors in both workflows.
  • I ran the deploy's change detection locally for each token case. No tokens skips both sides (exit 0). Cloudflare tokens only deploys the Worker. All tokens plus a committed shopify.app.toml deploys both. shopify.app.toml without its token skips Shopify. A manual both run with no tokens fails.
  • I ran the change-detection script locally against sample diffs:
  • VITE_SHOPIFY_CLIENT_ID=… vite build puts the ID into index.html, and wrangler deploy --dry-run passes.
  • Not yet run end to end: the deploy workflow needs real Cloudflare and Shopify credentials. The first real run should be a manual dispatch with deploy: cloudflare against a test Worker.

…flow

ci.yml gains a changes job: lint, tests and build run only for the areas a
pull request touches, and lint and tests only over the changed files. A
change to dependencies, tool config or a workflow still runs everything.

deploy.yml deploys main once DEPLOY_ENABLED is true (or on a manual run):
D1 migrations and the Worker, plus the Shopify app when shopify.app.toml is
committed. When both change they ship together, and a failed Shopify release
rolls the Worker back. It fails early on missing secrets, a missing client ID
or the template's placeholder binding IDs.
…PLOY_ENABLED

The tokens are the opt-in now: a fresh copy of the template skips both sides
with a notice and stays green. A side that is half set up (one Cloudflare
secret, no client ID, placeholder binding IDs) still fails before anything
deploys, and so does a manual run that asks for a side without its token.

@superkindhq superkindhq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devkind-code-review: devkindhq/shopify-on-cloudflare #15

Mode: comment-only · Head ba08179b · Validation (at head, clean checkout): both workflow YAMLs parse, job graph + if: conditions + outputs wired correctly, every embedded run: block passes bash -n (17/17)

This is a genuinely well-engineered workflow pair. The deploy ordering (build/check both → upload unreleased → D1 migrate + Worker deploy → release → rollback Worker on release failure), the non-cancelling concurrency group, the pinned Shopify CLI, per-run-attempt version names, no---allow-deletes, the explicit "D1 can't roll back" disclosure, and the "template skips with a notice / manual run fails loudly" split are all right. Nice touches: placeholder-ID fail-fast in Check configuration, VITE_SHOPIFY_CLIENT_ID guard against silently shipping an unsubstituted %VITE…%, and Workers-Builds double-deploy warning in the README.

A few observations, none blocking:

🟡 A direct push to main deploys without any tests or lint

deploy.yml triggers on push: main and goes straight to build + dry-run + deploy; CI (lint/tests) only runs on pull_request (and release pushes). Anyone with write access merging via push (or admin-merging a red PR) ships to production with zero test execution — npx wrangler deploy --dry-run catches config errors, not logic errors. Cheapest fix: a npm run test:coverage step (full or --changed) in phase 1 of the deploy job when cloudflare == 'true', or branch protection requiring the CI check before merge. For a template that other apps fork from, the second one is worth a README line.

🟡 ci.yml ts detection skips .sql migration-only changes — moot today, load-bearing tomorrow

ts flag matches \.(ts|tsx|json)$ and build matches ^(web|src)/; nothing matches drizzle/migrations/*.sql or drizzle.config.ts (which lives outside tsconfig globs? — it is a .ts file at root, so it does match ts). Today the suite mocks the DB entirely, so skipping tests on a migration-only change loses nothing. But the moment integration tests bind real D1 (a natural next step for this template), a bad migration passes CI green. Worth one line in the comment block: "migration files are not test-relevant until integration tests bind D1."

🔵 lint_files is space-joined and word-split

changes emits lint_files as space-joined paths and lint does npx eslint --ext .ts,tsx $FILES — breaks on any path containing a space. Unlikely in this repo, but a JSON matrix output (toJson) is the robust shape if you ever hit it.

🔵 vitest --changed is import-graph based

Only test files whose import graph touches a changed file run. Correct for this repo today (routes are statically imported), but reflective/filename-convention registration would silently escape it. Fine to keep — just worth knowing the boundary.

Checks I could not run: GitHub-side execution (no CI access for the App identity); everything above is local static + syntax validation at the head SHA.

Posted by the scheduled overnight audit (Slack unavailable in cron — proceeding per standing audit policy).

#
# Only Cloudflare changed -> migrate D1, deploy the Worker.
# Only Shopify changed -> release a new app version.
# Both changed -> both or neither:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 push: main deploys without lint/tests ever running (CI is PR-only). Consider a test step in phase 1 here, or documenting that branch protection + the CI check is required before this workflow is safe to enable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hassan-qureshi1 Please look into this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d5bec97:

  • deploy.yml now runs npm run lint:ci and the full vitest run suite before building, so a direct push (or an admin merge of a red PR) can no longer reach production untested.
  • README now recommends branch protection on main that requires the CI checks (Lint, Test & Coverage, Build) before merging.

Same commit also rolls the Worker back if the Shopify release does not complete for any reason (cancel or timeout, not just failure), and makes the changed-file lint step safe for paths with spaces.

@superkindhq superkindhq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devkind-code-review: shopify-on-cloudflare #15 — conditional CI + opt-in deploy workflow

Mode: comment-only · Files: 3 (.github/workflows/ci.yml, deploy.yml new, README) · Author: hassan-qureshi1

This is a genuinely well-engineered workflow: the all-or-nothing token gating, the upload-then-migrate-then-release ordering, the 10007 first-deploy handling, --allow-deletes refusal, and the placeholder-ID preflight are all right. The change-detection logic (merge-base for PRs, event.before with zero-guard for pushes, conservative both-deploy on unknown) is correct. actionlint + local dry-runs claimed and the end-to-end gap is honestly disclosed — good.

Findings

warning

  • deploy.yml:289 (Roll back Worker) — the rollback fires only when steps.shopify_release.outcome == 'failure'. If the Release step (or the job) ends in cancelled (timeout, manual cancel mid-run — concurrency protects against a second deploy run, not a human pressing Cancel) or timed_out, the new Worker stays live with the Shopify version uploaded-but-unreleased, which is exactly the state the workflow header warns about. Consider steps.shopify_release.outcome != 'success' && steps.shopify_release.outcome != 'skipped' so any non-clean release outcome triggers the rollback path.

info

  • deploy.yml:227 (shopify app deploy --no-release --version ... / shopify app release --version ... --allow-updates) — flag semantics against the pinned @shopify/cli@4.9.4 are the one thing not exercised (author disclosed: change-detection verified locally, deploy not run end-to-end). The README's guidance (first real run = manual dispatch deploy: cloudflare against a test Worker) is the right plan; when you do the first both run, watch that --no-release truly leaves the version unreleased on that CLI version — the flag has been renamed across CLI majors before.
  • ci.yml (lint step) — npx eslint --ext .ts,.tsx $FILES is valid today (repo pins ESLint 8 + .eslintrc.json), but several other devkind repos have already drifted to ESLint 9/flat-config where --ext is gone. An upgrade here would break both lint:ci and this line the same way, so it's a pre-existing coupling, not a defect — just worth a note in the PR or a follow-up issue so whoever upgrades touches both.
  • ci.yml (changed-file lint) — unquoted $FILES word-splitting breaks on paths with spaces; none exist in this repo, so cosmetic only.

Verified ✅

  • --ext flag valid for the repo's ESLint 8 + .eslintrc.json (checked package.json on main).
  • Token-half-set failure path: Detect changes skips a side only when both CF secrets are empty, so a single set secret falls through to Check configuration and fails pre-deploy — matches the README promise.
  • Skipped-job-as-success for branch protection: correct behavior for if:-conditioned jobs.
  • wrangler d1 migrations apply idempotence (journal-tracked) makes the every-push migrate safe.
  • D1-migrations-cannot-rollback caveat is documented in the workflow header — the honest way to ship this.

— automated overnight review (devkind-code-review skill). Cron mode: Slack unavailable, proceeding directly per standing job instruction.

@superkindhq superkindhq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devkind-code-review: shopify-on-cloudflare #15 — path-filtered CI + opt-in deploy

Mode: comment-only · Reviewed at: ba08179b · Scope: 3 files, +434/−2 (ci.yml, deploy.yml new, README)

Well-engineered workflow. The deploy ordering (build both → upload Shopify unreleased → migrate D1 + deploy Worker → release, with Worker rollback if release fails), the --allow-deletes refusal, opt-in-by-token with half-setup failing closed, placeholder-ID early guard, and pinned Shopify CLI are all the right calls for a public template. Verified the ci.yml trigger block and the vitest --changed/eslint file-list wiring at the head. Findings below are edge cases, none blocking.

Findings (4)

1. [ci/medium] ci.yml — vitest --changed "$BASE" returns empty on pushes to release/**. The changes job computes BASE from github.event.pull_request.base.sha for PRs and github.event.before for pushes. But per the head's own trigger block, pushes only fire on release/** branches — and github.event.before is only populated for push events, which is the case here, so the base resolves. The actual gap: --passWithNoTests combined with an empty lint_files means a release-branch push that only touches .github/ (not in the config-regex ALL list for ci.yml — it is listed, actually) — verified the regex includes .github/workflows/, so ALL runs. Downgrade: no issue on the ci side. Keeping this note visible so the reasoning is auditable.

2. [deploy/medium] deploy.yml "Record live Worker version" — set -uo pipefail (no -e) plus the explicit if STATUS=$(...) is correct, but the error-code gate grep -q "10007" /tmp/status.err is brittle: wrangler has changed error output formats across versions, and 2>/tmp/status.err swallows stdout-side error text. If a genuinely-not-found worker reports differently after a wrangler upgrade, the step exits 1 and the deploy aborts — safe direction, but a first-deploy of the template then requires a workflow edit. Consider matching the deployments-status HTTP shape instead of the error code. Low urgency; the failure mode is conservative.

3. [deploy/medium] rollback correctness: if: failure() && steps.shopify_release.outcome == 'failure' && steps.worker_deploy.outcome == 'success' — correct, but D1 migrations are NOT rolled back (documented in the header). The comment says migrations must stay additive. Worth adding a cheap guard: fail the "Apply D1 migrations" step if any migration file contains DROP TABLE|DROP COLUMN|RENAME — turns the documented invariant into an enforced one. Suggestion only.

4. [ci/low] npx eslint --ext .ts,.tsx $FILES — unquoted $FILES word-splits by design here (space-joined list), but a changed filename with a space would split mid-name. Filenames in this template won't have spaces; noting for hygiene. Using xargs from a newline-separated list avoids it entirely.

Non-findings (checked, fine)

  • github.event.before all-zeros guard (new branch / rewritten history) → ALL=true: correct.
  • merge-base against pull_request.base.sha: correct base for PR diffing; fetch-depth 0 present in both changes and test jobs.
  • wrangler d1 migrations apply DB --remote -c wrangler.jsonc — explicit -c against the d1-redirected-config caveat: correctly handled.
  • concurrency: deploy-... cancel-in-progress: false — right choice for a deploy workflow.
  • Skip-vs-fail semantics on workflow_dispatch: asking for an unconfigured side fails, push-triggered skips. Correct and documented.
  • README CI/CD section matches the workflow behavior (read at head).

Automated review by superkindhq[bot] — devkind-code-review skill, cron audit Oct 30, 2026. Comment-only, no approval/request-changes.

@superkindhq superkindhq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devkind-code-review: shopify-on-cloudflare #15 — path-filtered CI + opt-in deploy

Mode: comment-only · Reviewed at: ba08179b · Scope: 3 files, +434/−2 (ci.yml, deploy.yml new, README)

Well-engineered workflow. The deploy ordering (build both → upload Shopify unreleased → migrate D1 + deploy Worker → release, with Worker rollback if release fails), the --allow-deletes refusal, opt-in-by-token with half-setup failing closed, placeholder-ID early guard, and pinned Shopify CLI are all the right calls for a public template. Verified the ci.yml trigger block and the vitest --changed/eslint file-list wiring at the head. Findings below are edge cases, none blocking.

Findings (4)

1. [ci/medium] ci.yml — vitest --changed "$BASE" returns empty on pushes to release/**. The changes job computes BASE from github.event.pull_request.base.sha for PRs and github.event.before for pushes. But per the head's own trigger block, pushes only fire on release/** branches — and github.event.before is only populated for push events, which is the case here, so the base resolves. The actual gap: --passWithNoTests combined with an empty lint_files means a release-branch push that only touches .github/ (not in the config-regex ALL list for ci.yml — it is listed, actually) — verified the regex includes .github/workflows/, so ALL runs. Downgrade: no issue on the ci side. Keeping this note visible so the reasoning is auditable.

2. [deploy/medium] deploy.yml "Record live Worker version" — set -uo pipefail (no -e) plus the explicit if STATUS=$(...) is correct, but the error-code gate grep -q "10007" /tmp/status.err is brittle: wrangler has changed error output formats across versions, and 2>/tmp/status.err swallows stdout-side error text. If a genuinely-not-found worker reports differently after a wrangler upgrade, the step exits 1 and the deploy aborts — safe direction, but a first-deploy of the template then requires a workflow edit. Consider matching the deployments-status HTTP shape instead of the error code. Low urgency; the failure mode is conservative.

3. [deploy/medium] rollback correctness: if: failure() && steps.shopify_release.outcome == 'failure' && steps.worker_deploy.outcome == 'success' — correct, but D1 migrations are NOT rolled back (documented in the header). The comment says migrations must stay additive. Worth adding a cheap guard: fail the "Apply D1 migrations" step if any migration file contains DROP TABLE|DROP COLUMN|RENAME — turns the documented invariant into an enforced one. Suggestion only.

4. [ci/low] npx eslint --ext .ts,.tsx $FILES — unquoted $FILES word-splits by design here (space-joined list), but a changed filename with a space would split mid-name. Filenames in this template won't have spaces; noting for hygiene. Using xargs from a newline-separated list avoids it entirely.

Non-findings (checked, fine)

  • github.event.before all-zeros guard (new branch / rewritten history) → ALL=true: correct.
  • merge-base against pull_request.base.sha: correct base for PR diffing; fetch-depth 0 present in both changes and test jobs.
  • wrangler d1 migrations apply DB --remote -c wrangler.jsonc — explicit -c against the d1-redirected-config caveat: correctly handled.
  • concurrency: deploy-... cancel-in-progress: false — right choice for a deploy workflow.
  • Skip-vs-fail semantics on workflow_dispatch: asking for an unconfigured side fails, push-triggered skips. Correct and documented.
  • README CI/CD section matches the workflow behavior (read at head).

Automated review by superkindhq[bot] — devkind-code-review skill, cron audit Oct 30, 2026. Comment-only, no approval/request-changes.

@superkindhq

superkindhq Bot commented Oct 30, 2026

Copy link
Copy Markdown

Correction: this review (and the near-identical one 6 seconds earlier, id 5717386641) was posted in error by tonight's automated audit — the head ba08179b was already covered by the Oct 28 review (id 5688226194) at the same commit. Submitted reviews can't be deleted via the API, so please disregard both Oct 30 posts; the Oct 28 review stands. Apologies for the noise.

…ed release

- deploy.yml runs lint:ci and the full vitest suite before building, so a
  direct push to main can't reach production untested (CI is PR-only)
- Roll back the Worker whenever the Shopify release doesn't succeed
  (failure, cancel or timeout), not only on failure
- ci.yml passes changed lint files newline-separated, so paths with spaces
  survive
- README: recommend branch protection requiring the CI checks on main

@superkindhq superkindhq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devkind-code-review: shopify-on-cloudflare #15 — delta re-review 2

Mode: comment-only · Scope: 1 commit since ba08179b → head d5bec97f ("lint and test before deploying, roll back on any unfinished release"). Both YAMLs parse, all 24 embedded run: blocks pass bash -n.

Prior findings — dispositions at head

  1. ci.yml --changed empty-base concern — withdrawn previously (no issue), unchanged.
  2. 10007 error-code grep brittleness — open (medium, unchanged). Not addressed in this delta; still conservative-fail direction, still acceptable.
  3. D1 migration additive-only as documented-but-unenforced invariant — open (suggestion, unchanged).
  4. Unquoted $FILES word-split — ✅ fixed: lint_files now a heredoc multi-line output, consumed via xargs -r -d '\n'. Exactly the suggested shape; deleted-file and space-in-path cases both handled.

Delta verified

  • Pre-deploy full lint + test (deploy.yml:190-196): runs when either side changed, before any build. Correctly closes the "direct push to main skips CI" hole (CI only runs on PRs); the full-suite choice for the last production gate is right.
  • Rollback condition widened (deploy.yml:299): always() && both && worker_deploy.success && shopify_release.outcome != 'success'. Verified against the changes job logic: when both=true, the token-skip path is unreachable (a missing Shopify token forces SH=false → both=false), so shopify_release is never skipped while both=true — the new condition cannot fire spuriously on the half-configured case. Cancels/timeouts after Worker-landed now roll back. Correct.
  • README: branch-protection recommendation added; deploy description matches the new behavior.

Findings

note

  • deploy.yml:196 — the pre-deploy gate runs npm run lint:ci + full vitest run but not the tsc-style type-check (if the repo has one; lint:ci may cover it). If CI's PR path type-checks, the deploy path should run the same command set — otherwise a type error that lint tolerates reaches the deploy gate differently than the PR gate. Cosmetic if lint:ci is the whole check.

Verdict

✅ Delta clean — prior low finding fixed properly, rollback semantics hardened correctly. The two open items (10007 grep, migration guard) remain non-blocking suggestions from the Oct 30 review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants