@otwld/nx-argo 0.0.5 → 0.0.7

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +18 -61
  3. package/generators.json +8 -13
  4. package/package.json +1 -1
  5. package/src/executors/validate/schema.d.ts +5 -1
  6. package/src/executors/validate/schema.json +14 -3
  7. package/src/executors/validate/validate.d.ts +1 -1
  8. package/src/executors/validate/validate.js +164 -14
  9. package/src/executors/write-artifact-lock/schema.d.ts +8 -0
  10. package/src/executors/write-artifact-lock/schema.json +29 -1
  11. package/src/executors/write-artifact-lock/write-artifact-lock.d.ts +1 -1
  12. package/src/executors/write-artifact-lock/write-artifact-lock.js +128 -16
  13. package/src/generators/environment-project/environment-project.d.ts +4 -0
  14. package/src/generators/{service-application/service-application.js → environment-project/environment-project.js} +13 -9
  15. package/src/generators/environment-project/schema.d.ts +13 -0
  16. package/src/generators/{service-application → environment-project}/schema.json +7 -11
  17. package/src/generators/preview-project/preview-project.d.ts +4 -0
  18. package/src/generators/{preview-stack/preview-stack.js → preview-project/preview-project.js} +7 -8
  19. package/src/generators/{preview-stack → preview-project}/schema.d.ts +2 -4
  20. package/src/generators/{preview-stack → preview-project}/schema.json +2 -6
  21. package/src/index.d.ts +4 -6
  22. package/src/index.js +5 -7
  23. package/src/generators/application/application.d.ts +0 -9
  24. package/src/generators/application/application.js +0 -263
  25. package/src/generators/application/schema.d.ts +0 -27
  26. package/src/generators/application/schema.json +0 -97
  27. package/src/generators/preview-stack/preview-stack.d.ts +0 -4
  28. package/src/generators/service-application/schema.d.ts +0 -15
  29. package/src/generators/service-application/service-application.d.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## 0.0.7 (unreleased)
