@invarn/cibuild 2.5.6 → 2.5.8

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.
@@ -38,8 +38,19 @@ export interface IosSetupOptions {
38
38
  appStoreDeploy: boolean;
39
39
  bundleId: string;
40
40
  }
41
- export declare function generateAndroidPipeline(javaVersion?: number, setup?: SetupOptions, variants?: WorkflowVariants, cacheTechnology?: "gradle" | "kmm", metaNamespace?: 'invarn' | 'cibuild.io'): string;
42
- export declare function generateIosPipeline(projectPath: string, setup: IosSetupOptions, variants: IosWorkflowVariants, metaNamespace?: 'invarn' | 'cibuild.io'): string;
41
+ /**
42
+ * The `trigger_map` block appended to every generated pipeline.
43
+ *
44
+ * Without it the pipeline is inert on the Invarn side: `dispatchRepoEvent`
45
+ * skips any pipeline whose YAML declares no trigger_map, so a scaffolded repo
46
+ * receives pushes and builds nothing, with no error to explain it.
47
+ *
48
+ * `release` is deliberately absent — it deploys to Google Play / App Store,
49
+ * and a webhook must never reach it.
50
+ */
51
+ export declare function triggerMapBlock(defaultBranch?: string): string;
52
+ export declare function generateAndroidPipeline(javaVersion?: number, setup?: SetupOptions, variants?: WorkflowVariants, cacheTechnology?: "gradle" | "kmm", metaNamespace?: 'invarn' | 'cibuild.io', defaultBranch?: string): string;
53
+ export declare function generateIosPipeline(projectPath: string, setup: IosSetupOptions, variants: IosWorkflowVariants, metaNamespace?: 'invarn' | 'cibuild.io', defaultBranch?: string): string;
43
54
  export declare function handleBuildCommand(detectMobileProjectRoot: (dir: string) => "android" | "ios" | "kmm" | null, options?: {
44
55
  createPipelinesDir?: boolean;
45
56
  nonInteractive?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/commands/build.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,C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jC,WAAW,EAAE,uBAAuB,CAAC;IACrC,OAAO,EAAE,uBAAuB,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAoJD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,aAAa,GAAE,MAAgC,GAAG,MAAM,CAcvF;AAED,wBAAgB,uBAAuB,CACrC,WAAW,GAAE,MAAW,EACxB,KAAK,GAAE,YAAgL,EACvL,QAAQ,GAAE,gBAAmC,EAC7C,eAAe,GAAE,QAAQ,GAAG,KAAgB,EAC5C,aAAa,GAAE,QAAQ,GAAG,YAA2B,EACrD,aAAa,GAAE,MAAgC,GAC9C,MAAM,CA2NR;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,GAAE,QAAQ,GAAG,YAA2B,EACrD,aAAa,GAAE,MAAgC,GAC9C,MAAM,CA4LR;AAiVD,wBAAsB,kBAAkB,CACtC,uBAAuB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,EAC1E,OAAO,GAAE;IACP,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;CACpC,GACL,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -6,6 +6,7 @@ import { scanIosProject, formatIosScanResult } from "./ios-scanner.js";
6
6
  import { SecretsManager } from "../yaml/secrets-manager.js";
7
7
  import { collectFileSecret } from "./file-secret-collector.js";
8
8
  import { generateGitHubActionsWorkflow } from "./github-workflow.js";
9
+ import { detectDefaultBranch, FALLBACK_DEFAULT_BRANCH } from "../shared/git.js";
9
10
  function variantFromName(name) {
10
11
  const buildType = name.charAt(0).toUpperCase() + name.slice(1);
11
12
  return { variant: name, buildType, gradleTask: `assemble${buildType}` };
@@ -122,7 +123,32 @@ function detectSetupNeeds(warnings) {
122
123
  artifactType: 'apk',
123
124
  };
124
125
  }
125
- export function generateAndroidPipeline(javaVersion = 17, setup = { keystore: false, keystoreProperties: false, googleServices: false, googlePlayDeploy: false, googlePlayPackageName: '', artifactType: 'apk', keystorePaths: {} }, variants = DEFAULT_VARIANTS, cacheTechnology = "gradle", metaNamespace = 'cibuild.io') {
126
+ /**
127
+ * The `trigger_map` block appended to every generated pipeline.
128
+ *
129
+ * Without it the pipeline is inert on the Invarn side: `dispatchRepoEvent`
130
+ * skips any pipeline whose YAML declares no trigger_map, so a scaffolded repo
131
+ * receives pushes and builds nothing, with no error to explain it.
132
+ *
133
+ * `release` is deliberately absent — it deploys to Google Play / App Store,
134
+ * and a webhook must never reach it.
135
+ */
136
+ export function triggerMapBlock(defaultBranch = FALLBACK_DEFAULT_BRANCH) {
137
+ const branch = defaultBranch.trim() || FALLBACK_DEFAULT_BRANCH;
138
+ // JSON.stringify gives a valid double-quoted YAML scalar for any branch
139
+ // name git will accept. Quoting is not cosmetic: a branch called `no` or
140
+ // `y` parses as a boolean unquoted, and one called `1.0` as a number.
141
+ return `
142
+ # Which GitHub events build which workflow. Without this block the pipeline
143
+ # is never triggered by a push or a pull request.
144
+ trigger_map:
145
+ - push_branch: ${JSON.stringify(branch)}
146
+ workflow: primary
147
+ - pull_request_target_branch: "*"
148
+ workflow: pull-request
149
+ `;
150
+ }
151
+ export function generateAndroidPipeline(javaVersion = 17, setup = { keystore: false, keystoreProperties: false, googleServices: false, googlePlayDeploy: false, googlePlayPackageName: '', artifactType: 'apk', keystorePaths: {} }, variants = DEFAULT_VARIANTS, cacheTechnology = "gradle", metaNamespace = 'cibuild.io', defaultBranch = FALLBACK_DEFAULT_BRANCH) {
126
152
  const keystoreStepFor = (wf) => {
127
153
  if (!setup.keystore)
128
154
  return "";
@@ -331,9 +357,9 @@ ${googlePlayStep}
331
357
  echo "${releaseArtifactLabel}: \$artifact"
332
358
  done
333
359
  fi
334
- `;
360
+ ${triggerMapBlock(defaultBranch)}`;
335
361
  }
336
- export function generateIosPipeline(projectPath, setup, variants, metaNamespace = 'cibuild.io') {
362
+ export function generateIosPipeline(projectPath, setup, variants, metaNamespace = 'cibuild.io', defaultBranch = FALLBACK_DEFAULT_BRANCH) {
337
363
  const { primary: pv, pullRequest: prv, release: rv } = variants;
338
364
  // Global scheme is the primary scheme (used as default across workflows)
339
365
  const globalScheme = pv.scheme;
@@ -508,7 +534,7 @@ ${appStoreDeployStep}
508
534
  if [ -n "\$CIBUILD_XCARCHIVE_PATH" ]; then
509
535
  echo "Archive: \$CIBUILD_XCARCHIVE_PATH"
510
536
  fi
511
- `;
537
+ ${triggerMapBlock(defaultBranch)}`;
512
538
  }
513
539
  /**
514
540
  * Prints a hint listing env vars / Gradle properties detected during scanning
@@ -771,7 +797,7 @@ async function handleIosBuildCommand(cwd, options = {}) {
771
797
  }
772
798
  }
773
799
  // 7. Generate and write the pipeline
774
- const yaml = generateIosPipeline(iosScanResult.projectPath, iosSetupOptions, iosVariants, options.metaNamespace);
800
+ const yaml = generateIosPipeline(iosScanResult.projectPath, iosSetupOptions, iosVariants, options.metaNamespace, detectDefaultBranch());
775
801
  writeFileSync(outputPath, yaml, "utf-8");
776
802
  console.log("\n✅ Generated .ci/pipelines/cibuild.yml");
777
803
  console.log(" Platform: iOS");
@@ -1042,7 +1068,7 @@ async function handleAndroidBuildCommand(cwd, options, cacheTechnology) {
1042
1068
  // that exact JDK — a newer JDK can cross-compile. Enforce a minimum of 17
1043
1069
  // since ubuntu-latest runners ship with JDK 17+ and JDK <17 is unavailable.
1044
1070
  const javaVersion = Math.max(scanResult.detectedJavaVersion ?? 17, 17);
1045
- const yaml = generateAndroidPipeline(javaVersion, setupOptions, variants, cacheTechnology, options.metaNamespace);
1071
+ const yaml = generateAndroidPipeline(javaVersion, setupOptions, variants, cacheTechnology, options.metaNamespace, detectDefaultBranch());
1046
1072
  writeFileSync(outputPath, yaml, "utf-8");
1047
1073
  console.log("\n✅ Generated .ci/pipelines/cibuild.yml");
1048
1074
  console.log(` Platform: ${platformLabel}`);
@@ -10,7 +10,9 @@
10
10
  * `metaNamespace: 'invarn'` and get `meta.invarn:`.
11
11
  */
12
12
  import { describe, test, expect } from '@jest/globals';
13
+ import { load } from 'js-yaml';
13
14
  import { generateIosPipeline, generateAndroidPipeline, } from './build.js';
15
+ const parse = (yaml) => load(yaml);
14
16
  const iosSetup = {
15
17
  cocoaPods: false,
16
18
  codeSigning: false,
@@ -56,4 +58,64 @@ describe('generateAndroidPipeline — meta namespace', () => {
56
58
  expect(yaml).not.toContain('meta:\n cibuild.io:\n');
57
59
  });
58
60
  });
61
+ /**
62
+ * A generated pipeline with no `trigger_map` is inert on the Invarn side:
63
+ * the webhook handler skips any pipeline whose YAML has none, so a repo
64
+ * scaffolded by `ci build` receives pushes and builds nothing, with no
65
+ * error anywhere to explain it.
66
+ *
67
+ * Both generators emit `primary`, `pull-request` and `release`. Pushes go to
68
+ * `primary`, pull requests to `pull-request`, and `release` stays manual —
69
+ * it deploys to Google Play / App Store and must never fire off a push.
70
+ */
71
+ describe.each([
72
+ ['generateIosPipeline', (branch) => generateIosPipeline('./MyApp', iosSetup, iosVariants, 'cibuild.io', branch)],
73
+ ['generateAndroidPipeline', (branch) => generateAndroidPipeline(17, undefined, undefined, 'gradle', 'cibuild.io', branch)],
74
+ ])('%s — trigger_map', (_name, generate) => {
75
+ test('emits a trigger_map', () => {
76
+ const doc = parse(generate());
77
+ expect(Array.isArray(doc.trigger_map)).toBe(true);
78
+ expect(doc.trigger_map.length).toBeGreaterThan(0);
79
+ });
80
+ test('every rule names a workflow the pipeline actually declares', () => {
81
+ const doc = parse(generate());
82
+ const declared = Object.keys(doc.workflows ?? {});
83
+ for (const rule of doc.trigger_map) {
84
+ expect(declared).toContain(rule.workflow);
85
+ }
86
+ });
87
+ test('routes a push to primary and a pull request to pull-request', () => {
88
+ const doc = parse(generate());
89
+ const push = doc.trigger_map.find((r) => r.push_branch !== undefined);
90
+ const pr = doc.trigger_map.find((r) => r.pull_request_target_branch !== undefined);
91
+ expect(push?.workflow).toBe('primary');
92
+ expect(pr?.workflow).toBe('pull-request');
93
+ });
94
+ test('never fires release off a webhook', () => {
95
+ const doc = parse(generate());
96
+ expect(doc.trigger_map.map((r) => r.workflow)).not.toContain('release');
97
+ });
98
+ test('defaults the push branch to main', () => {
99
+ const doc = parse(generate());
100
+ const push = doc.trigger_map.find((r) => r.push_branch !== undefined);
101
+ expect(push?.push_branch).toBe('main');
102
+ });
103
+ test('keys the push branch to the branch it is given', () => {
104
+ const doc = parse(generate('develop'));
105
+ const push = doc.trigger_map.find((r) => r.push_branch !== undefined);
106
+ expect(push?.push_branch).toBe('develop');
107
+ });
108
+ test('survives a branch name containing a slash', () => {
109
+ const doc = parse(generate('release/1.0'));
110
+ const push = doc.trigger_map.find((r) => r.push_branch !== undefined);
111
+ expect(push?.push_branch).toBe('release/1.0');
112
+ });
113
+ test('still parses when the branch name would otherwise read as a YAML bool', () => {
114
+ // `push_branch: no` parses as `false` unquoted. Git allows a branch
115
+ // called `no`, so the value has to be quoted on the way out.
116
+ const doc = parse(generate('no'));
117
+ const push = doc.trigger_map.find((r) => r.push_branch !== undefined);
118
+ expect(push?.push_branch).toBe('no');
119
+ });
120
+ });
59
121
  //# sourceMappingURL=build.test.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Git probes used while scaffolding a pipeline.
3
+ *
4
+ * Scaffolding runs inside the user's checkout, so the repository itself is
5
+ * the best available source of truth for values the generated YAML has to
6
+ * hardcode. Everything here is best-effort: a scaffold must still succeed in
7
+ * a directory that is not a git repository at all.
8
+ */
9
+ /** What we key a `trigger_map` to when git can't tell us anything better. */
10
+ export declare const FALLBACK_DEFAULT_BRANCH = "main";
11
+ /**
12
+ * The branch a generated `trigger_map` should build on push.
13
+ *
14
+ * Order matters. The remote's HEAD is what GitHub calls the repository's
15
+ * default branch, and it is what the webhook will report on a merge — so it
16
+ * wins over whatever happens to be checked out. Only when there is no remote
17
+ * (a repo that has not been pushed anywhere yet) do we fall back to the
18
+ * current branch, and only when that is unavailable too — no repo, or a
19
+ * detached HEAD — do we guess.
20
+ *
21
+ * Guessing wrong is not silent: the pipeline is written to disk where the
22
+ * user can read and correct the branch before committing it.
23
+ */
24
+ export declare function detectDefaultBranch(cwd?: string): string;
25
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../src/shared/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,SAAS,CAAC;AAc9C;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAevE"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Git probes used while scaffolding a pipeline.
3
+ *
4
+ * Scaffolding runs inside the user's checkout, so the repository itself is
5
+ * the best available source of truth for values the generated YAML has to
6
+ * hardcode. Everything here is best-effort: a scaffold must still succeed in
7
+ * a directory that is not a git repository at all.
8
+ */
9
+ import { execFileSync } from 'node:child_process';
10
+ /** What we key a `trigger_map` to when git can't tell us anything better. */
11
+ export const FALLBACK_DEFAULT_BRANCH = 'main';
12
+ function git(cwd, args) {
13
+ try {
14
+ return execFileSync('git', args, {
15
+ cwd,
16
+ encoding: 'utf8',
17
+ stdio: ['ignore', 'pipe', 'ignore'],
18
+ }).trim();
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ /**
25
+ * The branch a generated `trigger_map` should build on push.
26
+ *
27
+ * Order matters. The remote's HEAD is what GitHub calls the repository's
28
+ * default branch, and it is what the webhook will report on a merge — so it
29
+ * wins over whatever happens to be checked out. Only when there is no remote
30
+ * (a repo that has not been pushed anywhere yet) do we fall back to the
31
+ * current branch, and only when that is unavailable too — no repo, or a
32
+ * detached HEAD — do we guess.
33
+ *
34
+ * Guessing wrong is not silent: the pipeline is written to disk where the
35
+ * user can read and correct the branch before committing it.
36
+ */
37
+ export function detectDefaultBranch(cwd = process.cwd()) {
38
+ // `origin/main` → `main`. Absent unless the remote HEAD ref is set locally,
39
+ // which `git clone` does and `git init` does not.
40
+ const remoteHead = git(cwd, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']);
41
+ if (remoteHead) {
42
+ const branch = remoteHead.replace(/^origin\//, '').trim();
43
+ if (branch)
44
+ return branch;
45
+ }
46
+ // `--abbrev-ref HEAD` answers the literal string "HEAD" on a detached
47
+ // checkout, which is not a branch name and must not become one.
48
+ const current = git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']);
49
+ if (current && current !== 'HEAD')
50
+ return current;
51
+ return FALLBACK_DEFAULT_BRANCH;
52
+ }
53
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Unit tests for the default-branch probe.
3
+ *
4
+ * The probe shells out to git, so these drive it against real throwaway
5
+ * repositories in a temp dir rather than mocking child_process — the whole
6
+ * point of the helper is that it agrees with what git actually reports.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=git.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.test.d.ts","sourceRoot":"","sources":["../../../src/shared/git.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Unit tests for the default-branch probe.
3
+ *
4
+ * The probe shells out to git, so these drive it against real throwaway
5
+ * repositories in a temp dir rather than mocking child_process — the whole
6
+ * point of the helper is that it agrees with what git actually reports.
7
+ */
8
+ import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
9
+ import { execFileSync } from 'node:child_process';
10
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
11
+ import { tmpdir } from 'node:os';
12
+ import { join } from 'node:path';
13
+ import { detectDefaultBranch } from './git.js';
14
+ function git(cwd, ...args) {
15
+ execFileSync('git', args, { cwd, stdio: 'ignore' });
16
+ }
17
+ /** A repo with one commit on `branch`, and no remote. */
18
+ function makeRepo(root, name, branch) {
19
+ const dir = join(root, name);
20
+ execFileSync('mkdir', ['-p', dir]);
21
+ git(dir, 'init', '--quiet', `--initial-branch=${branch}`);
22
+ git(dir, 'config', 'user.email', 'test@example.com');
23
+ git(dir, 'config', 'user.name', 'Test');
24
+ writeFileSync(join(dir, 'README.md'), '# test\n');
25
+ git(dir, 'add', 'README.md');
26
+ git(dir, 'commit', '--quiet', '-m', 'init');
27
+ return dir;
28
+ }
29
+ describe('detectDefaultBranch', () => {
30
+ let root;
31
+ beforeAll(() => {
32
+ root = mkdtempSync(join(tmpdir(), 'cibuild-git-'));
33
+ });
34
+ afterAll(() => {
35
+ rmSync(root, { recursive: true, force: true });
36
+ });
37
+ test('reads the current branch when there is no remote', () => {
38
+ expect(detectDefaultBranch(makeRepo(root, 'plain', 'main'))).toBe('main');
39
+ });
40
+ test('reads a non-main current branch', () => {
41
+ expect(detectDefaultBranch(makeRepo(root, 'legacy', 'master'))).toBe('master');
42
+ });
43
+ test('prefers the remote HEAD over the checked-out branch', () => {
44
+ // A clone sitting on a topic branch must still key its trigger to the
45
+ // branch the remote considers default — otherwise the generated pipeline
46
+ // would only ever build whatever branch happened to be checked out at
47
+ // scaffold time.
48
+ const origin = makeRepo(root, 'origin-repo', 'develop');
49
+ const clone = join(root, 'cloned');
50
+ execFileSync('git', ['clone', '--quiet', origin, clone], { stdio: 'ignore' });
51
+ git(clone, 'checkout', '--quiet', '-b', 'feature/whatever');
52
+ expect(detectDefaultBranch(clone)).toBe('develop');
53
+ });
54
+ test('falls back to main outside a git repository', () => {
55
+ const notARepo = join(root, 'bare-dir');
56
+ execFileSync('mkdir', ['-p', notARepo]);
57
+ expect(detectDefaultBranch(notARepo)).toBe('main');
58
+ });
59
+ test('falls back to main on a detached HEAD with no remote', () => {
60
+ const dir = makeRepo(root, 'detached', 'main');
61
+ const sha = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
62
+ git(dir, 'checkout', '--quiet', sha);
63
+ expect(detectDefaultBranch(dir)).toBe('main');
64
+ });
65
+ });
66
+ //# sourceMappingURL=git.test.js.map
@@ -42,6 +42,12 @@ export interface YAMLApp {
42
42
  export interface YAMLTrigger {
43
43
  push_branch?: string;
44
44
  pull_request_source_branch?: string;
45
+ /**
46
+ * The branch a pull request is opened *against*. Matched by Invarn's
47
+ * trigger resolver alongside the source branch, and what the generated
48
+ * scaffold uses — a `"*"` here means "any pull request".
49
+ */
50
+ pull_request_target_branch?: string;
45
51
  workflow?: string;
46
52
  }
47
53
  export interface YAMLPipeline {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/yaml/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AACzC,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAGD,MAAM,WAA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AI,CAAC,EAAE,UAAU,EAAE,CAAC;IACpB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAGD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;CACrB;AAGD,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;IAC5C,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;CAC7B;AAGD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAGD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invarn/cibuild",
3
- "version": "2.5.6",
3
+ "version": "2.5.8",
4
4
  "description": "CI Build CLI — local pipeline orchestration and validation",
5
5
  "type": "module",
6
6
  "main": "dist/cli.cjs",