WIP: ci: check, preview and deploy the site on CircleCI #10
Loading…
Reference in a new issue
No description provided.
Delete branch "drcrow/Site:ci/circleci"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Nothing checks the site before it deploys, and every merge deploys, even a README change. This moves the checks, preview and deploy to CircleCI, so a broken link or page fails the PR instead of the live site.
What changed
.circleci/config.ymlhas one small setup job per event (pull request, push to main, manual API run). Each one looks at which files changed and continues with.circleci/shared.ymlplus that event's file in.circleci/events/. Changes underpublic/,wrangler.jsoncor the package files run lint, checks and a preview; anything else runs lint only.magicbeandev/ci, used by all three repos (source in a newMagicBeanDev/orbrepo). This repo keeps only its own jobs.mise run testuses standard tools:lycheefor links,html-validate,jqon the Matrix.well-knownfile, andwrangler deploy --dry-run. Results show up as CircleCI test results.public/is saved as a CircleCI artifact, and one PR comment links to it, updated on every push. No Cloudflare token is used on PRs. A Cloudflare preview is still available as a manual run.ci/circleci: gate, the one check branch protection needs.ci: approvedlabel (Forgejo only lets people with write access do that). A separate CircleCI project then runs the same checks on that exact commit with no secrets, and posts the gate status. The label stays on, so new pushes keep running. If a fork PR goes 14 days without activity, the label is removed automatically.mise.tomlpins the tools and haslint,testandvalidatetasks. Also adds pre-commit hooks (Conventional Commit messages included), a devcontainer, and a Chunk sidecar config.public/index.htmlgets<!DOCTYPE html>.Testing
Tested:
circleci config validateon every event's merged config with the orb inlined; the orb's conftest policies (16 pass);mise run lintandmise run testin a clean container and on a fresh Chunk sidecar.Not tested: a live CircleCI run (it starts once this is on main and the orb is published), a real deploy (needs the Cloudflare token in CircleCI), and the fork flow end to end (needs the org webhook).
Feedback very welcome, especially on whether an artifact link works as a preview for you, or whether you'd rather keep a Cloudflare preview on every PR.
a4e6d3085da41c7991bda41c7991bdd07dd27288Looked over what runs when, at
d07dd272(read ata41c7991; the push since then adds diagrams todocs/ci.mdand changes nothing else). Seven things in the files, then points that depend on the orb or on settings I cannot see.1. The manual dry run carries the production Cloudflare context onto any branch and runs package scripts there.
.circleci/events/manual.yml:21-37:manual-release-dry-rungivesdeploythecloudflare-prodcontext with no branch condition. Thedeployjob (shared.yml:203-217) checks out the selected branch and runsinstall-node-depsbefore the dry-run guard, and that command only passes--ignore-scriptswhen asked (shared.yml:46-54);deploydoes not ask. So a dry run on a branch runs that branch's npm lifecycle scripts with the production token in the environment. A dry run needs neither the context nor the scripts: a separate job without the context, orignore_scripts: trueplus no context, closes it.2. Lint fails on
mise.tomlas committed. The file has no final newline (it ends in"""),.pre-commit-config.yaml:9enablesend-of-file-fixer, and lint runspre-commit run --all-files(shared.yml:73-75, andmise run lint). That hook rewrites the file and exits non-zero. It is the only file in the diff without a final newline.3. The preview's link rewrite never matches.
shared.yml:116-117: ins/(href|src)=(\"|')\/([^/\"' ][^\"']*)\1/\1=\2\3\1/gthe closing quote is written as\1, which ishreforsrc; the quote is\2. On<link href="/style.css"><img src="/img/logo.png">the command changes nothing; with\2for the closing quote it giveshref="style.css"andsrc="img/logo.png".public/index.htmlhas five root-relative references (the three icons,logo.webp,longshot.webp), which in the artifact preview point at the artifact host's root.4. The manual Cloudflare preview keeps files the pull request deleted.
shared.yml:155-169resets to main and then extracts the pull request'spublic/over main's. A file removed or renamed in the pull request stays in the upload. Clearingpublic/before the extract fixes it.5. The manual preview looks at the first 50 open pull requests only.
shared.yml:176-183asks forpulls?state=open&limit=50and takes no further pages; a pull request beyond that is treated as absent and the job ends "No PR number; skipping upload" with success.6. Docs changes are "full".
mapping.conf:12-14mapsdocs/,CONTRIBUTING.mdandAGENTS.mdtofull, so they run tests and a preview on a pull request and deploy on main (events/main.yml:3-20). The description says anything outsidepublic/,wrangler.jsoncand the package files runs lint only; that holds forREADME.md, which has no rule.7. The fork workflow's condition is always true.
.circleci/events/fork.yml:4-5haswhen: greater: [<< pipeline.parameters.fork_pr >>, 0].greateris not one of CircleCI's logic statements, and the compiler does not reject it: an unknown operator counts as true. A small config with exactly that condition compiles as valid and keeps the workflow withfork_prat 0 as well as at 7; withwhen: pipeline.parameters.fork_pr > 0it is dropped at 0. So the workflow runs whenever this file is continued into, not only forfork_pr> 0 asdocs/ci.mdhas it. The same line is in Longshot and the launcher.Depends on the orb or on settings:
8. Which pull request does the preview comment go to?
shared.yml:141-144passespr: << pipeline.parameters.fork_pr >>andcommit-sha: << pipeline.parameters.fork_sha >>tomb/preview-commentin the same-repository workflow too, where those are 0 and empty. Does the orb look the number up itself in that case?9. Can a tester open the artifact link without a CircleCI account?
shared.yml:119-125builds a plainoutput.circle-artifacts.comlink. If the project is private, that link asks for a sign-in.10. A failed check and the gate. The gates use plain
requires(events/pr.yml:32-34), so when lint, test or the comment job fails the gate job does not run. Does something else then post a failedci/circleci: gate, or does the check stay missing?11. "Never has secrets." The new text in
docs/ci.mdsays the forks project never has secrets.events/fork.yml:15-19givesfork-preview-commenttheforgejo-commentcontext and:23-42gives the two report jobsforgejo-bot;forks.ymlgives the doorbellforgejo-bot. If the point is that jobs running fork code ask for no context, the sentence could say that. Also still in the new text: "A change outsidepublic/,wrangler.jsoncand the package files runs lint andgateonly", which point 6 contradicts.12. Two deploys while both run.
.forgejo/workflows/deploy.ymlstill deploys on every push to main andpreview.ymlstill makes Cloudflare previews with the token on pull requests. Until they are removed, a site change deploys twice and a README-only merge still deploys.Checked and fine: the orb is pinned to an exact version; the automatic pull request and fork workflows ask for no Cloudflare context; the main deploy requires lint and test; the link check runs offline, so an outside site being down cannot fail a pull request; a README-only change on main selects lint and gate only; the manual Cloudflare preview installs with
--ignore-scriptsand takes onlypublic/from the pull request.One request: https://git.magicbean.dev/MagicBeanDev/orb is not readable (404), and the setup, fork handling, preview comment and gate live in the orb. Those parts cannot be reviewed from this pull request until its source can be read.
Thanks @mooki, this is a really useful review. You caught things
circleci config validatecan't. Fixed ind07dd272..a7cc146:deployinstalls with--ignore-scriptswhenever it's a dry run (a04620b).mise.tomlfinal newline: fixed (0bb8dca)..gitignorehad the same problem (a7cc146).\2. Your sample becomeshref="style.css"andsrc="img/logo.png"(9c51ccd).public/is cleared before the PR's copy is extracted (697e4a2).243c1ae).docs/,CONTRIBUTING.mdandAGENTS.mdare lint-only now, as the description says (6c8e618).greater:: confirmed it counts as always true, so the fork workflow now useswhen: pipeline.parameters.fork_pr > 0. Checked withcircleci config process: the workflow is dropped at 0 and kept at 7 (5965b00).Orb and settings:
pr: 0,mb/preview-commentlooks up the open same-repo PR for the branch, paging through all of them, and skips quietly if there isn't one.ci/circleci: <job>status, so a failed lint shows red on the PR with the cause.gatedoesn't appear, and once it's a required check that blocks the merge. I'd rather not givegatean API token on PR pipelines just to turn it red. Happy to revisit if that's confusing in practice.b8d5b96).deploy.ymlstays the only deployer (da5a2e8). The cutover PR flips that and removesdeploy.ymlandpreview.ymlin the same commit.Orb source: MagicBeanDev/orb is being created now, and I'll open the first PR there with the source as soon as it exists. Until then I can share a tarball if that helps.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.