@smoothbricks/nx-plugin 0.4.19 → 0.4.21
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.
- package/README.md +68 -18
- package/dist/bin/smoo-nx-cargo-hash.js +5 -3
- package/dist/cargo-source-hash.d.ts +3 -11
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +25 -14
- package/dist/cargo-workspace.d.ts +0 -1
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +9 -2
- package/dist/ensure-built.d.ts +6 -5
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +227 -30
- package/dist/index.js +18 -10
- package/dist/managed-files/ci-workflow.d.ts +20 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +42 -13
- package/dist/managed-files/files.d.ts +1 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +8 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +37 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +34 -6
- package/dist/workspace-manifest.d.ts +3 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +23 -91
- package/managed/raw/tooling/git-hooks/commit-msg.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-commit.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +6 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +19 -7
- package/package.json +1 -1
- package/src/bin/smoo-nx-cargo-hash.ts +7 -3
- package/src/cargo-source-hash.test.ts +237 -1
- package/src/cargo-source-hash.ts +32 -16
- package/src/cargo-workspace.test.ts +17 -10
- package/src/cargo-workspace.ts +9 -3
- package/src/ensure-built.test.ts +87 -29
- package/src/ensure-built.ts +274 -29
- package/src/index.test.ts +117 -20
- package/src/index.ts +18 -11
- package/src/managed-files/ci-workflow.ts +45 -14
- package/src/managed-files/files.ts +9 -2
- package/src/managed-files/generator.test.ts +5 -1
- package/src/managed-files/github-host-cache-isolation.test.ts +32 -6
- package/src/managed-files/pr-preview-cleanup-workflow.ts +87 -6
- package/src/workspace-manifest.ts +3 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are emitted literally. */
|
|
2
|
+
import { CI_CONCURRENCY_GROUP, CiWorkflowStepKind, cargoCredentialJobEnvLines, cargoCredentialStepLines, cloudflareCredentialEnvLines, environmentLine, privateNpmReadTokenJobEnv, sourceCheckoutsStepLines, } from './ci-workflow.js';
|
|
2
3
|
import { renderRunsOnLine } from './github-runs-on.js';
|
|
3
4
|
export function renderPrPreviewCleanupWorkflowYaml(options = {}) {
|
|
4
5
|
return `name: PR Preview Cleanup
|
|
@@ -10,29 +11,56 @@ on:
|
|
|
10
11
|
permissions:
|
|
11
12
|
contents: read
|
|
12
13
|
|
|
14
|
+
# The pull request's CI group, named by its number whether the close merged it
|
|
15
|
+
# or not: closing it cancels its running CI run, so the cleanup starts only
|
|
16
|
+
# after that run's stage deploy has stopped.
|
|
17
|
+
concurrency:
|
|
18
|
+
group: ${CI_CONCURRENCY_GROUP}
|
|
19
|
+
cancel-in-progress: true
|
|
20
|
+
|
|
13
21
|
jobs:
|
|
14
22
|
cleanup:
|
|
15
23
|
name: Cleanup PR environment
|
|
16
24
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
17
25
|
${renderRunsOnLine(options.runsOn)}
|
|
18
26
|
timeout-minutes: 15
|
|
19
|
-
defaults:
|
|
27
|
+
${environmentLine(options.environments?.staging)} defaults:
|
|
20
28
|
run:
|
|
21
29
|
working-directory: tooling/direnv
|
|
22
|
-
steps:
|
|
30
|
+
${setupJobEnv(options)} steps:
|
|
23
31
|
- name: Checkout
|
|
24
32
|
uses: actions/checkout@v6.0.2
|
|
25
33
|
with:
|
|
26
34
|
filter: blob:none
|
|
27
35
|
fetch-depth: 1
|
|
28
|
-
|
|
36
|
+
${preflightSteps(options)}
|
|
29
37
|
- name: Setup Nix/devenv
|
|
30
38
|
uses: ./.github/actions/setup-devenv
|
|
31
39
|
|
|
32
40
|
- name: Cleanup PR environment
|
|
33
|
-
|
|
34
|
-
CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
35
|
-
CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
41
|
+
${cloudflareCredentialEnvLines(options.deploySecrets).join('\n')}
|
|
36
42
|
run: smoo wrangler cleanup-pr --pr \${{ github.event.pull_request.number }}
|
|
37
43
|
`;
|
|
38
44
|
}
|
|
45
|
+
/** The job env setup-devenv needs, as the CI jobs spell it; nothing for a repository that declares no credential. */
|
|
46
|
+
function setupJobEnv(options) {
|
|
47
|
+
const tokenLines = `${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)}`;
|
|
48
|
+
return tokenLines === '' ? '' : ` env:\n${tokenLines}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The CI jobs' steps between checkout and setup-devenv, in their order and each
|
|
52
|
+
* set off by blank lines: the Cargo credential step, then the sibling-source
|
|
53
|
+
* clones. Nothing when neither is declared.
|
|
54
|
+
*/
|
|
55
|
+
function preflightSteps(options) {
|
|
56
|
+
const steps = [];
|
|
57
|
+
if (options.cargoCredentials !== undefined) {
|
|
58
|
+
const step = { kind: CiWorkflowStepKind.CargoCredentials, name: 'Prepare Cargo credentials', number: 0 };
|
|
59
|
+
steps.push(cargoCredentialStepLines(step, options.cargoCredentials));
|
|
60
|
+
}
|
|
61
|
+
if (options.sourceCheckouts?.length) {
|
|
62
|
+
const step = { kind: CiWorkflowStepKind.SourceCheckouts, name: 'Check out sibling sources', number: 0 };
|
|
63
|
+
steps.push(sourceCheckoutsStepLines(step, options.sourceCheckouts));
|
|
64
|
+
}
|
|
65
|
+
return steps.map((lines) => `\n${lines.join('\n')}\n`).join('');
|
|
66
|
+
}
|
|
@@ -32,7 +32,7 @@ export interface PackagePublishConfig {
|
|
|
32
32
|
registry?: string;
|
|
33
33
|
}
|
|
34
34
|
export interface PackageSmooGithubEnvironments {
|
|
35
|
-
/** GitHub Environment for the staging deploy and
|
|
35
|
+
/** GitHub Environment for the staging deploy, e2e and PR preview cleanup jobs. */
|
|
36
36
|
staging?: string;
|
|
37
37
|
/** GitHub Environment for the production-on-push deploy job. */
|
|
38
38
|
production?: string;
|
|
@@ -247,6 +247,8 @@ export interface PackageJson {
|
|
|
247
247
|
optionalDependencies?: StringMap;
|
|
248
248
|
/** Bun patchedDependencies map (package@version → patch path). */
|
|
249
249
|
patchedDependencies?: StringMap;
|
|
250
|
+
overrides?: StringMap;
|
|
251
|
+
resolutions?: StringMap;
|
|
250
252
|
engines?: StringMap;
|
|
251
253
|
scripts?: StringMap;
|
|
252
254
|
publishConfig?: PackagePublishConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-manifest.d.ts","sourceRoot":"","sources":["../src/workspace-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C,2DAA2D;AAC3D,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAE3C,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,CAEnE;AAED,mHAAmH;AACnH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAE1D;;;GAGG;AAC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
12
|
} from 'node:fs';
|
|
13
|
-
import { mkdir, rmdir, stat } from 'node:fs/promises';
|
|
14
13
|
import { createRequire } from 'node:module';
|
|
15
14
|
import path from 'node:path';
|
|
16
15
|
import { $ } from 'bun';
|
|
@@ -78,12 +77,6 @@ async function resolveProjectRoot(): Promise<string> {
|
|
|
78
77
|
|
|
79
78
|
const projectRoot = await resolveProjectRoot();
|
|
80
79
|
|
|
81
|
-
// A legitimate concurrent setup finishes well within this; anything older is a
|
|
82
|
-
// leftover from an interrupted run (CTRL-C/kill before the finally-cleanup) and
|
|
83
|
-
// would otherwise wedge every future shell load behind the 120s spin + EEXIST.
|
|
84
|
-
// NOTE: must be declared ABOVE the top-level setup block below — module consts
|
|
85
|
-
// are not hoisted, and the lock loop runs during that block.
|
|
86
|
-
const STALE_LOCK_MS = 10 * 60_000;
|
|
87
80
|
// Unscoped require("typescript") must expose the TS6 compiler API for Nx.
|
|
88
81
|
// @typescript/native installs another package also named "typescript" (TS7). Bun's
|
|
89
82
|
// isolated linker RACES the node_modules/.bun/node_modules/typescript fallback link
|
|
@@ -124,28 +117,24 @@ try {
|
|
|
124
117
|
// and package resolution/Typia transforms are not available yet.
|
|
125
118
|
if (process.env.CI) {
|
|
126
119
|
await resolveSecrets();
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
// skips the finally that releases the lock and strands it, so failures
|
|
132
|
-
// are captured inside and reported outside.
|
|
120
|
+
// Failures are captured and reported below. Exiting in the catch would
|
|
121
|
+
// skip the git-diff diagnostic that follows a frozen-lockfile miss.
|
|
122
|
+
// bun install already races concurrent installs with an atomic cache
|
|
123
|
+
// rename; this script does not add a second mutex around it.
|
|
133
124
|
let frozenError: unknown;
|
|
134
125
|
let fallbackError: unknown;
|
|
135
|
-
|
|
126
|
+
try {
|
|
127
|
+
await runSetupCommand('bun install --frozen-lockfile', $`bun install --frozen-lockfile`, { quiet: false });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
frozenError = error;
|
|
130
|
+
console.error('! Failed to install dependencies with frozen lockfile');
|
|
131
|
+
replayCapturedOutput(error);
|
|
136
132
|
try {
|
|
137
|
-
await runSetupCommand('bun install
|
|
138
|
-
} catch (
|
|
139
|
-
|
|
140
|
-
console.error('! Failed to install dependencies with frozen lockfile');
|
|
141
|
-
replayCapturedOutput(error);
|
|
142
|
-
try {
|
|
143
|
-
await runSetupCommand('bun install', $`bun install`, { quiet: false });
|
|
144
|
-
} catch (fallback) {
|
|
145
|
-
fallbackError = fallback;
|
|
146
|
-
}
|
|
133
|
+
await runSetupCommand('bun install', $`bun install`, { quiet: false });
|
|
134
|
+
} catch (fallback) {
|
|
135
|
+
fallbackError = fallback;
|
|
147
136
|
}
|
|
148
|
-
}
|
|
137
|
+
}
|
|
149
138
|
if (fallbackError !== undefined) {
|
|
150
139
|
reportSetupFailure(fallbackError);
|
|
151
140
|
}
|
|
@@ -214,19 +203,15 @@ async function installLocalDependencies(): Promise<unknown> {
|
|
|
214
203
|
} catch (error) {
|
|
215
204
|
return error;
|
|
216
205
|
}
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
installError = error;
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
return installError;
|
|
206
|
+
// Returned, not thrown: the caller still wires git config, then reports a
|
|
207
|
+
// degraded shell. Same reason as the CI branch — bun install's own rename
|
|
208
|
+
// is the concurrency control, not a lock in this script.
|
|
209
|
+
try {
|
|
210
|
+
await runSetupCommand('bun install --no-summary', $`bun install --no-summary`);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return error;
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
230
215
|
}
|
|
231
216
|
|
|
232
217
|
function ensureTypeScriptApiPackage(root: string): void {
|
|
@@ -457,59 +442,6 @@ async function runSetupCommand(
|
|
|
457
442
|
}
|
|
458
443
|
}
|
|
459
444
|
|
|
460
|
-
async function withSetupLock<T>(fn: () => Promise<T>): Promise<T> {
|
|
461
|
-
const lockDir = path.join(projectRoot, 'tooling/direnv/.devenv/setup-environment.lock');
|
|
462
|
-
await acquireLock(lockDir);
|
|
463
|
-
try {
|
|
464
|
-
return await fn();
|
|
465
|
-
} finally {
|
|
466
|
-
await rmdir(lockDir).catch(() => undefined);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
async function acquireLock(lockDir: string): Promise<void> {
|
|
471
|
-
const deadline = Date.now() + 120_000;
|
|
472
|
-
while (true) {
|
|
473
|
-
try {
|
|
474
|
-
await mkdir(lockDir, { recursive: false });
|
|
475
|
-
return;
|
|
476
|
-
} catch (error) {
|
|
477
|
-
if (!isFileExistsError(error) || Date.now() > deadline) {
|
|
478
|
-
throw error;
|
|
479
|
-
}
|
|
480
|
-
if (await isStaleLock(lockDir)) {
|
|
481
|
-
// Surface the self-heal so an interrupted-run leftover is visible in
|
|
482
|
-
// the direnv log rather than silently absorbed.
|
|
483
|
-
console.error(`! Breaking stale setup lock (${lockDir}) left by an interrupted run`);
|
|
484
|
-
// Best-effort: if a concurrent process breaks it first, the rmdir
|
|
485
|
-
// fails silently and the next mkdir attempt settles the race.
|
|
486
|
-
await rmdir(lockDir).catch(() => undefined);
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
await Bun.sleep(100);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
async function isStaleLock(lockDir: string): Promise<boolean> {
|
|
495
|
-
try {
|
|
496
|
-
const info = await stat(lockDir);
|
|
497
|
-
return Date.now() - info.mtimeMs > STALE_LOCK_MS;
|
|
498
|
-
} catch (error) {
|
|
499
|
-
// Only "lock vanished" is expected here (a concurrent process released
|
|
500
|
-
// it); anything else must surface — a swallowed ReferenceError in this
|
|
501
|
-
// exact spot once disabled stale detection entirely.
|
|
502
|
-
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
503
|
-
return false; // gone — let the mkdir retry acquire it
|
|
504
|
-
}
|
|
505
|
-
throw error;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function isFileExistsError(error: unknown): boolean {
|
|
510
|
-
return error instanceof Error && 'code' in error && error.code === 'EEXIST';
|
|
511
|
-
}
|
|
512
|
-
|
|
513
445
|
function reportSetupFailure(error: unknown): never {
|
|
514
446
|
describeFailure('ERROR', error);
|
|
515
447
|
process.exit(1);
|
|
@@ -3,6 +3,12 @@ cd "$(git rev-parse --show-toplevel)"
|
|
|
3
3
|
TOOLING="$PWD/tooling"
|
|
4
4
|
|
|
5
5
|
export PATH="$("$TOOLING/direnv/repo-path")"
|
|
6
|
+
# ttsc compiles with the native TypeScript compiler, which the dev shell names in
|
|
7
|
+
# TTSC_TSGO_BINARY. A hook runs outside that shell, where ttsc would resolve the
|
|
8
|
+
# JavaScript compiler a package's `typescript` dependency names and refuse to run.
|
|
9
|
+
if [ -z "${TTSC_TSGO_BINARY:-}" ] && [ -x "$PWD/node_modules/@typescript/native/bin/tsc" ]; then
|
|
10
|
+
export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
|
|
11
|
+
fi
|
|
6
12
|
|
|
7
13
|
set -e -o pipefail
|
|
8
14
|
|
|
@@ -3,6 +3,12 @@ cd "$(git rev-parse --show-toplevel)"
|
|
|
3
3
|
TOOLING="$PWD/tooling"
|
|
4
4
|
|
|
5
5
|
export PATH="$("$TOOLING/direnv/repo-path")"
|
|
6
|
+
# ttsc compiles with the native TypeScript compiler, which the dev shell names in
|
|
7
|
+
# TTSC_TSGO_BINARY. A hook runs outside that shell, where ttsc would resolve the
|
|
8
|
+
# JavaScript compiler a package's `typescript` dependency names and refuse to run.
|
|
9
|
+
if [ -z "${TTSC_TSGO_BINARY:-}" ] && [ -x "$PWD/node_modules/@typescript/native/bin/tsc" ]; then
|
|
10
|
+
export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
|
|
11
|
+
fi
|
|
6
12
|
|
|
7
13
|
set -e -o pipefail
|
|
8
14
|
|
|
@@ -25,6 +25,12 @@ cd "$(git rev-parse --show-toplevel)"
|
|
|
25
25
|
TOOLING="$PWD/tooling"
|
|
26
26
|
|
|
27
27
|
export PATH="$("$TOOLING/direnv/repo-path")"
|
|
28
|
+
# ttsc compiles with the native TypeScript compiler, which the dev shell names in
|
|
29
|
+
# TTSC_TSGO_BINARY. A hook runs outside that shell, where ttsc would resolve the
|
|
30
|
+
# JavaScript compiler a package's `typescript` dependency names and refuse to run.
|
|
31
|
+
if [ -z "${TTSC_TSGO_BINARY:-}" ] && [ -x "$PWD/node_modules/@typescript/native/bin/tsc" ]; then
|
|
32
|
+
export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
|
|
33
|
+
fi
|
|
28
34
|
|
|
29
35
|
case "$(uname -s)" in
|
|
30
36
|
Darwin) ;;
|
|
@@ -73,19 +73,26 @@ 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.
|
|
77
|
-
#
|
|
76
|
+
# mid-read. Per workflow alone is not enough either: CI's concurrency
|
|
77
|
+
# group is per pull request (by number), or per ref for pushes, so
|
|
78
|
+
# separate PRs and jobs run at once and must never share mutable graph
|
|
79
|
+
# or eval state. The scope hashes that same identity, not github.ref: a
|
|
80
|
+
# merged close carries the base branch's ref, so two pull requests'
|
|
81
|
+
# cleanups merged a minute apart would share one scope while running in
|
|
82
|
+
# different concurrency groups.
|
|
78
83
|
# Hash the exact identity (not a lossy path slug); keep cache artifacts
|
|
79
|
-
# and their metadata DB together, warm across runs of the same
|
|
84
|
+
# and their metadata DB together, warm across runs of the same pull
|
|
85
|
+
# request or ref and job.
|
|
80
86
|
- name: 📂 Locate the Nx cache on the shared bind
|
|
81
87
|
if: steps.runner-kind.outputs.host == 'true'
|
|
82
88
|
shell: bash
|
|
83
89
|
env:
|
|
84
90
|
NX_CACHE_REPO: ${{ github.repository }}
|
|
85
91
|
NX_CACHE_LANE: ${{ github.workflow }}
|
|
92
|
+
SCOPE_REF: ${{ github.event.pull_request.number || github.ref }}
|
|
86
93
|
run: |
|
|
87
94
|
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" "$
|
|
95
|
+
scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$SCOPE_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
|
|
89
96
|
NX_CACHE_ROOT="/var/cache/ci/nx/$NX_CACHE_REPO/${lane:-default}/$scope"
|
|
90
97
|
mkdir -p "$NX_CACHE_ROOT/cache" "$NX_CACHE_ROOT/workspace-data"
|
|
91
98
|
{
|
|
@@ -102,8 +109,12 @@ runs:
|
|
|
102
109
|
# .devenv (eval SQLite, gc roots, profile) and .direnv survive the job, so
|
|
103
110
|
# the next job on this host evaluates nothing and downloads nothing. The
|
|
104
111
|
# Actions cache segment below is the ephemeral runners' substitute for this.
|
|
105
|
-
# Scoped per workflow
|
|
106
|
-
# jobs can overlap, and one
|
|
112
|
+
# Scoped per workflow, pull request (by number) or ref for pushes, job and
|
|
113
|
+
# platform, like Nx: separate PR runs and jobs can overlap, and one
|
|
114
|
+
# eval-cache.db must have only one writer. Not per github.ref: a merged
|
|
115
|
+
# close carries the base branch's ref, so two pull requests' cleanups
|
|
116
|
+
# would share this state and the second's bind mount below would shadow
|
|
117
|
+
# the first's workspace.
|
|
107
118
|
#
|
|
108
119
|
# The eval cache keys on canonical absolute paths, and act's host executor
|
|
109
120
|
# checks out under <cache>/<random 8 chars>/hostexecutor - a new path every
|
|
@@ -124,9 +135,10 @@ runs:
|
|
|
124
135
|
DEVENV_STATE_REPO: ${{ github.repository }}
|
|
125
136
|
DEVENV_STATE_LANE: ${{ github.workflow }}
|
|
126
137
|
DEVENV_STATE_JOB: ${{ github.job }}
|
|
138
|
+
SCOPE_REF: ${{ github.event.pull_request.number || github.ref }}
|
|
127
139
|
run: |
|
|
128
140
|
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" "$
|
|
141
|
+
scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$SCOPE_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
|
|
130
142
|
root="/var/cache/ci/devenv/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
|
|
131
143
|
mkdir -p "$root/.devenv" "$root/.direnv"
|
|
132
144
|
rm -rf tooling/direnv/.devenv tooling/direnv/.direnv
|
package/package.json
CHANGED
|
@@ -3,12 +3,16 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { hashCargoPathInputs } from '../cargo-source-hash.js';
|
|
4
4
|
|
|
5
5
|
const args = process.argv.slice(2);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const includeWorkspace = args[0] === '--include-workspace';
|
|
7
|
+
const manifest = args[includeWorkspace ? 1 : 0];
|
|
8
|
+
if (args.length > (includeWorkspace ? 2 : 1) || manifest?.startsWith('-')) {
|
|
9
|
+
process.stderr.write('usage: smoo-nx-cargo-hash [--include-workspace] [Cargo.toml]\n');
|
|
8
10
|
process.exit(2);
|
|
9
11
|
}
|
|
10
12
|
try {
|
|
11
|
-
process.stdout.write(
|
|
13
|
+
process.stdout.write(
|
|
14
|
+
`${await hashCargoPathInputs(resolve(manifest ?? 'Cargo.toml'), process.cwd(), { includeWorkspace })}\n`,
|
|
15
|
+
);
|
|
12
16
|
} catch (error) {
|
|
13
17
|
process.stderr.write(`smoo-nx-cargo-hash: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
14
18
|
process.stderr.write(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, it } from 'bun:test';
|
|
2
2
|
import { execFileSync } from 'node:child_process';
|
|
3
|
-
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { hashCargoPathInputs } from './cargo-source-hash.js';
|
|
@@ -49,3 +49,239 @@ it.each(['app', '.'])('invalidates transitive and inherited Cargo inputs with Nx
|
|
|
49
49
|
await rm(root, { recursive: true, force: true });
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
it('the runtime input is byte-identical under cargo lock contention: nothing on stderr', async () => {
|
|
54
|
+
// Nx hashes a runtime input's stdout and stderr together, and hashes once per
|
|
55
|
+
// distinct task env, so the bin runs many times at once at the start of a
|
|
56
|
+
// run. Cargo reports package-cache lock contention on stderr; a private
|
|
57
|
+
// CARGO_HOME makes that contention real here.
|
|
58
|
+
const root = await mkdtemp(join(tmpdir(), 'cargo-hash-'));
|
|
59
|
+
const manifest = join(root, 'Cargo.toml');
|
|
60
|
+
try {
|
|
61
|
+
await mkdir(join(root, 'src'), { recursive: true });
|
|
62
|
+
await writeFile(manifest, '[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[workspace]\n');
|
|
63
|
+
await writeFile(join(root, 'src', 'lib.rs'), 'pub fn run() {}\n');
|
|
64
|
+
const env = { ...process.env, CARGO_HOME: join(root, '.cargo-home') };
|
|
65
|
+
execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', manifest], { stdio: 'pipe', env });
|
|
66
|
+
// The built bin under node, exactly as nx.json's runtime input invokes it (test depends on build).
|
|
67
|
+
const bin = join(import.meta.dir, '..', 'dist', 'bin', 'smoo-nx-cargo-hash.js');
|
|
68
|
+
const runs = await Promise.all(
|
|
69
|
+
Array.from({ length: 8 }, async () => {
|
|
70
|
+
const proc = Bun.spawn(['node', bin, manifest], {
|
|
71
|
+
cwd: root,
|
|
72
|
+
env,
|
|
73
|
+
stdout: 'pipe',
|
|
74
|
+
stderr: 'pipe',
|
|
75
|
+
});
|
|
76
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
77
|
+
new Response(proc.stdout).text(),
|
|
78
|
+
new Response(proc.stderr).text(),
|
|
79
|
+
proc.exited,
|
|
80
|
+
]);
|
|
81
|
+
return { stdout, stderr, exitCode };
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
for (const run of runs) {
|
|
85
|
+
expect(run.exitCode).toBe(0);
|
|
86
|
+
expect(run.stderr).toBe('');
|
|
87
|
+
}
|
|
88
|
+
expect(new Set(runs.map((run) => run.stdout)).size).toBe(1);
|
|
89
|
+
} finally {
|
|
90
|
+
await rm(root, { recursive: true, force: true });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
async function workspaceCargoFixture(root: string) {
|
|
95
|
+
const workspace = join(root, 'workspace');
|
|
96
|
+
const manifest = join(workspace, 'Cargo.toml');
|
|
97
|
+
const sources = {
|
|
98
|
+
'workspace/Cargo.toml': '[workspace]\nmembers=["packages/app","crates/bridge","crates/leaf"]\nresolver="2"\n',
|
|
99
|
+
'workspace/packages/app/Cargo.toml':
|
|
100
|
+
'[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nbridge={path="../../crates/bridge"}\n',
|
|
101
|
+
'workspace/packages/app/src/main.rs': 'fn main() { println!("{}", bridge::answer()); }\n',
|
|
102
|
+
'workspace/crates/bridge/Cargo.toml':
|
|
103
|
+
'[package]\nname="bridge"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nleaf={path="../leaf"}\nexternal={path="../../../external"}\n',
|
|
104
|
+
'workspace/crates/bridge/src/lib.rs': 'pub fn answer() -> u8 { leaf::answer() + external::answer() }\n',
|
|
105
|
+
'workspace/crates/leaf/Cargo.toml': '[package]\nname="leaf"\nversion="0.1.0"\nedition="2021"\n',
|
|
106
|
+
'workspace/crates/leaf/src/lib.rs': 'pub fn answer() -> u8 { 1 }\n',
|
|
107
|
+
'external/Cargo.toml': '[package]\nname="external"\nversion="0.1.0"\nedition="2021"\n[workspace]\n',
|
|
108
|
+
'external/src/lib.rs': 'pub fn answer() -> u8 { 10 }\n',
|
|
109
|
+
};
|
|
110
|
+
for (const [path, text] of Object.entries(sources)) {
|
|
111
|
+
const file = join(root, path);
|
|
112
|
+
await mkdir(dirname(file), { recursive: true });
|
|
113
|
+
await writeFile(file, text);
|
|
114
|
+
}
|
|
115
|
+
execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', manifest], { stdio: 'pipe' });
|
|
116
|
+
return { workspace, manifest, leafSource: join(workspace, 'crates/leaf/src/lib.rs') };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
it('include-workspace hashes in-workspace transitive source edits without changing the external-only contract', async () => {
|
|
120
|
+
const root = await mkdtemp(join(tmpdir(), 'cargo-hash-workspace-'));
|
|
121
|
+
try {
|
|
122
|
+
const { workspace, manifest, leafSource } = await workspaceCargoFixture(root);
|
|
123
|
+
const external = await hashCargoPathInputs(manifest, workspace);
|
|
124
|
+
const included = await hashCargoPathInputs(manifest, workspace, { includeWorkspace: true });
|
|
125
|
+
expect(await hashCargoPathInputs(manifest, workspace, { includeWorkspace: true })).toBe(included);
|
|
126
|
+
|
|
127
|
+
await writeFile(leafSource, 'pub fn answer() -> u8 { 2 }\n');
|
|
128
|
+
expect(await hashCargoPathInputs(manifest, workspace)).toBe(external);
|
|
129
|
+
const changed = await hashCargoPathInputs(manifest, workspace, { includeWorkspace: true });
|
|
130
|
+
expect(changed).not.toBe(included);
|
|
131
|
+
expect(await hashCargoPathInputs(manifest, workspace, { includeWorkspace: true })).toBe(changed);
|
|
132
|
+
|
|
133
|
+
await writeFile(join(root, 'external/src/lib.rs'), 'pub fn answer() -> u8 { 20 }\n');
|
|
134
|
+
expect(await hashCargoPathInputs(manifest, workspace)).not.toBe(external);
|
|
135
|
+
expect(await hashCargoPathInputs(manifest, workspace, { includeWorkspace: true })).not.toBe(changed);
|
|
136
|
+
} finally {
|
|
137
|
+
await rm(root, { recursive: true, force: true });
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('include-workspace CLI accepts an optional manifest and refuses unsupported arguments', async () => {
|
|
142
|
+
const root = await mkdtemp(join(tmpdir(), 'cargo-hash-cli-'));
|
|
143
|
+
try {
|
|
144
|
+
const { workspace, leafSource } = await workspaceCargoFixture(root);
|
|
145
|
+
const bin = join(import.meta.dir, '../dist/bin/smoo-nx-cargo-hash.js');
|
|
146
|
+
const run = async (args: string[]) => {
|
|
147
|
+
const child = Bun.spawn(['bun', bin, ...args], { cwd: workspace, stdout: 'pipe', stderr: 'pipe' });
|
|
148
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
149
|
+
child.exited,
|
|
150
|
+
new Response(child.stdout).text(),
|
|
151
|
+
new Response(child.stderr).text(),
|
|
152
|
+
]);
|
|
153
|
+
return { exitCode, stdout, stderr };
|
|
154
|
+
};
|
|
155
|
+
const external = await run(['Cargo.toml']);
|
|
156
|
+
expect(external.exitCode, external.stderr).toBe(0);
|
|
157
|
+
const included = await run(['--include-workspace']);
|
|
158
|
+
expect(included.exitCode, included.stderr).toBe(0);
|
|
159
|
+
expect(included.stderr).toBe('');
|
|
160
|
+
expect(await run(['--include-workspace', 'Cargo.toml'])).toEqual(included);
|
|
161
|
+
|
|
162
|
+
await writeFile(leafSource, 'pub fn answer() -> u8 { 2 }\n');
|
|
163
|
+
expect(await run([])).toEqual(external);
|
|
164
|
+
const changed = await run(['--include-workspace', 'Cargo.toml']);
|
|
165
|
+
expect(changed.exitCode, changed.stderr).toBe(0);
|
|
166
|
+
expect(changed.stderr).toBe('');
|
|
167
|
+
expect(changed.stdout).not.toBe(included.stdout);
|
|
168
|
+
expect(await run(['--include-workspace'])).toEqual(changed);
|
|
169
|
+
|
|
170
|
+
for (const args of [
|
|
171
|
+
['--unknown'],
|
|
172
|
+
['--include-workspace', '--unknown'],
|
|
173
|
+
['Cargo.toml', '--include-workspace'],
|
|
174
|
+
['--include-workspace', 'Cargo.toml', 'extra'],
|
|
175
|
+
]) {
|
|
176
|
+
const refused = await run(args);
|
|
177
|
+
expect(refused.exitCode, refused.stderr).toBe(2);
|
|
178
|
+
expect(refused.stdout).toBe('');
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
await rm(root, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it.each(['helper', 'cli'])(
|
|
186
|
+
'include-workspace keeps a custom Nx cached Cargo consumer fresh via %s',
|
|
187
|
+
async (mode) => {
|
|
188
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-hash-nx-')));
|
|
189
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
190
|
+
const dist = join(import.meta.dir, '../dist');
|
|
191
|
+
try {
|
|
192
|
+
const { workspace, leafSource } = await workspaceCargoFixture(root);
|
|
193
|
+
execFileSync('git', ['init', '--quiet', workspace], { stdio: 'pipe' });
|
|
194
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
195
|
+
await writeFile(join(workspace, '.gitignore'), 'node_modules/\ntarget/\ndist/\n.nx/\n');
|
|
196
|
+
await writeFile(join(workspace, 'package.json'), '{"name":"cargo-consumer-fixture","private":true}\n');
|
|
197
|
+
const hashProgram =
|
|
198
|
+
`import { hashCargoPathInputs } from ${JSON.stringify(join(dist, 'cargo-source-hash.js'))}; ` +
|
|
199
|
+
'console.log(await hashCargoPathInputs("Cargo.toml", process.cwd(), { includeWorkspace: true }));';
|
|
200
|
+
await writeFile(
|
|
201
|
+
join(workspace, 'nx.json'),
|
|
202
|
+
JSON.stringify({
|
|
203
|
+
namedInputs: {
|
|
204
|
+
cargoSources: [
|
|
205
|
+
'{workspaceRoot}/Cargo.lock',
|
|
206
|
+
{
|
|
207
|
+
runtime:
|
|
208
|
+
mode === 'helper'
|
|
209
|
+
? `bun -e '${hashProgram}'`
|
|
210
|
+
: `bun ${JSON.stringify(join(dist, 'bin/smoo-nx-cargo-hash.js'))} --include-workspace`,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
await writeFile(
|
|
217
|
+
join(workspace, 'packages/app/project.json'),
|
|
218
|
+
JSON.stringify({
|
|
219
|
+
name: 'app',
|
|
220
|
+
targets: {
|
|
221
|
+
build: {
|
|
222
|
+
executor: 'nx:run-commands',
|
|
223
|
+
cache: true,
|
|
224
|
+
inputs: ['{projectRoot}/**/*', '!{projectRoot}/dist/**/*', 'cargoSources'],
|
|
225
|
+
outputs: ['{projectRoot}/dist'],
|
|
226
|
+
options: { command: 'bun packages/app/build.ts' },
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
const executions = join(root, 'executions.log');
|
|
232
|
+
const outputDirectory = join(workspace, 'packages/app/dist');
|
|
233
|
+
const output = join(outputDirectory, 'result.txt');
|
|
234
|
+
await writeFile(
|
|
235
|
+
join(workspace, 'packages/app/build.ts'),
|
|
236
|
+
`import { execFileSync } from 'node:child_process';
|
|
237
|
+
import { appendFile, mkdir, writeFile } from 'node:fs/promises';
|
|
238
|
+
const result = execFileSync('cargo', ['run', '--quiet', '--locked', '--offline', '--manifest-path', 'packages/app/Cargo.toml'], { encoding: 'utf8' });
|
|
239
|
+
await mkdir(${JSON.stringify(outputDirectory)}, { recursive: true });
|
|
240
|
+
await writeFile(${JSON.stringify(output)}, result);
|
|
241
|
+
await appendFile(${JSON.stringify(executions)}, result);
|
|
242
|
+
`,
|
|
243
|
+
);
|
|
244
|
+
const run = async () => {
|
|
245
|
+
const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:build'], {
|
|
246
|
+
cwd: workspace,
|
|
247
|
+
env: {
|
|
248
|
+
...process.env,
|
|
249
|
+
NX_WORKSPACE_ROOT_PATH: workspace,
|
|
250
|
+
NX_DAEMON: 'false',
|
|
251
|
+
NX_ISOLATE_PLUGINS: 'false',
|
|
252
|
+
NX_WORKSPACE_DATA_DIRECTORY: join(workspace, '.nx/workspace-data'),
|
|
253
|
+
NX_CACHE_DIRECTORY: join(workspace, '.nx/cache'),
|
|
254
|
+
},
|
|
255
|
+
stdout: 'pipe',
|
|
256
|
+
stderr: 'pipe',
|
|
257
|
+
});
|
|
258
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
259
|
+
child.exited,
|
|
260
|
+
new Response(child.stdout).text(),
|
|
261
|
+
new Response(child.stderr).text(),
|
|
262
|
+
]);
|
|
263
|
+
expect(exitCode, stdout + stderr).toBe(0);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
await run();
|
|
267
|
+
expect(await readFile(output, 'utf8')).toBe('11\n');
|
|
268
|
+
expect(await readFile(executions, 'utf8')).toBe('11\n');
|
|
269
|
+
await rm(outputDirectory, { recursive: true });
|
|
270
|
+
await run();
|
|
271
|
+
expect(await readFile(output, 'utf8')).toBe('11\n');
|
|
272
|
+
expect(await readFile(executions, 'utf8')).toBe('11\n');
|
|
273
|
+
|
|
274
|
+
await writeFile(leafSource, 'pub fn answer() -> u8 { 2 }\n');
|
|
275
|
+
await run();
|
|
276
|
+
expect(await readFile(output, 'utf8')).toBe('12\n');
|
|
277
|
+
expect(await readFile(executions, 'utf8')).toBe('11\n12\n');
|
|
278
|
+
await rm(outputDirectory, { recursive: true });
|
|
279
|
+
await run();
|
|
280
|
+
expect(await readFile(output, 'utf8')).toBe('12\n');
|
|
281
|
+
expect(await readFile(executions, 'utf8')).toBe('11\n12\n');
|
|
282
|
+
} finally {
|
|
283
|
+
await rm(root, { recursive: true, force: true });
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
120_000,
|
|
287
|
+
);
|