Skip to content

Commit 2b02d0d

Browse files
authored
refactor(ado-script): flatten bundled artifact paths (#671)
1 parent 79ecd1d commit 2b02d0d

20 files changed

Lines changed: 68 additions & 66 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ jobs:
6767
run: |
6868
npm ci
6969
npm run build
70-
# `npm run build` runs codegen + ncc and outputs dist/gate/index.js.
70+
# `npm run build` runs codegen + ncc and outputs gate.js + import.js.
7171

7272
- name: Package ado-script bundle
7373
run: |
7474
set -euo pipefail
7575
cd scripts
76-
zip -r ../ado-script.zip ado-script/dist
76+
zip -r ../ado-script.zip ado-script/gate.js ado-script/import.js
7777
7878
- name: Upload release assets
7979
env:

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ Every compiled pipeline runs as three sequential jobs:
161161
├── scripts/ # Supporting scripts shipped as release artifacts
162162
│ └── ado-script/ # TypeScript workspace for bundled gate.js, import.js, and future bundles
163163
│ └── src/
164-
│ ├── gate/ # Gate evaluator source (bundled to dist/gate/index.js)
165-
│ ├── import/ # Runtime prompt resolver source (bundled to dist/import/index.js)
164+
│ ├── gate/ # Gate evaluator source (bundled to gate.js)
165+
│ ├── import/ # Runtime prompt resolver source (bundled to import.js)
166166
│ └── shared/ # Shared modules across bundles (auth, ado-client, env-facts, types.gen.ts)
167167
├── tests/ # Integration tests and fixtures
168168
├── docs/ # Per-concept reference documentation (see index below)

docs/ado-script.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ because the compiler always embeds an absolute marker path and
5151
`import.js` is single-pass (nested markers inside the inlined body are
5252
not re-expanded).
5353

54-
The bundle lives at `dist/import/index.js` and ships in the same
54+
The bundle lives at `import.js` and ships in the same
5555
`ado-script.zip` release asset as `gate.js`, so pipelines download it
5656
through the same Setup-job asset flow. `import.js` uses only the Node
5757
standard library, so the ncc bundle is small (~1.5 KB) and carries no
@@ -137,7 +137,7 @@ job.
137137
## Runtime env-var contract
138138

139139
The compiler injects these environment variables on the
140-
`bash: node gate/index.js` step. `gate.js` reads them via
140+
`bash: node gate.js` step. `gate.js` reads them via
141141
`process.env`:
142142

143143
| Env var | Source | Purpose |
@@ -187,13 +187,13 @@ scripts/ado-script/
187187
│ ├── index.ts # main(): expand runtime-import markers in place
188188
│ └── __tests__/ # marker, path-resolution, and single-pass coverage
189189
├── test/ # End-to-end smoke tests
190-
└── dist/ # ncc bundle output (gitignored)
191-
├── gate/index.js
192-
└── import/index.js
190+
├── gate.js # ncc bundle output (gitignored)
191+
└── import.js # ncc bundle output (gitignored)
193192
```
194193

195194
The release workflow (`.github/workflows/release.yml`) runs
196-
`npm ci && npm run build`, then zips `scripts/ado-script/dist/` into
195+
`npm ci && npm run build`, then zips `scripts/ado-script/gate.js` and
196+
`scripts/ado-script/import.js` into
197197
the `ado-script.zip` release asset. Pipelines download that asset at
198198
runtime by URL pinned to the compiler's `CARGO_PKG_VERSION`, verify
199199
its SHA-256 against the `checksums.txt` asset, then extract.
@@ -250,7 +250,7 @@ three step strings into the Setup job:
250250
`CARGO_PKG_VERSION`, verifies the zip's SHA-256, then
251251
`unzip -o /tmp/ado-aw-scripts/ado-script.zip -d /tmp/ado-aw-scripts/`.
252252
Also capped at `timeoutInMinutes: 5`.
253-
3. **`bash: node '/tmp/ado-aw-scripts/ado-script/dist/gate/index.js'`**
253+
3. **`bash: node '/tmp/ado-aw-scripts/ado-script/gate.js'`**
254254
runs the gate with `GATE_SPEC` and the env-var contract documented
255255
above.
256256

@@ -263,7 +263,7 @@ the Agent job's existing `{{ prepare_steps }}` block:
263263
1. **`NodeTool@0`** — same shape as above.
264264
2. **`curl` download + verify + extract** — same artefact, same
265265
verification.
266-
3. **`bash: node '/tmp/ado-aw-scripts/ado-script/dist/import/index.js'`**
266+
3. **`bash: node '/tmp/ado-aw-scripts/ado-script/import.js'`**
267267
expands `{{#runtime-import …}}` markers in
268268
`/tmp/awf-tools/agent-prompt.md` in place. See
269269
[`runtime-imports.md`](runtime-imports.md) for marker syntax.
@@ -324,16 +324,16 @@ The IR-to-bash codegen that produces the gate step is
324324
`scripts/ado-script/src/poll/`. Reuse anything in `src/shared/`.
325325
2. Add a build script to `package.json`:
326326
```json
327-
"build:poll": "ncc build src/poll/index.ts -o dist/poll -m -t"
327+
"build:poll": "ncc build src/poll/index.ts -o .ado-build/poll -m -t && node -e \"const fs=require('node:fs'); fs.copyFileSync('.ado-build/poll/index.js','poll.js'); fs.rmSync('.ado-build/poll',{recursive:true,force:true});\""
328328
```
329329
and extend `build` to also run it.
330330
3. Add vitest tests under `src/poll/__tests__/`.
331331
4. Wire from a new `CompilerExtension` (or extend an existing one)
332332
that downloads `ado-script.zip` (already a release asset) and
333-
invokes `node /tmp/ado-aw-scripts/ado-script/dist/poll/index.js`
333+
invokes `node /tmp/ado-aw-scripts/ado-script/poll.js`
334334
as a runtime step.
335-
5. No release-workflow change is needed — `zip -r ado-script/dist`
336-
picks up the new bundle automatically.
335+
5. Update release packaging to include `scripts/ado-script/poll.js`
336+
in `ado-script.zip` alongside other bundles.
337337

338338
### Local development loop
339339

@@ -344,7 +344,7 @@ npm ci # one-time
344344
npm run codegen # regenerate types.gen.ts (compiles ado-aw first)
345345
npm test # vitest unit tests
346346
npm run typecheck # strict tsc --noEmit
347-
npm run build # ncc-bundle to dist/gate/index.js
347+
npm run build # ncc-bundle to gate.js
348348
npm run test:smoke # build + smoke test the bundle end-to-end
349349
```
350350

docs/filter-ir.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ require heuristic analysis and could produce false positives.
235235

236236
Produces a complete ADO pipeline step (`- bash: |`) with a **data-driven
237237
architecture**: bash is a thin ADO-macro shim, all filter logic lives in
238-
the bundled Node.js gate evaluator (`scripts/ado-script/dist/gate/index.js`) that reads a JSON
238+
the bundled Node.js gate evaluator (`scripts/ado-script/gate.js`) that reads a JSON
239239
gate spec.
240240

241241
#### Generated Step Structure
@@ -257,7 +257,7 @@ gate spec.
257257
export ADO_SYSTEM_ACCESS_TOKEN="$SYSTEM_ACCESSTOKEN"
258258
259259
# 4. Run the bundled Node evaluator (downloaded by the Setup job)
260-
node '/tmp/ado-aw-scripts/ado-script/dist/gate/index.js'
260+
node '/tmp/ado-aw-scripts/ado-script/gate.js'
261261
name: prGate
262262
displayName: "Evaluate PR filters"
263263
env:
@@ -304,7 +304,7 @@ acquisition logic.
304304
#### Bundled Gate Evaluator (`scripts/ado-script/src/gate/`)
305305

306306
The evaluator is a TypeScript program ncc-bundled to a single
307-
self-contained `scripts/ado-script/dist/gate/index.js` (~1.1 MB) that ships as part of the
307+
self-contained `scripts/ado-script/gate.js` (~1.1 MB) that ships as part of the
308308
`ado-script.zip` release asset. See [`ado-script.md`](ado-script.md) for the
309309
full design and codegen pipeline. It handles:
310310

@@ -364,9 +364,9 @@ For the gate path it controls:
364364
LTS so `gate.js` has a runtime.
365365
2. **Download step** — fetches `ado-script.zip` from the ado-aw release
366366
artifacts, verifies its SHA256 checksum via `checksums.txt`, then
367-
extracts `gate.js` to `/tmp/ado-aw-scripts/ado-script/dist/gate/index.js`.
367+
extracts `gate.js` to `/tmp/ado-aw-scripts/ado-script/gate.js`.
368368
3. **Gate step** — calls `compile_gate_step_external()` to generate a step
369-
that runs `node /tmp/ado-aw-scripts/ado-script/dist/gate/index.js` (no inline heredoc).
369+
that runs `node /tmp/ado-aw-scripts/ado-script/gate.js` (no inline heredoc).
370370
4. **Validation** — runs `validate_pr_filters()` / `validate_pipeline_filters()`
371371
during compilation via the `validate()` trait method.
372372

@@ -416,7 +416,7 @@ The `expression` escape hatch is also ANDed if present.
416416

417417
The `gate.js` bundle is built from the TypeScript workspace at
418418
`scripts/ado-script/` (see [`ado-script.md`](ado-script.md)) and emitted to
419-
`scripts/ado-script/dist/gate/index.js` by the release workflow's build step. It ships inside
419+
`scripts/ado-script/gate.js` by the release workflow's build step. It ships inside
420420
the `ado-script.zip` release asset, alongside any future bundled helpers
421421
(e.g. `poll.js`, `stats.js`). The download URL is deterministic based on
422422
the ado-aw version:
@@ -425,7 +425,7 @@ the ado-aw version:
425425
A `checksums.txt` file is also published at the same URL base and used to
426426
verify the SHA256 integrity of `ado-script.zip` before extraction.
427427

428-
The Setup-job download step pulls the zip, extracts `ado-script/dist/gate/index.js`,
428+
The Setup-job download step pulls the zip, extracts `ado-script/gate.js`,
429429
and discards the rest. New per-use-site bundles follow the same pattern
430430
(per-bundle ncc entry + per-bundle download step).
431431

docs/runtime-imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ compile time instead of on the pipeline runner.
7575

7676
## Implementation notes
7777

78-
- **Runtime**: `dist/import/index.js` is ncc-bundled into `ado-script.zip`.
78+
- **Runtime**: `import.js` is ncc-bundled into `ado-script.zip`.
7979
The always-on `AdoScriptExtension`'s `prepare_steps()` injects three
8080
steps into the Agent job's existing `{{ prepare_steps }}` block:
8181
`NodeTool@0` install, the `ado-script.zip` download/verify/extract,

scripts/ado-script/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
2-
dist
2+
.ado-build
3+
gate.js
4+
import.js
35
schema
46
*.tsbuildinfo

scripts/ado-script/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This invokes `cargo run -- export-gate-schema` to write the JSON Schema, then ru
2222
- `src/shared/` — modules shared across all bundles (auth, ado-client, vso-logger, env-facts, policy state machine)
2323
- `src/gate/` — gate evaluator entry point and per-concern modules
2424
- `src/import/` — runtime-import resolver entry point
25-
- `dist/` — ncc bundle output (gitignored); `npm run build` writes `dist/gate/index.js` and `dist/import/index.js`, both of which ship in `ado-script.zip`
25+
- `gate.js` / `import.js` — ncc bundle outputs (gitignored); `npm run build` writes both at the workspace root, and both ship in `ado-script.zip`
2626

2727
## See also
2828

scripts/ado-script/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"node": ">=20.0.0"
88
},
99
"scripts": {
10-
"build": "npm run codegen && npm run build:gate && npm run build:import",
11-
"build:gate": "ncc build src/gate/index.ts -o dist/gate -m -t",
12-
"build:import": "ncc build src/import/index.ts -o dist/import -m -t",
13-
"build:check": "ls -lh dist/gate/index.js && wc -c dist/gate/index.js",
10+
"build": "npm run codegen && npm run clean && npm run build:gate && npm run build:import",
11+
"clean": "node -e \"const fs=require('node:fs'); fs.rmSync('.ado-build',{recursive:true,force:true}); fs.rmSync('gate.js',{force:true}); fs.rmSync('import.js',{force:true});\"",
12+
"build:gate": "ncc build src/gate/index.ts -o .ado-build/gate -m -t && node -e \"const fs=require('node:fs'); fs.copyFileSync('.ado-build/gate/index.js','gate.js'); fs.rmSync('.ado-build/gate',{recursive:true,force:true});\"",
13+
"build:import": "ncc build src/import/index.ts -o .ado-build/import -m -t && node -e \"const fs=require('node:fs'); fs.copyFileSync('.ado-build/import/index.js','import.js'); fs.rmSync('.ado-build/import',{recursive:true,force:true});\"",
14+
"build:check": "ls -lh gate.js && wc -c gate.js",
1415
"codegen": "node -e \"require('node:fs').mkdirSync('schema', { recursive: true })\" && cargo run --quiet --manifest-path ../../Cargo.toml -- export-gate-schema --output schema/gate-spec.schema.json && npx json2ts schema/gate-spec.schema.json -o src/shared/types.gen.ts --bannerComment \"// AUTO-GENERATED from Rust IR via cargo run -- export-gate-schema. Do not edit; run npm run codegen.\"",
1516
"test": "vitest run",
1617
"test:smoke": "npm run build:gate && npm run build:import && vitest run -c vitest.config.smoke.ts",

scripts/ado-script/src/gate/predicates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function evaluatePredicate(p: PredicateSpec, facts: Map<string, unknown>)
164164
const unknownType = (p as { type?: unknown }).type;
165165
logWarning(
166166
`Unknown predicate type '${String(unknownType)}'; failing closed. ` +
167-
"Update scripts/ado-script/dist/gate/index.js (or the bundled ado-script.zip) to a " +
167+
"Update scripts/ado-script/gate.js (or the bundled ado-script.zip) to a " +
168168
"release that supports this predicate.",
169169
);
170170
return false;

scripts/ado-script/src/shared/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* (e.g. a manual build that hits the bypass branch in `bypass.ts`, or
1313
* a pipeline whose facts are all pipeline variables). The dynamic
1414
* `import()` below is statically analysable by ncc, so the SDK is
15-
* still bundled into `dist/gate/index.js` — only its module-evaluation
15+
* still bundled into `gate.js` — only its module-evaluation
1616
* cost is deferred until the first `getWebApi()` call.
1717
*
1818
* Env-var contract (set by the compiler in

0 commit comments

Comments
 (0)