2
+
3
+ ### Fixes
4
+
5
+ - Require preview ApplicationSets to consume PR-scoped immutable locks last.
6
+
7
+ ## 0.0.6 (2026-08-12)
8
+
9
+ ### Breaking changes
10
+
11
+ - Replace `application`, `service-application`, and `preview-stack` with `environment-project` and `preview-project`.
12
+ - Validate project-local environment locks and preview ApplicationSets; artifact writes are revision-idempotent.
13
+
14
+ ## 0.0.5 (2026-08-12)
15
+
16
+ ### 🚀 Features
17
+
18
+ - **argo:** add GitOps project tooling ([b291a720](https://github.com/otwld/devops/commit/b291a720))
19
+
20
+ ### ❤️ Thank You
21
+
22
+ - Tréhout Nathan
23
+
1
24
  ## 0.0.4 (2026-08-12)
2
25
 
3
26
  ### 🚀 Features
package/README.md CHANGED
@@ -1,80 +1,37 @@
1
1
  # @otwld/nx-argo
2
2
 
3
- Nx generator for Argo CD Applications and Helm values files.
3
+ Nx contract tooling for GitOps projects. It does not create or operate Argo CD resources.
4
4
 
5
- ## GitOps Projects
5
+ ## Generators
6
6
 
7
- `service-application` creates a GitOps project for one workload and
8
- environment. It records the deployment service key, depends only on its owning
9
- app, and creates separate human-owned `values.yaml` and automation-owned
10
- `artifacts.yaml` files.
7
+ `environment-project` creates `gitops/environments/<service>/<environment>` with:
8
+
9
+ - `project.json`: `gitops-<service>-<environment>`, one owning app dependency, delivery metadata, validation, and uncached artifact writes.
10
+ - `values.yaml`: human-owned configuration.
11
+ - `artifacts.yaml`: automation-owned immutable artifact lock.
11
12
 
12
13
  ```shell
13
- pnpm exec nx g @otwld/nx-argo:service-application frontend \
14
- --environment=staging \
15
- --app=frontend
14
+ pnpm exec nx g @otwld/nx-argo:environment-project frontend \
15
+ --environment=staging --app=frontend
16
16
  ```
17
17
 
18
- `preview-stack` creates an explicit multi-workload preview boundary. The
19
- declared apps are the only Nx dependencies; Argo CD resources remain entirely
20
- user-defined.
18
+ `preview-project` creates `gitops/previews/<name>/project.json` with explicit app dependencies and `delivery.previewStack`. It creates no PR-specific lock. Add `application-set.yaml` before running validation.
21
19
 
22
20
  ```shell
23
- pnpm exec nx g @otwld/nx-argo:preview-stack web \
21
+ pnpm exec nx g @otwld/nx-argo:preview-project web \
24
22
  --apps=frontend,backend
25
23
  ```
26
24
 
27
- Generated GitOps projects use `validate` and `write-artifact-lock` targets.
28
- The latter writes one immutable image repository and digest to paths declared
29
- by project metadata. It does not publish images, invoke Argo CD, or interpret
30
- Kubernetes resources.
31
-
32
- ## Generate an Application
33
-
34
- ```shell
35
- pnpm exec nx g @otwld/nx-argo:application \
36
- --directory=deployments/service/development \
37
- --name=service-development \
38
- --chart=service \
39
- --chartRepository=oci://registry.example.com/charts \
40
- --chartVersion=0.1.0 \
41
- --valuesRepoUrl=https://github.com/example/config.git \
42
- --valuesRevision=main \
43
- --project=default \
44
- --destinationServer=https://kubernetes.default.svc \
45
- --namespace=service-development
46
- ```
25
+ ## Contracts
47
26
 
48
- The generator writes `application.yaml` and `values.yaml` to `--directory`.
27
+ Environment validation accepts either a pending or completed `artifacts.yaml`. A pending lock has `artifact.pending: true` and exactly empty string values for `image.repository`, `image.digest`, `artifact.service`, and `artifact.sourceRevision`. A completed lock has `artifact.pending: false` (or no pending field), a nonempty repository/service/source revision, and an immutable digest. An optional `application.yaml` must be an Argo CD `Application`; when it declares Helm value files, `artifacts.yaml` is last.
49
28
 
50
- ```yaml
51
- spec:
52
- sources:
53
- - repoURL: registry.example.com/charts
54
- chart: service
55
- targetRevision: 0.1.0
56
- helm:
57
- releaseName: service
58
- valueFiles:
59
- - $values/deployments/service/development/values.yaml
60
- - repoURL: https://github.com/example/config.git
61
- targetRevision: main
62
- ref: values
63
- ```
29
+ Preview validation requires an Argo CD `ApplicationSet` at `application-set.yaml`, a PR generator, a literal nonempty template project, enabled automated sync with `prune` and `selfHeal`, and no `preserveResourcesOnDeletion`.
64
30
 
65
- The values repository URL must use HTTPS. Chart repositories may use HTTP(S) or
66
- OCI URLs; `oci://` is removed from OCI chart-source URLs.
31
+ `write-artifact-lock` requires an existing project-local lock and accepts image repository/digest plus service/source revision values. It converts a valid pending lock to `artifact.pending: false`, advances a new revision, and only verifies identical service, repository, and digest for an existing revision.
67
32
 
68
33
  ## Package Targets
69
34
 
70
- - `nx build nx-argo`
71
- - `nx lint nx-argo`
72
- - `nx test nx-argo`
73
-
74
- ## npm Release
75
-
76
- ```shell
77
- pnpm exec nx release version --groups=npm --first-release --dry-run
78
- pnpm exec nx release publish --groups=npm --first-release --dry-run --access=public
79
- pnpm exec nx release --groups=npm --first-release
80
- ```
35
+ - `pnpm exec nx build nx-argo`
36
+ - `pnpm exec nx lint nx-argo`
37
+ - `pnpm exec nx test nx-argo`
package/generators.json CHANGED
@@ -1,20 +1,15 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "generators": {
4
- "application": {
5
- "factory": "./src/generators/application/application",
6
- "schema": "./src/generators/application/schema.json",
7
- "description": "Create an Argo CD Application and its Helm values file."
4
+ "environment-project": {
5
+ "factory": "./src/generators/environment-project/environment-project",
6
+ "schema": "./src/generators/environment-project/schema.json",
7
+ "description": "Create a GitOps project boundary for one service environment."
8
8
  },
9
- "service-application": {
10
- "factory": "./src/generators/service-application/service-application",
11
- "schema": "./src/generators/service-application/schema.json",
12
- "description": "Create a GitOps Application project for one workload."
13
- },
14
- "preview-stack": {
15
- "factory": "./src/generators/preview-stack/preview-stack",
16
- "schema": "./src/generators/preview-stack/schema.json",
17
- "description": "Create a GitOps preview stack project for multiple workloads."
9
+ "preview-project": {
10
+ "factory": "./src/generators/preview-project/preview-project",
11
+ "schema": "./src/generators/preview-project/schema.json",
12
+ "description": "Create a GitOps project boundary for an explicit preview stack."
18
13
  }
19
14
  }
20
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otwld/nx-argo",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -1,7 +1,11 @@
1
1
  /** Options accepted by the Argo CD validation executor. */
2
2
  export interface ValidateExecutorSchema {
3
- /** Application manifest relative to the owning Nx project root. */
3
+ /** GitOps project contract to validate. */
4
+ mode: 'environment' | 'preview';
5
+ /** Optional Application manifest relative to the owning Nx project root. */
4
6
  applicationFile?: string;
7
+ /** ApplicationSet manifest relative to the owning Nx project root. */
8
+ applicationSetFile?: string;
5
9
  /** Artifact lock file relative to the owning Nx project root. */
6
10
  artifactsFile?: string;
7
11
  }
@@ -2,16 +2,27 @@
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "version": 2,
4
4
  "title": "Validate Argo CD configuration",
5
- "description": "Validate optional Argo CD Application and artifact lock files.",
5
+ "description": "Validate a GitOps environment or preview project contract.",
6
6
  "type": "object",
7
7
  "properties": {
8
+ "mode": {
9
+ "type": "string",
10
+ "enum": ["environment", "preview"],
11
+ "description": "GitOps project contract to validate."
12
+ },
8
13
  "applicationFile": {
9
14
  "type": "string",
10
- "description": "Application manifest relative to the owning Nx project root."
15
+ "description": "Optional Application manifest relative to the owning Nx project root."
16
+ },
17
+ "applicationSetFile": {
18
+ "type": "string",
19
+ "description": "ApplicationSet manifest relative to the owning Nx project root."
11
20
  },
12
21
  "artifactsFile": {
13
22
  "type": "string",
14
23
  "description": "Artifact lock file relative to the owning Nx project root."
15
24
  }
16
- }
25
+ },
26
+ "required": ["mode"],
27
+ "additionalProperties": false
17
28
  }
@@ -1,5 +1,5 @@
1
1
  import type { PromiseExecutor } from '@nx/devkit';
2
2
  import type { ValidateExecutorSchema } from './schema';
3
- /** Validates optional Argo CD Application and artifact lock documents. */
3
+ /** Validates the declared Argo CD resources and artifact lock for one project. */
4
4
  declare const runExecutor: PromiseExecutor<ValidateExecutorSchema>;
5
5
  export default runExecutor;
@@ -3,38 +3,188 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_fs_1 = require("node:fs");
4
4
  const node_path_1 = require("node:path");
5
5
  const yaml_1 = require("yaml");
6
- /** Validates optional Argo CD Application and artifact lock documents. */
6
+ /** Validates the declared Argo CD resources and artifact lock for one project. */
7
7
  const runExecutor = async (options, context) => {
8
8
  const projectRoot = context.projectsConfigurations?.projects[context.projectName ?? '']?.root;
9
9
  if (!projectRoot) {
10
10
  throw new Error('[nx-argo] Validation requires an Nx project context.');
11
11
  }
12
12
  const root = (0, node_path_1.resolve)(context.root, projectRoot);
13
- validateApplication((0, node_path_1.resolve)(root, options.applicationFile || 'application.yaml'));
14
- validateArtifacts((0, node_path_1.resolve)(root, options.artifactsFile || 'artifacts.yaml'));
13
+ if (options.mode === 'environment') {
14
+ validateArtifacts(resolveProjectFile(root, options.artifactsFile, 'artifactsFile'));
15
+ if (options.applicationFile) {
16
+ validateApplication(resolveProjectFile(root, options.applicationFile, 'applicationFile'));
17
+ }
18
+ }
19
+ else {
20
+ validateApplicationSet(resolveProjectFile(root, options.applicationSetFile, 'applicationSetFile'));
21
+ }
15
22
  return { success: true };
16
23
  };
17
- /** Validates an Application document when it is present. */
18
- function validateApplication(filePath) {
24
+ /** Resolves a required project-local file without accepting path escapes. */
25
+ function resolveProjectFile(root, file, optionName) {
26
+ if (!file?.trim()) {
27
+ throw new Error(`[nx-argo] ${optionName} is required.`);
28
+ }
29
+ if ((0, node_path_1.isAbsolute)(file) || file.split(/[\\/]+/).includes('..')) {
30
+ throw new Error(`[nx-argo] ${optionName} must stay within the project root.`);
31
+ }
32
+ const filePath = (0, node_path_1.resolve)(root, file);
33
+ const pathFromRoot = (0, node_path_1.relative)(root, filePath);
34
+ if (!pathFromRoot ||
35
+ pathFromRoot === '..' ||
36
+ pathFromRoot.startsWith(`..${node_path_1.sep}`) ||
37
+ (0, node_path_1.isAbsolute)(pathFromRoot)) {
38
+ throw new Error(`[nx-argo] ${optionName} must stay within the project root.`);
39
+ }
40
+ return filePath;
41
+ }
42
+ /** Parses an existing YAML mapping. */
43
+ function readMapping(filePath, label) {
19
44
  if (!(0, node_fs_1.existsSync)(filePath)) {
20
- return;
45
+ throw new Error(`[nx-argo] Required ${label} is missing: ${filePath}`);
21
46
  }
22
47
  const document = (0, yaml_1.parseDocument)((0, node_fs_1.readFileSync)(filePath, 'utf8'));
23
48
  if (document.errors.length ||
24
- document.get('apiVersion') !== 'argoproj.io/v1alpha1' ||
25
- document.get('kind') !== 'Application') {
49
+ !document.contents ||
50
+ !(0, yaml_1.isMap)(document.contents)) {
51
+ throw new Error(`[nx-argo] Invalid ${label}: ${filePath}`);
52
+ }
53
+ return document.toJS();
54
+ }
55
+ /** Validates an Application document. */
56
+ function validateApplication(filePath) {
57
+ const application = readMapping(filePath, 'Argo CD Application');
58
+ if (application['apiVersion'] !== 'argoproj.io/v1alpha1' ||
59
+ application['kind'] !== 'Application') {
26
60
  throw new Error(`[nx-argo] Invalid Argo CD Application: ${filePath}`);
27
61
  }
62
+ const valueFiles = getHelmValueFiles(application);
63
+ if (valueFiles.length &&
64
+ valueFiles.at(-1)?.split('/').at(-1) !== 'artifacts.yaml') {
65
+ throw new Error(`[nx-argo] artifacts.yaml must be the final Helm values file: ${filePath}`);
66
+ }
67
+ }
68
+ /** Finds Helm value file lists across single- and multi-source Applications. */
69
+ function getHelmValueFiles(application) {
70
+ const spec = getMapping(application, 'spec');
71
+ if (!spec) {
72
+ return [];
73
+ }
74
+ const sources = [
75
+ spec['source'],
76
+ ...(Array.isArray(spec['sources']) ? spec['sources'] : []),
77
+ ];
78
+ return sources.flatMap((source) => {
79
+ const helm = getMapping(source, 'helm');
80
+ const valueFiles = helm?.['valueFiles'];
81
+ return Array.isArray(valueFiles)
82
+ ? valueFiles.filter((file) => typeof file === 'string')
83
+ : [];
84
+ });
28
85
  }
29
- /** Validates that an artifact lock is a YAML mapping when it is present. */
86
+ /** Validates an ApplicationSet document needed by a preview project. */
87
+ function validateApplicationSet(filePath) {
88
+ const applicationSet = readMapping(filePath, 'Argo CD ApplicationSet');
89
+ if (applicationSet['apiVersion'] !== 'argoproj.io/v1alpha1' ||
90
+ applicationSet['kind'] !== 'ApplicationSet') {
91
+ throw new Error(`[nx-argo] Invalid Argo CD ApplicationSet: ${filePath}`);
92
+ }
93
+ const spec = getMapping(applicationSet, 'spec');
94
+ const template = getMapping(spec, 'template');
95
+ const templateSpec = getMapping(template, 'spec');
96
+ const project = templateSpec?.['project'];
97
+ const automated = getMapping(getMapping(templateSpec, 'syncPolicy'), 'automated');
98
+ if (!containsPullRequestGenerator(spec?.['generators']) ||
99
+ typeof project !== 'string' ||
100
+ !project.trim() ||
101
+ /{{|}}/.test(project) ||
102
+ automated?.['enabled'] !== true ||
103
+ automated['prune'] !== true ||
104
+ automated['selfHeal'] !== true ||
105
+ getMapping(spec, 'syncPolicy')?.['preserveResourcesOnDeletion'] === true ||
106
+ !hasArtifactLockLast(templateSpec)) {
107
+ throw new Error(`[nx-argo] Invalid preview ApplicationSet contract: ${filePath}`);
108
+ }
109
+ }
110
+ /** Requires the PR-specific immutable lock to be the final Helm values file. */
111
+ function hasArtifactLockLast(templateSpec) {
112
+ const sources = templateSpec?.['sources'];
113
+ if (!Array.isArray(sources)) {
114
+ return false;
115
+ }
116
+ return sources.some((source) => {
117
+ const valueFiles = getMapping(source, 'helm')?.['valueFiles'];
118
+ return (Array.isArray(valueFiles) &&
119
+ typeof valueFiles.at(-1) === 'string' &&
120
+ valueFiles.at(-1)?.includes('/locks/pr-'));
121
+ });
122
+ }
123
+ /** Recursively finds a non-null ApplicationSet pull request generator. */
124
+ function containsPullRequestGenerator(value) {
125
+ if (Array.isArray(value)) {
126
+ return value.some(containsPullRequestGenerator);
127
+ }
128
+ if (!isRecord(value)) {
129
+ return false;
130
+ }
131
+ if (isRecord(value['pullRequest'])) {
132
+ return true;
133
+ }
134
+ return Object.values(value).some(containsPullRequestGenerator);
135
+ }
136
+ /** Validates the complete artifact lock required by environment projects. */
30
137
  function validateArtifacts(filePath) {
31
- if (!(0, node_fs_1.existsSync)(filePath)) {
32
- return;
138
+ const artifacts = readMapping(filePath, 'artifact lock');
139
+ const pending = getPath(artifacts, ['artifact', 'pending']);
140
+ const values = [
141
+ getPath(artifacts, ['image', 'repository']),
142
+ getPath(artifacts, ['image', 'digest']),
143
+ getPath(artifacts, ['artifact', 'service']),
144
+ getPath(artifacts, ['artifact', 'sourceRevision']),
145
+ ];
146
+ if (pending === true) {
147
+ if (values.every((value) => value === '')) {
148
+ return;
149
+ }
150
+ throw new Error(`[nx-argo] Invalid pending artifact lock: ${filePath}`);
33
151
  }
34
- const document = (0, yaml_1.parseDocument)((0, node_fs_1.readFileSync)(filePath, 'utf8'));
35
- if (document.errors.length ||
36
- (document.contents && !(0, yaml_1.isMap)(document.contents))) {
152
+ if (pending !== undefined && pending !== false) {
37
153
  throw new Error(`[nx-argo] Invalid artifact lock: ${filePath}`);
38
154
  }
155
+ if (!isNonEmptyString(values[0]) ||
156
+ !isDigest(values[1]) ||
157
+ !isNonEmptyString(values[2]) ||
158
+ !isNonEmptyString(values[3])) {
159
+ throw new Error(`[nx-argo] Invalid artifact lock: ${filePath}`);
160
+ }
161
+ }
162
+ /** Reads a nested mapping value without treating non-mappings as paths. */
163
+ function getPath(root, path) {
164
+ let current = root;
165
+ for (const segment of path) {
166
+ if (!isRecord(current)) {
167
+ return undefined;
168
+ }
169
+ current = current[segment];
170
+ }
171
+ return current;
172
+ }
173
+ /** Returns a mapping when a value has the expected structural type. */
174
+ function getMapping(value, key) {
175
+ const candidate = key === undefined ? value : isRecord(value) ? value[key] : undefined;
176
+ return isRecord(candidate) ? candidate : undefined;
177
+ }
178
+ /** Narrows unknown YAML values to simple object mappings. */
179
+ function isRecord(value) {
180
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
181
+ }
182
+ /** Requires a non-empty string scalar. */
183
+ function isNonEmptyString(value) {
184
+ return typeof value === 'string' && Boolean(value.trim());
185
+ }
186
+ /** Validates an immutable SHA-256 image digest. */
187
+ function isDigest(value) {
188
+ return typeof value === 'string' && /^sha256:[a-f0-9]{64}$/.test(value);
39
189
  }
40
190
  exports.default = runExecutor;
@@ -6,6 +6,14 @@ export interface WriteArtifactLockExecutorSchema {
6
6
  repositoryPath: string;
7
7
  /** Dot-separated YAML path for the immutable image digest. */
8
8
  digestPath: string;
9
+ /** Dot-separated YAML path for the deployment service identity. */
10
+ servicePath: string;
11
+ /** Dot-separated YAML path for the source revision. */
12
+ sourceRevisionPath: string;
13
+ /** Deployment service identity to write. */
14
+ service: string;
15
+ /** Source revision that produced this immutable artifact. */
16
+ sourceRevision: string;
9
17
  /** Image repository to write. */
10
18
  repository: string;
11
19
  /** Immutable image digest to write. */
@@ -17,6 +17,24 @@
17
17
  "type": "string",
18
18
  "description": "Dot-separated YAML path for the immutable image digest."
19
19
  },
20
+ "servicePath": {
21
+ "type": "string",
22
+ "description": "Dot-separated YAML path for the deployment service identity."
23
+ },
24
+ "sourceRevisionPath": {
25
+ "type": "string",
26
+ "description": "Dot-separated YAML path for the source revision."
27
+ },
28
+ "service": {
29
+ "type": "string",
30
+ "description": "Deployment service identity to write.",
31
+ "minLength": 1
32
+ },
33
+ "sourceRevision": {
34
+ "type": "string",
35
+ "description": "Source revision that produced this immutable artifact.",
36
+ "minLength": 1
37
+ },
20
38
  "repository": {
21
39
  "type": "string",
22
40
  "description": "Image repository to write."
@@ -27,6 +45,16 @@
27
45
  "pattern": "^sha256:[a-f0-9]{64}$"
28
46
  }
29
47
  },
30
- "required": ["file", "repositoryPath", "digestPath", "repository", "digest"],
48
+ "required": [
49
+ "file",
50
+ "repositoryPath",
51
+ "digestPath",
52
+ "servicePath",
53
+ "sourceRevisionPath",
54
+ "service",
55
+ "sourceRevision",
56
+ "repository",
57
+ "digest"
58
+ ],
31
59
  "additionalProperties": false
32
60
  }
@@ -1,5 +1,5 @@
1
1
  import type { PromiseExecutor } from '@nx/devkit';
2
2
  import type { WriteArtifactLockExecutorSchema } from './schema';
3
- /** Writes an immutable image reference to declared paths in an artifact lock. */
3
+ /** Writes or verifies one immutable artifact lock for a source revision. */
4
4
  declare const runExecutor: PromiseExecutor<WriteArtifactLockExecutorSchema>;
5
5
  export default runExecutor;