@gebit/stax-cli 1.2.1 → 1.3.2

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 CHANGED
@@ -12,14 +12,18 @@ Generates a deploy wrapper and an empty stack list in a repository:
12
12
 
13
13
  | File | Content |
14
14
  |---|---|
15
- | `.github/workflows/deploy.yml` | Manual `Deploy` workflow calling `a-wf-setup-ci.yml` and `a-wf-deploy-levels.yml` from `GEBITSolutions/stax@main` |
16
- | `configs/default.yaml` | One commented `deployment` block listing every required deployment value with its GitHub variable (`deployment.project` live only when `--project` is given), `stacks: []`, commented examples and a `yaml-language-server` schema link for editor completion |
15
+ | `.github/workflows/deploy.yml` | Manual `Deploy` workflow calling `a-wf-setup-ci.yml` and `a-wf-deploy-levels.yml` from `GEBITSolutions/stax` at the installed CLI version, with matching `actions-version` inputs |
16
+ | `configs/default.yaml` | One commented `deployment` block listing every required deployment value with its GitHub variable (`deployment.project` live only when `--project` is given), `stacks: []`, commented examples and a `yaml-language-server` schema link for editor completion at the same version |
17
17
 
18
18
  ```bash
19
- stax init [directory] [--environment <github-environment>] [--project <name>] [--force]
19
+ stax init [directory] [--environment <github-environment>] [--project <name>] [--force] [--framework-ref <tag-or-commit-sha>]
20
20
  ```
21
21
 
22
- `stax init` needs no input and never prompts; both options are optional.
22
+ `stax init` never prompts. `--environment` and `--project` are optional.
23
+
24
+ The installed CLI version sets both reusable workflow refs, both `actions-version` inputs and the editor schema URL. Global and project-local installs use the same rule. Use a CLI release that matches the framework version you deploy; `init` does not update existing configs or workflows.
25
+
26
+ `--framework-ref` is required only for a development build (`0.0.0-development`). Give it a tag, commit SHA or branch, including `main` if you choose to track it explicitly. Development builds do not default to `main`. Published CLI releases reject `--framework-ref` and use their own exact version.
23
27
 
24
28
  - `--environment`: default GitHub Environment preselected in the deploy form. Without it, the form has no preselection.
25
29
  - `--project`: lowercase letters, digits and hyphens, starting with a letter. Saved as `deployment.project` in `configs/default.yaml`; without it, the GitHub variable `PROJECT` supplies the value.
