@intentius/chant-lexicon-github 0.44.14 → 0.46.0
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/dist/codegen/docs.d.ts.map +1 -1
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/serializer.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/codegen/docs.ts +0 -1308
- package/src/serializer.test.ts +30 -0
- package/src/serializer.ts +14 -4
package/src/serializer.test.ts
CHANGED
|
@@ -180,6 +180,36 @@ describe("githubSerializer.serialize", () => {
|
|
|
180
180
|
expect(output).toContain("continue-on-error: true");
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
+
test("env / with map keys pass through verbatim (chant #1223)", () => {
|
|
184
|
+
const entities = new Map<string, Declarable>();
|
|
185
|
+
entities.set("workflow", new MockWorkflow({
|
|
186
|
+
name: "CI",
|
|
187
|
+
on: { push: null },
|
|
188
|
+
}));
|
|
189
|
+
entities.set("job", new MockJob({
|
|
190
|
+
"runs-on": "ubuntu-latest",
|
|
191
|
+
env: { CHANT_ENV: "pr-1", kubeConfigPath: "/tmp/kc" },
|
|
192
|
+
steps: [
|
|
193
|
+
new MockStep({
|
|
194
|
+
uses: "actions/setup-node@abc",
|
|
195
|
+
with: { "node-version": "22", checkLatest: "true" },
|
|
196
|
+
env: { GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" },
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
const output = githubSerializer.serialize(entities) as string;
|
|
202
|
+
// Env var names are user identifiers — kebab-casing renames what the
|
|
203
|
+
// script reads. They must survive exactly as written.
|
|
204
|
+
expect(output).toContain("CHANT_ENV: pr-1");
|
|
205
|
+
expect(output).toContain("kubeConfigPath: /tmp/kc");
|
|
206
|
+
expect(output).toContain("GH_TOKEN:");
|
|
207
|
+
// Action inputs are the action's declared names, also not chant's to touch.
|
|
208
|
+
expect(output).toContain("checkLatest: 'true'");
|
|
209
|
+
expect(output).not.toContain("gh-token");
|
|
210
|
+
expect(output).not.toContain("chant-env");
|
|
211
|
+
});
|
|
212
|
+
|
|
183
213
|
test("serializes trigger entities", () => {
|
|
184
214
|
const entities = new Map<string, Declarable>();
|
|
185
215
|
entities.set("workflow", new MockWorkflow({
|
package/src/serializer.ts
CHANGED
|
@@ -183,6 +183,15 @@ function buildStandaloneJobsSection(
|
|
|
183
183
|
|
|
184
184
|
// ── Key conversion for YAML output ────────────────────────────────
|
|
185
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Map keys whose entries are user-named, not schema properties. `env` names
|
|
188
|
+
* environment variables (`KUBECONFIG_DATA` must stay `KUBECONFIG_DATA`, not
|
|
189
|
+
* become `kubeconfig_data`), `with` names an action's declared inputs,
|
|
190
|
+
* `outputs`/`secrets`/`variables` name user identifiers referenced elsewhere
|
|
191
|
+
* by exact spelling. Kebab-casing inside these silently renames them.
|
|
192
|
+
*/
|
|
193
|
+
const VERBATIM_KEY_MAPS = new Set(["env", "with", "outputs", "secrets", "variables"]);
|
|
194
|
+
|
|
186
195
|
/**
|
|
187
196
|
* Convert a props object keys from camelCase to kebab-case for job/step properties.
|
|
188
197
|
*/
|
|
@@ -192,21 +201,22 @@ function convertKeys(obj: Record<string, unknown>): Record<string, unknown> {
|
|
|
192
201
|
if (value === undefined || value === null) continue;
|
|
193
202
|
// Zero and false are valid values, but undefined/null should be omitted
|
|
194
203
|
const yamlKey = toKebabCase(key);
|
|
195
|
-
result[yamlKey] = convertValueKeys(value);
|
|
204
|
+
result[yamlKey] = convertValueKeys(value, VERBATIM_KEY_MAPS.has(yamlKey));
|
|
196
205
|
}
|
|
197
206
|
return result;
|
|
198
207
|
}
|
|
199
208
|
|
|
200
|
-
function convertValueKeys(value: unknown): unknown {
|
|
209
|
+
function convertValueKeys(value: unknown, verbatim = false): unknown {
|
|
201
210
|
if (value === null || value === undefined) return value;
|
|
202
211
|
if (typeof value !== "object") return value;
|
|
203
|
-
if (Array.isArray(value)) return value.map(convertValueKeys);
|
|
212
|
+
if (Array.isArray(value)) return value.map((v) => convertValueKeys(v, verbatim));
|
|
204
213
|
|
|
205
214
|
const obj = value as Record<string, unknown>;
|
|
206
215
|
const result: Record<string, unknown> = {};
|
|
207
216
|
for (const [key, v] of Object.entries(obj)) {
|
|
208
217
|
if (v === undefined || v === null) continue;
|
|
209
|
-
|
|
218
|
+
const yamlKey = verbatim ? key : toKebabCase(key);
|
|
219
|
+
result[yamlKey] = convertValueKeys(v, verbatim || VERBATIM_KEY_MAPS.has(yamlKey));
|
|
210
220
|
}
|
|
211
221
|
return result;
|
|
212
222
|
}
|