@smoothbricks/nx-plugin 0.4.16 → 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.
@@ -73,8 +73,10 @@ runs:
73
73
  # and that DB lives in workspace-data. Since CI and Publish sit in
74
74
  # different concurrency groups they run simultaneously on one host, so a
75
75
  # repository-wide tree let one workflow rewrite the other's graph state
76
- # mid-read; that is what failed a release with a bare non-zero
77
- # `nx show project`. Per lane they stay warm and never overlap.
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.
78
80
  - name: 📂 Locate the Nx cache on the shared bind
79
81
  if: steps.runner-kind.outputs.host == 'true'
80
82
  shell: bash
@@ -83,7 +85,8 @@ runs:
83
85
  NX_CACHE_LANE: ${{ github.workflow }}
84
86
  run: |
85
87
  lane=$(printf '%s' "$NX_CACHE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
86
- NX_CACHE_ROOT="/var/cache/ci/nx/$NX_CACHE_REPO/${lane:-default}"
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"
87
90
  mkdir -p "$NX_CACHE_ROOT/cache" "$NX_CACHE_ROOT/workspace-data"
88
91
  {
89
92
  echo "NX_CACHE_DIRECTORY=$NX_CACHE_ROOT/cache"
@@ -99,8 +102,8 @@ runs:
99
102
  # .devenv (eval SQLite, gc roots, profile) and .direnv survive the job, so
100
103
  # the next job on this host evaluates nothing and downloads nothing. The
101
104
  # Actions cache segment below is the ephemeral runners' substitute for this.
102
- # Scoped per job as well as lane: two jobs of one run are parallel, and one
103
- # eval-cache.db has one writer.
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.
104
107
  #
105
108
  # The eval cache keys on canonical absolute paths, and act's host executor
106
109
  # checks out under <cache>/<random 8 chars>/hostexecutor - a new path every
@@ -123,12 +126,13 @@ runs:
123
126
  DEVENV_STATE_JOB: ${{ github.job }}
124
127
  run: |
125
128
  lane=$(printf '%s' "$DEVENV_STATE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
126
- root="/var/cache/ci/devenv/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB"
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"
127
131
  mkdir -p "$root/.devenv" "$root/.direnv"
128
132
  rm -rf tooling/direnv/.devenv tooling/direnv/.direnv
129
133
  ln -s "$root/.devenv" tooling/direnv/.devenv
130
134
  ln -s "$root/.direnv" tooling/direnv/.direnv
131
- stable="/work/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB"
135
+ stable="/work/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
132
136
  if mkdir -p "$stable" && sudo mount --bind "$GITHUB_WORKSPACE" "$stable"; then
133
137
  echo "DEVENV_WORKDIR=$stable" >> "$GITHUB_ENV"
134
138
  echo "devenv state: $root (workspace bind-mounted at $stable)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.16",
3
+ "version": "0.4.17",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -0,0 +1,60 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ const action = readFileSync(
5
+ new URL('../../managed/templates/github/actions/setup-devenv/action.yml', import.meta.url),
6
+ 'utf8',
7
+ );
8
+ const assignments = action.split('\n').filter((line) => line.trimStart().startsWith('scope=$('));
9
+
10
+ function scope(overrides: Record<string, string> = {}): string {
11
+ const assignment = assignments[0];
12
+ if (!assignment) throw new Error('The setup action must scope its mutable host caches');
13
+ const result = Bun.spawnSync(['bash', '-ceu', `${assignment}\nprintf '%s' "$scope"`], {
14
+ env: {
15
+ ...process.env,
16
+ GITHUB_WORKFLOW: 'CI',
17
+ GITHUB_REF: 'refs/pull/10/merge',
18
+ GITHUB_JOB: 'main',
19
+ RUNNER_OS: 'Linux',
20
+ RUNNER_ARCH: 'X64',
21
+ ...overrides,
22
+ },
23
+ });
24
+ expect(result.exitCode).toBe(0);
25
+ return result.stdout.toString();
26
+ }
27
+
28
+ describe('host CI mutable cache isolation', () => {
29
+ test('Nx and devenv use the same exact workflow/ref/job/platform identity', () => {
30
+ expect(assignments).toHaveLength(2);
31
+ expect(assignments[0]).toBe(assignments[1]);
32
+ expect(action).toContain('/${lane:-default}/$scope');
33
+ expect(action).toContain('/${lane:-default}/$DEVENV_STATE_JOB/$scope');
34
+ expect(action).toContain('NX_CACHE_DIRECTORY=$NX_CACHE_ROOT/cache');
35
+ expect(action).toContain('NX_WORKSPACE_DATA_DIRECTORY=$NX_CACHE_ROOT/workspace-data');
36
+ });
37
+
38
+ test('repeat runs stay warm but distinct PRs, jobs and platforms cannot share graph state', () => {
39
+ const original = scope();
40
+ expect(original).toMatch(/^[a-f0-9]{40}$/);
41
+ expect(scope({ GITHUB_RUN_ID: 'another-run', GITHUB_RUN_ATTEMPT: '2' })).toBe(original);
42
+ const identities: Record<string, string>[] = [
43
+ { GITHUB_WORKFLOW: 'Publish' },
44
+ { GITHUB_REF: 'refs/pull/11/merge' },
45
+ { GITHUB_REF: 'refs/heads/main' },
46
+ { GITHUB_JOB: 'e2e-deployment' },
47
+ { RUNNER_OS: 'macOS' },
48
+ { RUNNER_ARCH: 'ARM64' },
49
+ ];
50
+ for (const other of identities) {
51
+ expect(scope(other)).not.toBe(original);
52
+ }
53
+ });
54
+
55
+ test('similar-looking refs do not collide or become filesystem paths', () => {
56
+ expect(scope({ GITHUB_REF: 'refs/heads/feature/a' })).not.toBe(scope({ GITHUB_REF: 'refs/heads/feature-a' }));
57
+ expect(scope({ GITHUB_REF: 'refs/heads/Feature' })).not.toBe(scope({ GITHUB_REF: 'refs/heads/feature' }));
58
+ expect(scope({ GITHUB_REF: 'refs/heads/../../other' })).toMatch(/^[a-f0-9]{40}$/);
59
+ });
60
+ });