@@ -48,10 +52,14 @@ stax add [directory] [--config <name>] [--name <stack name>] [--type <type>] [--
48
52
 
49
53
  The field list and examples come from the schema: each stack property lists the types that read it in `x-stax-types` (`"all"` for every type) and its example in `examples`.
50
54
 
55
+ `stax add` reads the schema bundled with the installed CLI. It works offline and does not fetch the editor schema URL in `configs/default.yaml`.
56
+
51
57
  ## `stax validate config`
52
58
 
53
59
  Checks deploy configs against the schema in [`schema/deploy-config.schema.json`](../schema/deploy-config.schema.json) and against the rules the pipeline enforces.
54
60
 
61
+ Validation reads the schema bundled with the installed CLI, not the editor schema URL. It works offline; match your installed CLI to the framework version you deploy.
62
+
55
63
  ```bash
56
64
  stax validate config # deploy configs directly in configs/
57
65
  stax validate config -r # ... and in its subdirectories
@@ -88,6 +96,8 @@ npm run build
88
96
  npm run sync-schema && node src/cli.ts validate config ../path/to/configs # runs from source (Node 24 type stripping)
89
97
  ```
90
98
 
99
+ For a development build, choose a framework ref when initializing a project, for example `node src/cli.ts init ../my-project --framework-ref main` (or `stax init ../my-project --framework-ref main` after `npm link`). A released CLI needs no ref and rejects this option.
100
+
91
101
  ## Releasing
92
102
 
93
103
  The CLI is released together with the reusable workflows, under the same version. [`release.yml`](../.github/workflows/release.yml) runs on every push to `main` and composes the `a-wf-release-*` phase workflows:
package/dist/cli.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
3
  import { join, relative, resolve } from "node:path";
5
4
  import { input, select } from "@inquirer/prompts";
6
5
  import { Command } from "commander";
@@ -9,7 +8,7 @@ import { schema, STACK_TYPES, requiredStackFields, stackFieldProblem } from "./s
9
8
  import { DEPLOY_CONFIG_PATH, renderProject, validateEnvironment, validateProject } from "./templates.js";
10
9
  import { collectConfigFiles, isDeployConfigText, validateConfigText } from "./validate.js";
11
10
  import { writeProject } from "./write.js";
12
- const { version } = createRequire(import.meta.url)("../package.json");
11
+ import { packageVersion, resolveFrameworkRef } from "./version.js";
13
12
  /**
14
13
  * Command-line values win; missing values are prompted for on a terminal and are an
15
14
  * error otherwise, so scripted runs never hang on a prompt.
@@ -34,13 +33,14 @@ async function resolveValue(question) {
34
33
  const program = new Command()
35
34
  .name("stax")
36
35
  .description("Scaffold, extend and validate projects for the stax stack framework")
37
- .version(version);
36
+ .version(packageVersion);
38
37
  program
39
38
  .command("init")
40
39
  .description("Generate the deploy workflow and default deploy config in a repository")
41
40
  .argument("[directory]", "repository root to write into", ".")
42
41
  .option("-p, --project <name>", "optional deployment.project; otherwise the GitHub variable PROJECT supplies it")
43
42
  .option("-e, --environment <name>", "optional default GitHub Environment of the deploy form")
43
+ .option("--framework-ref <ref>", "framework tag, commit SHA or branch (required for development builds only)")
44
44
  .option("-f, --force", "overwrite existing files", false)
45
45
  .action(async (directory, flags) => {
46
46
  const problems = [
@@ -51,7 +51,8 @@ program
51
51
  throw new Error(problems.join("\n"));
52
52
  const { environment } = flags;
53
53
  const root = resolve(directory);
54
- const files = renderProject({ project: flags.project, environment });
54
+ const frameworkRef = resolveFrameworkRef(packageVersion, flags.frameworkRef);
55
+ const files = renderProject({ project: flags.project, environment }, frameworkRef);
55
56
  await writeProject(root, files, flags.force);
56
57
  for (const file of files)
57
58
  console.log(`created ${file.path}`);
package/dist/templates.js CHANGED
@@ -1,11 +1,6 @@
1
- /**
2
- * Reusable workflows the generated wrapper calls. Unpinned until stax publishes releases.
3
- */
4
1
  export const WORKFLOW_REPOSITORY = "GEBITSolutions/stax";
5
- export const WORKFLOW_REF = "main";
6
2
  export const DEPLOY_WORKFLOW_PATH = ".github/workflows/deploy.yml";
7
3
  export const DEPLOY_CONFIG_PATH = "configs/default.yaml";
8
- export const DEPLOY_CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/GEBITSolutions/stax/main/schema/deploy-config.schema.json";
9
4
  const PROJECT_PATTERN = /^[a-z][a-z0-9-]*$/;
10
5
  const ENVIRONMENT_PATTERN = /^[A-Za-z0-9._-]+$/;
11
6
  /** Returns an error message, or undefined when the project name is valid. */
@@ -57,8 +52,8 @@ function renderDeploymentBlock(project) {
57
52
  const lines = rows.map(({ prefix, entry, note }) => `${(prefix + entry).padEnd(width)} # ${note}`);
58
53
  return [project === undefined ? "# deployment:" : "deployment:", ...lines].join("\n");
59
54
  }
60
- function renderDeployConfig({ project, environment }) {
61
- return `# yaml-language-server: $schema=${DEPLOY_CONFIG_SCHEMA_URL}
55
+ function renderDeployConfig({ project, environment }, frameworkRef) {
56
+ return `# yaml-language-server: $schema=https://raw.githubusercontent.com/${WORKFLOW_REPOSITORY}/${encodeURIComponent(frameworkRef)}/schema/deploy-config.schema.json
62
57
  # Deploy configuration read by the Deploy workflow (deploy-config input "default").
63
58
  # Nothing is deployed until at least one stack is defined. Add one with: stax add
64
59
  # Check the file with: stax validate config
@@ -95,7 +90,7 @@ stacks: []
95
90
  # - global.pipeline.var.stage
96
91
  `;
97
92
  }
98
- export function renderProject(values) {
93
+ export function renderProject(values, frameworkRef) {
99
94
  const { environment } = values;
100
95
  const workflowPrefix = `${WORKFLOW_REPOSITORY}/.github/workflows`;
101
96
  const deployWorkflow = `name: Deploy
@@ -141,9 +136,10 @@ concurrency:
141
136
  jobs:
142
137
  setup:
143
138
  name: Setup CI/CD
144
- uses: ${workflowPrefix}/a-wf-setup-ci.yml@${WORKFLOW_REF}
139
+ uses: ${workflowPrefix}/a-wf-setup-ci.yml@${frameworkRef}
145
140
  secrets: inherit
146
141
  with:
142
+ actions-version: ${JSON.stringify(frameworkRef)}
147
143
  environment: \${{ inputs.environment }}
148
144
  stack_filter: \${{ inputs.stack-filter }}
149
145
  dry-run: \${{ inputs.dry-run }}
@@ -154,9 +150,10 @@ jobs:
154
150
  deploy-levels:
155
151
  name: Deploy Levels
156
152
  needs: setup
157
- uses: ${workflowPrefix}/a-wf-deploy-levels.yml@${WORKFLOW_REF}
153
+ uses: ${workflowPrefix}/a-wf-deploy-levels.yml@${frameworkRef}
158
154
  secrets: inherit
159
155
  with:
156
+ actions-version: ${JSON.stringify(frameworkRef)}
160
157
  ci_config: \${{ needs.setup.outputs.ci-config }}
161
158
  env: \${{ needs.setup.outputs.env }}
162
159
  default_location: \${{ needs.setup.outputs.default-location }}
@@ -164,6 +161,6 @@ jobs:
164
161
  `;
165
162
  return [
166
163
  { path: DEPLOY_WORKFLOW_PATH, content: deployWorkflow },
167
- { path: DEPLOY_CONFIG_PATH, content: renderDeployConfig(values) },
164
+ { path: DEPLOY_CONFIG_PATH, content: renderDeployConfig(values, frameworkRef) },
168
165
  ];
169
166
  }
@@ -0,0 +1,23 @@
1
+ import { createRequire } from "node:module";
2
+ export const { version: packageVersion } = createRequire(import.meta.url)("../package.json");
3
+ const RELEASE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
4
+ /** A development checkout has no release tag; choosing a framework ref must be explicit. */
5
+ export function resolveFrameworkRef(version, frameworkRef) {
6
+ if (version !== "0.0.0-development") {
7
+ if (!RELEASE_VERSION.test(version))
8
+ throw new Error(`invalid CLI release version "${version}"`);
9
+ if (frameworkRef !== undefined)
10
+ throw new Error("--framework-ref is only available in development builds");
11
+ return version;
12
+ }
13
+ if (frameworkRef === undefined) {
14
+ throw new Error("Development CLI has no matching framework release. Run init with --framework-ref <tag-or-commit-sha>.");
15
+ }
16
+ // Keep refs safe in workflow scalars and reject Git's ambiguous/invalid path forms.
17
+ if (!/^[A-Za-z0-9][A-Za-z0-9._/+\-]*$/.test(frameworkRef) ||
18
+ frameworkRef.includes("..") ||
19
+ frameworkRef.split("/").some((part) => part === "" || part.startsWith(".") || part.endsWith(".") || part.endsWith(".lock"))) {
20
+ throw new Error(`invalid framework ref "${frameworkRef}": use a tag, commit SHA or branch name`);
21
+ }
22
+ return frameworkRef;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gebit/stax-cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.2",
4
4
  "description": "Scaffold, extend and validate projects for the stax stack framework",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",