diff --git a/.github/workflows/on_pr.yml b/.github/workflows/on_pr.yml index c5abea3..1b4af1f 100644 --- a/.github/workflows/on_pr.yml +++ b/.github/workflows/on_pr.yml @@ -1,7 +1,7 @@ name: on_pr # Generated from plexus-ms/tooling, templates/repo-turbo: edit the template, never this file. -# A package repo's pull-request mount, check and the changeset guard (§ 5 PLX-Delivery). +# A package repo's pull-request mount, the test job and the changeset guard (§ 5 PLX-Delivery). on: pull_request: @@ -14,11 +14,13 @@ concurrency: cancel-in-progress: true jobs: - check: - uses: plexus-ms/tooling/.github/workflows/_check.yml@0.133.0 + test: + uses: plexus-ms/tooling/.github/workflows/_check.yml@0.134.1 with: strategy: ${{ vars.CI_STRATEGY || 'github' }} - tasks: verify + tasks: test + secrets: + op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} changeset-status: # `changeset version` consumed the release branch's changesets, and the bot's branches get theirs from the @@ -35,7 +37,7 @@ jobs: changeset: if: ${{ startsWith(github.head_ref, 'renovate/') }} - uses: plexus-ms/tooling/.github/workflows/_changeset.yml@0.133.0 + uses: plexus-ms/tooling/.github/workflows/_changeset.yml@0.134.1 with: gh-client-id: ${{ vars.GH_CLIENT_ID }} strategy: ${{ vars.CI_STRATEGY || 'github' }} diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index e55f32c..8e4a6b9 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -1,7 +1,7 @@ name: on_push # Generated from plexus-ms/tooling, templates/repo-turbo: edit the template, never this file. -# A package repo's trunk mount, check then publish; started by hand on a branch, snapshot versions of it (§ 5 PLX-Delivery). +# A package repo's trunk mount, the test job then publish; started by hand on a branch, snapshot versions of it (§ 5 PLX-Delivery). on: push: @@ -19,15 +19,17 @@ permissions: id-token: write jobs: - check: - uses: plexus-ms/tooling/.github/workflows/_check.yml@0.133.0 + test: + uses: plexus-ms/tooling/.github/workflows/_check.yml@0.134.1 with: strategy: ${{ vars.CI_STRATEGY || 'github' }} - tasks: verify + tasks: test + secrets: + op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} publish: - needs: check - uses: plexus-ms/tooling/.github/workflows/_publish-package.yml@0.133.0 + needs: test + uses: plexus-ms/tooling/.github/workflows/_publish-package.yml@0.134.1 with: strategy: ${{ vars.CI_STRATEGY || 'github' }} registry: npm diff --git a/.github/workflows/plx-update.yml b/.github/workflows/plx-update.yml index 206902d..61b5f93 100644 --- a/.github/workflows/plx-update.yml +++ b/.github/workflows/plx-update.yml @@ -18,7 +18,7 @@ permissions: jobs: update: - uses: plexus-ms/tooling/.github/workflows/_plx-update.yml@0.133.0 + uses: plexus-ms/tooling/.github/workflows/_plx-update.yml@0.134.1 with: version: ${{ inputs.version || '' }} now: ${{ github.event_name == 'workflow_dispatch' }} diff --git a/PLEXUS.md b/PLEXUS.md index e51fa64..6a920d8 100644 --- a/PLEXUS.md +++ b/PLEXUS.md @@ -1,5 +1,5 @@ --- -version: 0.133.0 +version: 0.134.1 templates: [repo-turbo, updates] ci_strategy: github package_registry: npm @@ -8,6 +8,7 @@ private_packages_scope: '' publishes_packages: true tenant: plexus-ms update_max_age: 7 +postgres: "" --- - The `@plexus-ms/*` libraries: tenant-neutral methodology for the web/Node/TypeScript world on its own semver, versioned by changesets and published through trusted publishing (§ 5 PLX-Delivery); `plx` and `@plexus-ms/lib` live in `tooling` and carry the Plexus version (§ 1.5 PLX). diff --git a/hk.pkl b/hk.pkl index 6ec23d4..8f7c368 100644 --- a/hk.pkl +++ b/hk.pkl @@ -10,12 +10,16 @@ hooks { check = "mise :lint {{ files }}" fix = "mise :lint --write {{ files }}" } + ["check"] { + depends = "lint" + check = "mise :check" + } } } ["pre-push"] { steps { - ["check"] { - check = "mise :check" + ["test"] { + check = "mise :test" } } } diff --git a/mise.toml b/mise.toml index b9bc22e..dc4e5f1 100644 --- a/mise.toml +++ b/mise.toml @@ -8,9 +8,13 @@ node = "24" hk = "latest" # The plx pins are written with each Plexus version, never by the update bot (§ 1 PLX-Updates); # allow_low_downloads only waives npm's young-package heuristics. +<<<<<<< current "npm:@plexus-ms/cli" = { version = "0.133.0", allow_low_downloads = true } # The server @plexus-ms/test-postgres starts in its own tests; PLX_POSTGRES_MAJOR below names its major. "conda:postgresql" = "18.6" +======= +"npm:@plexus-ms/cli" = { version = "0.134.1", allow_low_downloads = true } +>>>>>>> new render [settings] # Not a version source: it lets config_roots match a project without a mise config of its own, @@ -23,9 +27,15 @@ postinstall = "if command -v hk >/dev/null; then hk install --mise; fi && npx co [env] _.path = ["{{config_root}}/node_modules/.bin"] +<<<<<<< current # The major the tests ask the server for: that of the conda:postgresql pin, which a wrong one fails. # Declared in turbo.json, so a new major runs the tests again. PLX_POSTGRES_MAJOR = "18" +======= +# Turbo hashes these where a turbo.json declares them: the platform on an app's build only, and never in the +# root's env or globalEnv, which would move the hash of every task; the major in the root's env of test and e2e. +PLX_PLATFORM = "{{ os() }}-{{ arch() }}" +>>>>>>> new render [tasks.dev] description = "No-op: a package repo has no development environment to start; build builds its packages and test exercises them" @@ -45,37 +55,12 @@ if [ -n "${usage_name:-}" ]; then [ ! -f "packages/$usage_name/package.json" ] || dir=packages/$usage_name [ -n "$dir" ] || { echo "build: no package $usage_name under packages/" >&2; exit 1; } fi -turbo run build ${dir:+--filter="{./$dir}..."} +./turbow trusted run build ${dir:+--filter="{./$dir}..."} ''' -[tasks.verify] -description = "Perform all steps that verify code quality" -usage = 'arg "[name]" help="Package to verify, by its directory name under packages/ (e.g. my-package, defaults to all)"' -run = [ - 'mise run check ${usage_name:+"$usage_name"}', - 'mise run test ${usage_name:+"$usage_name"}', -] - -[tasks.install] -description = "Install and wire up project dependencies" -hide = true -run = "pnpm install" -sources = ["package.json", "packages/*/package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml"] -outputs = ["node_modules/.pnpm/lock.yaml"] - -[tasks.lint] -depends = ["install"] -description = "Lint and format the codebase" -usage = ''' -flag "--write" help="Apply safe fixes and formatting in place" -arg "" var=#true default="." help="Files or directories to lint (defaults to the whole repo)" -''' -# usage shell-quotes var-arg values, so re-parse them via eval instead of bare expansion. -run = 'eval "set -- $usage_paths"; biome check ${usage_write:+--write} --no-errors-on-unmatched "$@"' - [tasks.check] depends = ["install"] -description = "Run static checks on the codebase: lint and the contracts' checks (plx doctor), repo-wide, then each project's check script" +description = "Run every static check, executing no test: lint (Biome) and the contracts' checks (plx doctor), repo-wide, then each project's check script" usage = 'arg "[name]" help="Package to check, by its directory name under packages/ (e.g. my-package, defaults to all)"' run = ''' dir= @@ -88,12 +73,12 @@ if [ -n "${usage_name:-}" ]; then fi mise run lint plx doctor -turbo run check ${dir:+--filter="{./$dir}..."} +./turbow shared run check ${dir:+--filter="{./$dir}..."} ''' [tasks.test] depends = ["install"] -description = "Run tests on the codebase" +description = "Run check, then every test that lives beside the code; no built app is needed" usage = 'arg "[name]" help="Package to test, by its directory name under packages/ (e.g. my-package, defaults to all)"' run = ''' dir= @@ -104,5 +89,40 @@ if [ -n "${usage_name:-}" ]; then [ ! -f "packages/$usage_name/package.json" ] || dir=packages/$usage_name [ -n "$dir" ] || { echo "test: no package $usage_name under packages/" >&2; exit 1; } fi -turbo run test ${dir:+--filter="{./$dir}..."} +mise run check ${usage_name:+"$usage_name"} +./turbow shared run test ${dir:+--filter="{./$dir}..."} ''' + +[tasks.e2e] +depends = ["install"] +description = "Run the end-to-end suites, after the workspace packages they depend on are built; it neither checks nor tests" +usage = 'arg "[name]" help="Package to e2e, by its directory name under packages/ (e.g. my-package, defaults to all)"' +# A name selects the project and the projects that depend on it, since a suite is a package that depends on its app. +run = ''' +dir= +if [ -n "${usage_name:-}" ]; then + case $usage_name in + */* | . | ..) echo "e2e: $usage_name is not a directory name under packages/" >&2; exit 1 ;; + esac + [ ! -f "packages/$usage_name/package.json" ] || dir=packages/$usage_name + [ -n "$dir" ] || { echo "e2e: no package $usage_name under packages/" >&2; exit 1; } +fi +./turbow trusted run e2e ${dir:+--filter="...{./$dir}"} +''' + +[tasks.install] +description = "Install and wire up project dependencies" +hide = true +run = "pnpm install" +sources = ["package.json", "packages/*/package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml"] +outputs = ["node_modules/.pnpm/lock.yaml"] + +[tasks.lint] +depends = ["install"] +description = "Lint and format the codebase" +usage = ''' +flag "--write" help="Apply safe fixes and formatting in place" +arg "" var=#true default="." help="Files or directories to lint (defaults to the whole repo)" +''' +# usage shell-quotes var-arg values, so re-parse them via eval instead of bare expansion. +run = 'eval "set -- $usage_paths"; biome check ${usage_write:+--write} --no-errors-on-unmatched "$@"' diff --git a/turbo.json b/turbo.json index 8198a1c..6b71136 100644 --- a/turbo.json +++ b/turbo.json @@ -3,7 +3,16 @@ "tasks": { "build": { "dependsOn": ["^build"], - "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**", "!docker/compose*.yaml"], + "inputs": [ + "$TURBO_DEFAULT$", + "!**/{README,AGENTS,PLEXUS}.md", + "!docs/**", + "!docker/compose*.yaml", + "!**/*.{test,spec}.*", + "!**/{__tests__,__snapshots__}/**", + "!tests/**", + "!{vitest,playwright,jest}*.config.*" + ], "outputs": ["dist/**"] }, "check": { @@ -11,9 +20,15 @@ "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**", "!docker/compose*.yaml"] }, "test": { - "dependsOn": ["build"], + "dependsOn": ["^build"], + "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**"], + // CI is passed through, never hashed: a pass on a developer's machine counts in CI, so no test may change what it tests by CI. + "passThroughEnv": ["CI"] + }, + "e2e": { + "dependsOn": ["^build"], "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**"], - "passThroughEnv": ["CI", "DATABASE_URL", "E2E_*", "PLAYWRIGHT_*", "PW_TEST_*"] + "passThroughEnv": ["CI", "PLAYWRIGHT_BROWSERS_PATH"] }, "dev": { "cache": false, diff --git a/turbow b/turbow new file mode 100755 index 0000000..110baee --- /dev/null +++ b/turbow @@ -0,0 +1,86 @@ +#!/bin/sh +# Generated from plexus-ms/tooling, templates/repo-turbo. +# Turbo with the remote cache its verb may use, as the tasks call it: ./turbow . +set -eu + +cache=${1:-} +case $cache in + shared | trusted) shift ;; + *) + echo "usage: ./turbow " >&2 + exit 2 + ;; +esac + +# Where and how artifacts go is turbow's alone: no remote-cache setting of the caller's shell reaches Turbo, and no +# artifact is signed. +unset TURBO_API TURBO_TEAM TURBO_TEAMID TURBO_TOKEN TURBO_CACHE TURBO_REMOTE_CACHE_SIGNATURE_KEY \ + TURBO_REMOTE_CACHE_READ_ONLY TURBO_PREFLIGHT TURBO_REMOTE_ONLY + +reason= +# Outside a job of the forge no machine holds the trusted keys: every verb uses the shared server, by default this +# machine's own, run without a token. In a job (GITHUB_ACTIONS=true, which the forge's runner sets and CI alone does not) +# a verb uses only the server its job started (.github/actions/turbo-cache of plexus-ms/tooling), with the job's token, +# and build and e2e never use the shared one. A server named none is a tenant without the bucket. +if [ "${GITHUB_ACTIONS:-}" != true ]; then + from=shared server=${PLX_TURBO_SHARED:-http://127.0.0.1:8585} token=${PLX_TURBO_SHARED_TOKEN:-local} + if [ "$server" != none ] && ! node -e ' + fetch(process.argv[1], { signal: AbortSignal.timeout(2000) }).then( + (answer) => process.exit(answer.ok ? 0 : 1), + () => process.exit(1), + );' "$server/management/health"; then + reason="nothing answers at $server" + fi +elif [ "$cache" = trusted ]; then + if [ -z "${PLX_TURBO_TRUSTED:-}" ]; then + echo "turbow: in a job of the forge, build and e2e need the trusted cache server, and this job started none (PLX_TURBO_TRUSTED is unset); they never use the shared one" >&2 + exit 1 + fi + from=trusted server=$PLX_TURBO_TRUSTED token=${PLX_TURBO_TRUSTED_TOKEN:-local} +else + from=shared server=${PLX_TURBO_SHARED:-} token=${PLX_TURBO_SHARED_TOKEN:-local} + [ -n "$server" ] || reason="this job started no shared cache server (PLX_TURBO_SHARED is unset)" +fi +if [ "$server" = none ]; then + reason="the tenant has no $from bucket" +fi + +# The team keeps the repos of a tenant apart in a bucket: owner-repo, the last two names of the path of origin's URL +# (a nested group keeps its last two), in lower case, without .git, every character but [a-z0-9._-] a dash. +if [ -z "$reason" ]; then + if url=$(git remote get-url origin 2>/dev/null); then + path=$(printf '%s' "$url" | LC_ALL=C tr '[:upper:]' '[:lower:]') + case $path in + *://*) + path=${path#*://} + path=${path#*/} + ;; + *) case ${path%%/*} in *:*) path=${path#*:} ;; esac ;; + esac + path=${path%/} + path=${path%.git} + case $path in + */*) + rest=${path%/*} + team=$(printf '%s-%s' "${rest##*/}" "${path##*/}" | LC_ALL=C sed 's/[^a-z0-9._-]/-/g') + ;; + *) reason="origin's URL names no owner to name the team with ($url)" ;; + esac + else + reason="the checkout has no origin to name its team" + fi +fi + +if [ -n "$reason" ]; then + echo "turbow: without a remote cache: $reason" >&2 + # Told to Turbo too: a login and a linked repo would otherwise send the artifacts there. + export TURBO_API='' TURBO_TEAM='' TURBO_TOKEN='' TURBO_CACHE=local:rw +elif [ "$from" = trusted ]; then + echo "turbow: the trusted remote cache at $server, team $team" >&2 + # Never the local cache, which a shared run of this checkout may have filled from the shared bucket. + export TURBO_API="$server" TURBO_TEAM="$team" TURBO_TOKEN="$token" TURBO_CACHE=remote:rw +else + echo "turbow: the shared remote cache at $server, team $team" >&2 + export TURBO_API="$server" TURBO_TEAM="$team" TURBO_TOKEN="$token" TURBO_CACHE=local:rw,remote:rw +fi +exec turbo "$@"