@smoothbricks/nx-plugin 0.4.15 → 0.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +17 -0
  2. package/dist/deploy-policy.d.ts +26 -0
  3. package/dist/deploy-policy.d.ts.map +1 -0
  4. package/dist/deploy-policy.js +36 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +153 -14
  7. package/dist/managed-assets.d.ts +3 -0
  8. package/dist/managed-assets.d.ts.map +1 -0
  9. package/dist/managed-assets.js +3 -0
  10. package/dist/managed-files/ci-workflow.d.ts +215 -0
  11. package/dist/managed-files/ci-workflow.d.ts.map +1 -0
  12. package/dist/managed-files/ci-workflow.js +1082 -0
  13. package/dist/managed-files/context.d.ts +51 -0
  14. package/dist/managed-files/context.d.ts.map +1 -0
  15. package/dist/managed-files/context.js +206 -0
  16. package/dist/managed-files/files.d.ts +53 -0
  17. package/dist/managed-files/files.d.ts.map +1 -0
  18. package/dist/managed-files/files.js +248 -0
  19. package/dist/managed-files/generator.d.ts +16 -0
  20. package/dist/managed-files/generator.d.ts.map +1 -0
  21. package/dist/managed-files/generator.js +41 -0
  22. package/dist/managed-files/github-runs-on.d.ts +19 -0
  23. package/dist/managed-files/github-runs-on.d.ts.map +1 -0
  24. package/dist/managed-files/github-runs-on.js +48 -0
  25. package/dist/managed-files/managed-content.d.ts +45 -0
  26. package/dist/managed-files/managed-content.d.ts.map +1 -0
  27. package/dist/managed-files/managed-content.js +102 -0
  28. package/dist/managed-files/managed-format.d.ts +37 -0
  29. package/dist/managed-files/managed-format.d.ts.map +1 -0
  30. package/dist/managed-files/managed-format.js +94 -0
  31. package/dist/managed-files/paths.d.ts +8 -0
  32. package/dist/managed-files/paths.d.ts.map +1 -0
  33. package/dist/managed-files/paths.js +46 -0
  34. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +5 -0
  35. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -0
  36. package/dist/managed-files/pr-preview-cleanup-workflow.js +38 -0
  37. package/dist/managed-files/private-npm-policy.d.ts +7 -0
  38. package/dist/managed-files/private-npm-policy.d.ts.map +1 -0
  39. package/dist/managed-files/private-npm-policy.js +51 -0
  40. package/dist/managed-files/publish-workflow.d.ts +150 -0
  41. package/dist/managed-files/publish-workflow.d.ts.map +1 -0
  42. package/dist/managed-files/publish-workflow.js +989 -0
  43. package/dist/managed-files/tree.d.ts +30 -0
  44. package/dist/managed-files/tree.d.ts.map +1 -0
  45. package/dist/managed-files/tree.js +91 -0
  46. package/dist/platform-targets.d.ts +5 -0
  47. package/dist/platform-targets.d.ts.map +1 -0
  48. package/dist/platform-targets.js +4 -0
  49. package/dist/typecheck-test-policy.d.ts +5 -9
  50. package/dist/typecheck-test-policy.d.ts.map +1 -1
  51. package/dist/typecheck-test-policy.js +69 -99
  52. package/dist/workspace-config-policy.d.ts +2 -3
  53. package/dist/workspace-config-policy.d.ts.map +1 -1
  54. package/dist/workspace-config-policy.js +8 -3
  55. package/dist/workspace-manifest.d.ts +291 -0
  56. package/dist/workspace-manifest.d.ts.map +1 -0
  57. package/dist/workspace-manifest.js +6 -0
  58. package/dist/workspace-package-policy.d.ts +13 -0
  59. package/dist/workspace-package-policy.d.ts.map +1 -0
  60. package/dist/workspace-package-policy.js +24 -0
  61. package/generators.json +5 -0
  62. package/managed/raw/envrc +20 -0
  63. package/managed/raw/git-format-staged.yml +82 -0
  64. package/managed/raw/gitattributes +8 -0
  65. package/managed/raw/tooling/devenv +83 -0
  66. package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
  67. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
  68. package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
  69. package/managed/raw/tooling/direnv/repo-path +34 -0
  70. package/managed/raw/tooling/direnv/secret-references.ts +636 -0
  71. package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
  72. package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
  73. package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
  74. package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
  75. package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
  76. package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
  77. package/managed/raw/tsconfig.lib.json +28 -0
  78. package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
  79. package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
  80. package/managed/templates/github/actions/cache-nx/action.yml +21 -0
  81. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
  82. package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
  83. package/managed/templates/github/actions/setup-devenv/action.yml +245 -0
  84. package/managed/templates/github/workflows/managed-files.yml +127 -0
  85. package/package.json +89 -5
  86. package/src/bun-bootstrap.test.ts +0 -6
  87. package/src/deploy-policy.ts +40 -0
  88. package/src/index.test.ts +225 -2
  89. package/src/index.ts +180 -14
  90. package/src/managed-assets.ts +4 -0
  91. package/src/managed-files/ci-workflow.ts +1365 -0
  92. package/src/managed-files/context.ts +240 -0
  93. package/src/managed-files/files.ts +324 -0
  94. package/src/managed-files/generator.test.ts +151 -0
  95. package/src/managed-files/generator.ts +60 -0
  96. package/src/managed-files/github-host-cache-isolation.test.ts +60 -0
  97. package/src/managed-files/github-runs-on.ts +51 -0
  98. package/src/managed-files/managed-content.test.ts +147 -0
  99. package/src/managed-files/managed-content.ts +121 -0
  100. package/src/managed-files/managed-format.ts +102 -0
  101. package/src/managed-files/paths.ts +44 -0
  102. package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
  103. package/src/managed-files/private-npm-policy.ts +62 -0
  104. package/src/managed-files/publish-workflow.ts +1523 -0
  105. package/src/managed-files/schema.json +8 -0
  106. package/src/managed-files/tree-permissions.test.ts +109 -0
  107. package/src/managed-files/tree.test.ts +123 -0
  108. package/src/managed-files/tree.ts +118 -0
  109. package/src/platform-targets.ts +4 -0
  110. package/src/typecheck-test-policy.test.ts +28 -3
  111. package/src/typecheck-test-policy.ts +46 -121
  112. package/src/workspace-config-policy.test.ts +14 -2
  113. package/src/workspace-config-policy.ts +9 -3
  114. package/src/workspace-manifest.ts +327 -0
  115. package/src/workspace-package-policy.ts +32 -0
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+ # Restore the index for the paths the commit just wrote.
3
+ #
4
+ # `git commit --only -- <paths>` — the form used whenever paths are named, and
5
+ # the one a shared worktree requires so a commit cannot sweep in a peer's
6
+ # staged work — is a PARTIAL commit, and git builds it from two different index
7
+ # files. It stages the worktree content of the named paths into the real index,
8
+ # locks it, and then hands the pre-commit hook a separate throwaway index which
9
+ # is what becomes the commit. So when the pre-commit formatter rewrites
10
+ # content, the rewrite reaches the commit and the worktree file, while the real
11
+ # index keeps the pre-format blob: an entry that matches neither HEAD nor the
12
+ # file on disk. `git diff HEAD` is then empty while `git diff --cached HEAD` is
13
+ # not, `git status` reports a path as staged immediately after committing it,
14
+ # and the next bare `git commit` sweeps that ghost in under another message.
15
+ #
16
+ # The formatter cannot repair this from pre-commit. While a pre-commit hook
17
+ # runs, the real index is locked — .git/index.lock exists and git renames it
18
+ # into place after the commit — so no hook can write it. Measured, not assumed:
19
+ # `git add` there fails with "Unable to create .git/index.lock: File exists",
20
+ # and formatting the worktree instead of the index only makes it worse, because
21
+ # the throwaway index was snapshotted before the hook started and would carry
22
+ # unformatted bytes into the commit. post-commit is the first point where the
23
+ # lock is gone; git even points GIT_INDEX_FILE at the real index for it.
24
+ #
25
+ # The repair is an invariant, not a heuristic: for every path this commit wrote,
26
+ # the index must equal the commit. Restricting it to those paths is what makes
27
+ # it safe in a shared worktree. A peer's staged work on any other path is never
28
+ # considered, and for the committed paths git itself already replaced the index
29
+ # entry with the worktree snapshot, so no staged intent is left there to lose.
30
+ # The one race is a peer running `git add` on a path this commit wrote in the
31
+ # moment between git unlocking the index and this hook running; it costs them a
32
+ # repeated `git add`, never file content, which is never touched here.
33
+ #
34
+ # That restriction has one measured edge: if the formatter reduces a staged
35
+ # change to what HEAD already holds, the commit writes no path at all, so the
36
+ # pre-format entry stays until the next commit that does write that path. The
37
+ # alternative — repairing any entry that matches neither HEAD nor the file on
38
+ # disk — is refused on purpose: that is also the shape of `git add -p` staging
39
+ # and of a deliberate `git rm --cached`, and no formatter ghost is worth
40
+ # deleting either of those.
41
+ #
42
+ # Needs nothing but git, so it does not enter the devenv profile.
43
+
44
+ cd "$(git rev-parse --show-toplevel)"
45
+
46
+ set -e -o pipefail
47
+
48
+ paths="$(mktemp)"
49
+ trap 'rm -f "$paths"' EXIT
50
+
51
+ # The paths this commit wrote, NUL-delimited so no path can be misread. A merge
52
+ # commit prints nothing (no single-parent diff), which is right: git refuses a
53
+ # partial commit during a merge, so there is nothing to repair. --root makes an
54
+ # initial commit list its paths instead of none.
55
+ git diff-tree -r -z --no-commit-id --name-only --root HEAD >"$paths"
56
+ [ -s "$paths" ] || exit 0
57
+
58
+ # Report before repairing, and only when there is something to report: a
59
+ # silently mutated index is the thing this hook exists to stop.
60
+ stale="$(xargs -0 git diff --cached --name-only HEAD -- <"$paths")"
61
+ [ -n "$stale" ] || exit 0
62
+
63
+ {
64
+ echo "post-commit: index entries do not match the commit just made; restoring them from HEAD:"
65
+ echo "$stale" | sed 's/^/ /'
66
+ } >&2
67
+
68
+ # Reset the whole committed set, not just the entries named above: it is one
69
+ # index write either way, and for exactly those paths HEAD is by definition
70
+ # what the index should hold. This never touches the working tree.
71
+ git reset -q --pathspec-from-file="$paths" --pathspec-file-nul
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ cd "$(git rev-parse --show-toplevel)"
3
+ TOOLING="$PWD/tooling"
4
+
5
+ export PATH="$("$TOOLING/direnv/repo-path")"
6
+
7
+ set -e -o pipefail
8
+
9
+ # Format the index git handed this hook, which is what the commit will contain:
10
+ # the staged content for a plain `git commit`, and a snapshot of the working
11
+ # tree copies of the named paths for `git commit --only -- <paths>`. It rewrites
12
+ # that index and the working tree file, and post-commit then drops the
13
+ # pre-format entry a partial commit strands in the real index.
14
+ git-format-staged
15
+
16
+ # Adding a workspace package is rare and easy to leave half-wired. Run the
17
+ # full monorepo validator only for newly staged package manifests.
18
+ smoo monorepo validate --fail-fast --only-if-new-workspace-package
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+ # macOS-only Linux cross-compile gate. This hook is a cache PROBE and nothing
3
+ # else: it reads the nx cache and never compiles. A hit means a real
4
+ # `cargo clippy --target x86_64-unknown-linux-gnu` already passed for exactly
5
+ # this tree, so the push is safe with no toolchain present. Anything else
6
+ # refuses the push and names the one command that fixes it.
7
+ #
8
+ # Why probe-only. The cross-clippy needs the linux-cross C toolchain, which
9
+ # lives in a devenv profile. A hook that entered that profile spent minutes
10
+ # compiling on a push the user expected to take a second, and it did so in an
11
+ # environment they never asked for. Pushing is not the place to discover that
12
+ # the tree has not been compiled for Linux; `bun run check:linux` is.
13
+ #
14
+ # CC_x86_64_unknown_linux_gnu is unset for the probe deliberately. The target's
15
+ # own guard reads it to decide whether the toolchain is present, so leaving it
16
+ # set would let a push made from inside an already-entered linux-cross shell
17
+ # fall through into a real multi-minute compile. It is not a declared input of
18
+ # the target, so unsetting it cannot change the task hash — a warm entry still
19
+ # hits.
20
+ #
21
+ # Everything in tooling depends only on devenv.nix packages, so this hook also
22
+ # works with no devenv on PATH. It must never pretend a check ran that did not.
23
+
24
+ cd "$(git rev-parse --show-toplevel)"
25
+ TOOLING="$PWD/tooling"
26
+
27
+ export PATH="$("$TOOLING/direnv/repo-path")"
28
+
29
+ case "$(uname -s)" in
30
+ Darwin) ;;
31
+ *) exit 0 ;;
32
+ esac
33
+
34
+ if env -u CC_x86_64_unknown_linux_gnu nx run-many -t cargo-lint-cross --output-style=static; then
35
+ exit 0
36
+ fi
37
+
38
+ cat >&2 <<'EOF'
39
+
40
+ pre-push: the Linux cross-compile check is NOT cached for this tree, so this
41
+ push would ship code that has never been compiled for Linux. This hook only
42
+ reads the cache; it does not build. The "needs the linux-cross C toolchain"
43
+ line above is the probe refusing to compile, not a broken toolchain.
44
+
45
+ Run: bun run check:linux
46
+ Wait for it to pass, then push again.
47
+ EOF
48
+ exit 1
@@ -0,0 +1,28 @@
1
+ {
2
+ // The managed raw scripts are their own TypeScript project, and must be:
3
+ // they run as plain Bun source during bootstrap — before any workspace
4
+ // package, before node_modules, before the Typia transform — so they can
5
+ // belong to no project that assumes those. This file is what says so.
6
+ //
7
+ // It is also load-bearing at runtime. Bun's ttsc loader (see
8
+ // packages/validation/src/bun/preload.ts) routes each file to the nearest
9
+ // `tsconfig.lib.json` above it; without this one, a raw script under
10
+ // managed/ routed to packages/cli/tsconfig.lib.json, whose `include` is
11
+ // `src/**/*.ts`, and the transform returned no output at all. `smoo secrets
12
+ // run` imports secret-references.ts from here, and a consuming repo does
13
+ // the same from inside node_modules, so this file ships with the package.
14
+ "compilerOptions": {
15
+ "target": "ESNext",
16
+ "lib": ["ESNext"],
17
+ "module": "Preserve",
18
+ "moduleResolution": "bundler",
19
+ "allowImportingTsExtensions": true,
20
+ "verbatimModuleSyntax": true,
21
+ "noEmit": true,
22
+ "strict": true,
23
+ "noUncheckedIndexedAccess": false,
24
+ "skipLibCheck": true,
25
+ "types": ["bun"]
26
+ },
27
+ "include": ["**/*.ts"]
28
+ }
@@ -0,0 +1,45 @@
1
+ name: Cache devenv and direnv
2
+ description: >
3
+ The small devenv cache (.devenv/.direnv — eval SQLite, shell scripts, profile), restored and saved on every runner.
4
+ The Nix store has its own cache in setup-devenv.
5
+
6
+ inputs:
7
+ mode:
8
+ description: Restore or save the Nix/devenv cache.
9
+ required: false
10
+ default: restore
11
+
12
+ outputs:
13
+ cache-hit:
14
+ description: Whether the restore step found an exact primary-key match.
15
+ value: ${{ steps.restore-devenv.outputs.cache-hit == 'true' }}
16
+
17
+ runs:
18
+ using: composite
19
+ steps:
20
+ - name: Restore devenv and direnv state
21
+ id: restore-devenv
22
+ if: inputs.mode == 'restore'
23
+ uses: actions/cache/restore@v5.0.5
24
+ with:
25
+ path: |
26
+ ${{ github.workspace }}/tooling/direnv/.devenv
27
+ ${{ github.workspace }}/tooling/direnv/.direnv
28
+ key:
29
+ ${{ runner.os }}-${{ runner.arch }}-devenv-v3-${{ hashFiles('tooling/direnv/devenv.yaml',
30
+ 'tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/devenv.lock',
31
+ 'tooling/direnv/envrc.sh', 'tooling/direnv/setup-environment.ts') }}
32
+ restore-keys: |
33
+ ${{ runner.os }}-${{ runner.arch }}-devenv-v3-
34
+
35
+ - name: Save devenv and direnv state
36
+ if: inputs.mode == 'save'
37
+ uses: actions/cache/save@v5.0.5
38
+ with:
39
+ path: |
40
+ ${{ github.workspace }}/tooling/direnv/.devenv
41
+ ${{ github.workspace }}/tooling/direnv/.direnv
42
+ key:
43
+ ${{ runner.os }}-${{ runner.arch }}-devenv-v3-${{ hashFiles('tooling/direnv/devenv.yaml',
44
+ 'tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/devenv.lock',
45
+ 'tooling/direnv/envrc.sh', 'tooling/direnv/setup-environment.ts') }}
@@ -0,0 +1,17 @@
1
+ name: Cache node_modules
2
+ description: Restore cached Bun workspace dependencies.
3
+
4
+ runs:
5
+ using: composite
6
+ steps:
7
+ - name: Cache node_modules
8
+ uses: actions/cache@v5.0.5
9
+ with:
10
+ # Dependencies only. ttsc plugin/GOCACHE live under $TTSC_CACHE_DIR
11
+ # (.cache/ttsc), not inside node_modules.
12
+ # v2 isolates restore-keys from older Darwin caches with a broken TS dual-package hoist.
13
+ path: node_modules
14
+ # prettier-ignore
15
+ key: ${{ runner.os }}-${{ runner.arch }}-node-v2-{{NODE_MODULES_CACHE_KEY}}
16
+ restore-keys: |
17
+ ${{ runner.os }}-${{ runner.arch }}-node-v2-
@@ -0,0 +1,21 @@
1
+ name: Restore Nx cache
2
+ description: Restore cached Nx task outputs without publishing new cache entries.
3
+
4
+ outputs:
5
+ cache-hit:
6
+ description: Whether an exact Nx cache key was restored.
7
+ value: ${{ steps.restore.outputs.cache-hit }}
8
+
9
+ runs:
10
+ using: composite
11
+ steps:
12
+ - name: Restore Nx cache
13
+ id: restore
14
+ uses: actions/cache/restore@v5.0.5
15
+ with:
16
+ path: |
17
+ .nx/cache
18
+ .nx/workspace-data/*.db*
19
+ key: ${{ runner.os }}-${{ runner.arch }}-nx-db-v1-${{ github.sha }}
20
+ restore-keys: |
21
+ ${{ runner.os }}-${{ runner.arch }}-nx-db-v1-
@@ -0,0 +1,19 @@
1
+ name: Cache ttsc plugins
2
+ description: >
3
+ Restore/save compiled ttsc native plugin binaries (typia, etc.). These are content-keyed under TTSC_CACHE_DIR/plugins
4
+ and skip the multi-minute `go build` when the cache key matches. The Go object cache (go-build/) is NOT cached — it is
5
+ multi-GB and only helps when the plugin key misses.
6
+
7
+ runs:
8
+ using: composite
9
+ steps:
10
+ - name: Cache ttsc plugin binaries
11
+ uses: actions/cache@v5.0.5
12
+ with:
13
+ # Only the compiled plugin binaries (~30MB each). Path is relative to the
14
+ # workspace; devenv sets TTSC_CACHE_DIR to <repo>/.cache/ttsc.
15
+ path: .cache/ttsc/plugins
16
+ # prettier-ignore
17
+ key: ${{ runner.os }}-${{ runner.arch }}-ttsc-plugins-v1-${{ hashFiles('bun.lock', 'package.json', 'patches/ttsc@*.patch', 'tooling/direnv/devenv.lock') }}
18
+ restore-keys: |
19
+ ${{ runner.os }}-${{ runner.arch }}-ttsc-plugins-v1-
@@ -0,0 +1,32 @@
1
+ name: Save Nix/devenv caches
2
+ description: >
3
+ Save the devenv/direnv eval-cache segment after the job, on every ephemeral runner where setup missed and build-shell
4
+ produced nix-eval-cache.db. The Nix store cache saves itself in setup-devenv's post phase (ephemeral runners only).
5
+
6
+ inputs:
7
+ devenv-cache-hit:
8
+ description: Exact-hit output from setup-devenv's devenv cache restore.
9
+ required: false
10
+ default: 'false'
11
+
12
+ runs:
13
+ using: composite
14
+ steps:
15
+ - name: 🔎 Devenv save ready
16
+ id: devenv-save
17
+ if: inputs.devenv-cache-hit != 'true'
18
+ shell: bash
19
+ run: |
20
+ db="${GITHUB_WORKSPACE}/tooling/direnv/.devenv/nix-eval-cache.db"
21
+ if [[ -f "$db" ]]; then
22
+ echo "ready=true" >> "$GITHUB_OUTPUT"
23
+ else
24
+ echo "ready=false" >> "$GITHUB_OUTPUT"
25
+ echo "skip devenv save: no nix-eval-cache.db"
26
+ fi
27
+
28
+ - name: 🧊 Save devenv and direnv
29
+ if: ${{ inputs.devenv-cache-hit != 'true' && steps.devenv-save.outputs.ready == 'true' }}
30
+ uses: ./.github/actions/cache-nix-devenv
31
+ with:
32
+ mode: save
@@ -0,0 +1,245 @@
1
+ name: Setup Nix/devenv
2
+ description: >
3
+ Build the SmoothBricks devenv shell after checkout. Restores the small devenv/direnv actions/cache segment on every
4
+ runner (eval SQLite + shell scripts). On host-nix runners (NIX_REMOTE=daemon + /var/cache/ci) skips Nix install and
5
+ the store cache (host store). On ephemeral runners installs a single-user Nix and restores /nix itself from the
6
+ actions cache: store paths and the Nix database come back as files, so no NAR is imported and no daemon is needed.
7
+
8
+ outputs:
9
+ devenv-cache-hit:
10
+ description: Whether the devenv/direnv cache restored from the exact primary key.
11
+ value: ${{ steps.runner-kind.outputs.host == 'true' || steps.devenv-cache.outputs.cache-hit || 'false' }}
12
+ host-runner:
13
+ description: Whether this job is on a host-nix runner with shared store/caches.
14
+ value: ${{ steps.runner-kind.outputs.host }}
15
+
16
+ runs:
17
+ using: composite
18
+ steps:
19
+ # This action is intentionally post-checkout only. Repo-local actions do not
20
+ # exist before actions/checkout has populated the working tree.
21
+
22
+ # Runner image/profile owns paths (NIX_REMOTE, /var/cache/ci/*). Detect here
23
+ # so every workflow can `uses: setup-devenv` without forking step graphs.
24
+ - name: 🔎 Runner kind
25
+ id: runner-kind
26
+ shell: bash
27
+ run: |
28
+ if [ "${NIX_REMOTE:-}" = daemon ] && [ -d /var/cache/ci ]; then
29
+ echo "host=true" >> "$GITHUB_OUTPUT"
30
+ echo "host-nix runner (shared store + /var/cache/ci)"
31
+ else
32
+ echo "host=false" >> "$GITHUB_OUTPUT"
33
+ echo "ephemeral runner (install Nix + GH caches)"
34
+ fi
35
+
36
+ # Nx names its cache metadata DB after the machine identity
37
+ # (.nx/workspace-data/<machine-id>-v3.db) and refuses artifacts written by a
38
+ # different machine. Each Linux runner instance is a fresh clone that
39
+ # generates its own id on first boot, so a restored DB is never the file Nx
40
+ # opens: measured, every artifact came back unrecognized and the transfer
41
+ # was wasted. GitHub's hosted images ship one baked id, which is why the
42
+ # same wiring works there.
43
+ #
44
+ # Pin the id on Linux, then keep the cache on the shared mutable bind
45
+ # instead of shipping it through the Actions cache. One host is then one
46
+ # cache with one identity, which is the only arrangement Nx trusts.
47
+ # Artifacts AND metadata must move together: the DB alone is where "Nx
48
+ # recognizes this" lives. Darwin has a stable native identity and no
49
+ # /etc/machine-id, so it skips the pin (and the sudo) entirely — the
50
+ # Linux-only gate below is on runner.os, not on host detection, because
51
+ # Darwin host jobs take the same host branch.
52
+ #
53
+ # /etc/machine-id is a plain writable file on the Linux hosts, not a mount
54
+ # point. The durable home for this is the runner image; doing it per job
55
+ # keeps the fix in one managed place until then.
56
+ - name: 🧠 Pin the machine id (Linux hosts only)
57
+ if: steps.runner-kind.outputs.host == 'true' && runner.os == 'Linux'
58
+ shell: bash
59
+ env:
60
+ # Any valid 32-char lowercase hex; only its stability across instances
61
+ # matters. Shared fleet-wide on purpose — see the cache trust model in
62
+ # the CI workflow's save step.
63
+ FLEET_MACHINE_ID: 5cbb1f9a4d2e4f0f8b6a3c7d9e150246
64
+ run: |
65
+ printf '%s\n' "$FLEET_MACHINE_ID" | sudo tee /etc/machine-id >/dev/null
66
+ echo "machine id : $(cat /etc/machine-id)"
67
+
68
+ # Nx cache location on the shared bind: common to every host runner.
69
+ # Scoped per workflow, and it has to be. workspace-data is not a cache:
70
+ # it holds project-graph.json, file-map.json and nx_files for ONE
71
+ # checkout. It cannot be split from the artifacts either -- Nx rejects
72
+ # cache artifacts it has no DB row for ("Unrecognized Cache Artifacts"),
73
+ # and that DB lives in workspace-data. Since CI and Publish sit in
74
+ # different concurrency groups they run simultaneously on one host, so a
75
+ # repository-wide tree let one workflow rewrite the other's graph state
76
+ # mid-read. CI concurrency is per workflow/ref, not workflow alone:
77
+ # separate PRs and jobs must never share mutable graph or eval state.
78
+ # Hash the exact identity (not a lossy path slug); keep cache artifacts
79
+ # and their metadata DB together, warm across runs of the same ref/job.
80
+ - name: 📂 Locate the Nx cache on the shared bind
81
+ if: steps.runner-kind.outputs.host == 'true'
82
+ shell: bash
83
+ env:
84
+ NX_CACHE_REPO: ${{ github.repository }}
85
+ NX_CACHE_LANE: ${{ github.workflow }}
86
+ run: |
87
+ lane=$(printf '%s' "$NX_CACHE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
88
+ scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$GITHUB_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
89
+ NX_CACHE_ROOT="/var/cache/ci/nx/$NX_CACHE_REPO/${lane:-default}/$scope"
90
+ mkdir -p "$NX_CACHE_ROOT/cache" "$NX_CACHE_ROOT/workspace-data"
91
+ {
92
+ echo "NX_CACHE_DIRECTORY=$NX_CACHE_ROOT/cache"
93
+ echo "NX_WORKSPACE_DATA_DIRECTORY=$NX_CACHE_ROOT/workspace-data"
94
+ # Nx's own eviction. It drops artifacts and their DB rows together, so
95
+ # never age this tree out with tmpfiles: deleting artifacts alone is a
96
+ # silent miss, but deleting the DB orphans every artifact.
97
+ echo "NX_MAX_CACHE_SIZE=20GB"
98
+ } >> "$GITHUB_ENV"
99
+ echo "nx cache : $NX_CACHE_ROOT"
100
+
101
+ # Host runners keep devenv's state on the shared bind, next to the Nx cache:
102
+ # .devenv (eval SQLite, gc roots, profile) and .direnv survive the job, so
103
+ # the next job on this host evaluates nothing and downloads nothing. The
104
+ # Actions cache segment below is the ephemeral runners' substitute for this.
105
+ # Scoped per workflow/ref/job/platform like Nx: separate PR runs and
106
+ # jobs can overlap, and one eval-cache.db must have only one writer.
107
+ #
108
+ # The eval cache keys on canonical absolute paths, and act's host executor
109
+ # checks out under <cache>/<random 8 chars>/hostexecutor - a new path every
110
+ # job by design (act/runner/run_context.go: MustRandName), so a restored
111
+ # cache could never match. The workspace is therefore bind-mounted at a
112
+ # stable path (a symlink would not do: Nix canonicalises) and devenv is
113
+ # evaluated from there; every later step still runs in the checkout, which
114
+ # is the same tree. DEVENV_WORKDIR names the path the devenv steps use.
115
+ # The mount target is the instance's own /work, not the shared bind: only
116
+ # the path's spelling must be stable, and a bind onto the idmapped cache
117
+ # dataset failed inside the job (move_mount: ENOENT) where a container-fs
118
+ # target does not. If the mount is refused the job goes on from the
119
+ # checkout and pays the evaluation: this is an optimisation, never a gate.
120
+ - name: 📂 Locate devenv state on the shared bind
121
+ if: steps.runner-kind.outputs.host == 'true'
122
+ shell: bash
123
+ env:
124
+ DEVENV_STATE_REPO: ${{ github.repository }}
125
+ DEVENV_STATE_LANE: ${{ github.workflow }}
126
+ DEVENV_STATE_JOB: ${{ github.job }}
127
+ run: |
128
+ lane=$(printf '%s' "$DEVENV_STATE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
129
+ scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$GITHUB_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
130
+ root="/var/cache/ci/devenv/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
131
+ mkdir -p "$root/.devenv" "$root/.direnv"
132
+ rm -rf tooling/direnv/.devenv tooling/direnv/.direnv
133
+ ln -s "$root/.devenv" tooling/direnv/.devenv
134
+ ln -s "$root/.direnv" tooling/direnv/.direnv
135
+ stable="/work/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
136
+ if mkdir -p "$stable" && sudo mount --bind "$GITHUB_WORKSPACE" "$stable"; then
137
+ echo "DEVENV_WORKDIR=$stable" >> "$GITHUB_ENV"
138
+ echo "devenv state: $root (workspace bind-mounted at $stable)"
139
+ else
140
+ echo "DEVENV_WORKDIR=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
141
+ echo "::warning::stable devenv path unavailable (bind mount refused); evaluating from the checkout"
142
+ echo "devenv state: $root (workspace at $GITHUB_WORKSPACE)"
143
+ fi
144
+
145
+ - name: 📂 Devenv runs in the checkout
146
+ if: steps.runner-kind.outputs.host != 'true'
147
+ shell: bash
148
+ run: echo "DEVENV_WORKDIR=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
149
+
150
+ # Devenv segment (own key): tooling/direnv/.devenv + .direnv — includes
151
+ # nix-eval-cache.db. Independent of the store cache; restored on ephemeral
152
+ # runners whether or not the store cache hit. Missing store paths are fine:
153
+ # devenv verifies shell drv/out exist on eval-cache hit and invalidates +
154
+ # re-evals / realizes when GC removed them. Packages still come from host
155
+ # store, the store cache, or Cachix — this blob only skips evaluation.
156
+ - name: 🧊 Cache devenv and direnv
157
+ id: devenv-cache
158
+ if: steps.runner-kind.outputs.host != 'true'
159
+ uses: ./.github/actions/cache-nix-devenv
160
+
161
+ # Single-user Nix unpacked into /nix in seconds: no installer volume, no
162
+ # daemon, no sudo. keep-outputs/keep-derivations make the garbage collection
163
+ # before a cache save keep the shell's derivations, so a restored eval cache
164
+ # still finds them.
165
+ - name: ❄️ Install Nix
166
+ if: steps.runner-kind.outputs.host != 'true'
167
+ uses: nixbuild/nix-quick-install-action@v35
168
+ with:
169
+ nix_conf: |
170
+ keep-outputs = true
171
+ keep-derivations = true
172
+ keep-env-derivations = true
173
+
174
+ # The store itself, restored as files: /nix/store plus the Nix database,
175
+ # merged into the fresh install. The post phase collects garbage down to the
176
+ # live closure and saves when the primary key missed.
177
+ #
178
+ # CONTENT ONLY — never the Nix profiles. `~/.nix-profile` and
179
+ # ~/.local/state/nix/profiles are mutable places whose whole job is to be
180
+ # gcroots, and restoring a previous run's copies over a freshly installed
181
+ # single-user Nix de-roots the Nix binary that is currently running. The post
182
+ # phase then garbage-collects it and cache-nix-action's own `nix --version`
183
+ # probe fails, at which point it skips the upload and still reports the step
184
+ # as a success — so the store cache silently stops being written and every
185
+ # later run pays a cold shell. Measured exactly that way: run 34371205556
186
+ # logged `nix (Nix) 2.34.7`, freed 2.7 GiB, then `nix: command not found`,
187
+ # and no `Cache saved` line for this key ever appeared.
188
+ #
189
+ # It only surfaced now because it needs a restore-prefix fallback rather than
190
+ # a cold store or an exact hit: a matching key restores profiles consistent
191
+ # with the store, while the diet rotated the key and pulled the previous
192
+ # store's profiles onto a different Nix.
193
+ #
194
+ # Dropping them costs nothing and buys determinism. devenv's closure still
195
+ # arrives inside /nix, so install-devenv's `nix profile add` of the locked
196
+ # rev is a link rather than a download, and the devenv in play is the one
197
+ # devenv.lock names instead of whichever run last populated the prefix.
198
+ - name: 🧊 Cache Nix store
199
+ id: nix-cache
200
+ if: steps.runner-kind.outputs.host != 'true'
201
+ uses: nix-community/cache-nix-action@v7
202
+ with:
203
+ paths: |
204
+ /nix
205
+ ~/.cache/nix
206
+ # prettier-ignore
207
+ primary-key: ${{ runner.os }}-${{ runner.arch }}-nix-v6-${{ hashFiles('tooling/direnv/devenv.yaml', 'tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/devenv.lock') }}
208
+ restore-prefixes-first-match: ${{ runner.os }}-${{ runner.arch }}-nix-v6-
209
+ gc-max-store-size: 1G
210
+
211
+ - name: ⚡ Enable Cachix
212
+ if: steps.runner-kind.outputs.host != 'true'
213
+ uses: cachix/cachix-action@v17
214
+ with:
215
+ name: devenv
216
+
217
+ # A host runner's devenv belongs to its image, so install-devenv accepts
218
+ # whatever is on PATH there. On an ephemeral runner the devenv came out of a
219
+ # cache this workflow wrote, so it is held to devenv.lock's rev: the store
220
+ # cache restores ~/.nix-profile wholesale and a prefix match hands the job
221
+ # the CLI of whichever run last populated the key, which outlived a lock bump
222
+ # until the check existed.
223
+ - name: 🧰 Install devenv
224
+ shell: bash
225
+ working-directory: ${{ env.DEVENV_WORKDIR }}/tooling/direnv
226
+ env:
227
+ SMOO_HOST_RUNNER: ${{ steps.runner-kind.outputs.host }}
228
+ run: ./github-actions-bootstrap.sh install-devenv
229
+
230
+ # node_modules + ttsc plugin binaries: GH Actions cache on ephemeral runners.
231
+ # Host runners keep those under the /var/cache/ci bind (bun / ttsc env).
232
+ - name: 📦 Cache node_modules
233
+ if: steps.runner-kind.outputs.host != 'true'
234
+ uses: ./.github/actions/cache-node-modules
235
+
236
+ - name: 🧊 Cache ttsc plugins
237
+ if: steps.runner-kind.outputs.host != 'true'
238
+ uses: ./.github/actions/cache-ttsc-plugins
239
+
240
+ - name: 🐚 Build devenv shell
241
+ shell: bash
242
+ working-directory: ${{ env.DEVENV_WORKDIR }}/tooling/direnv
243
+ env:
244
+ SMOO_ROOT_BUILD_INPUTS: ${{ steps.runner-kind.outputs.host != 'true' }}
245
+ run: ./github-actions-bootstrap.sh build-shell