Skip to content

Commit

Permalink
Merge branch 'origin-dev' into pileks/feat/cli-wrapper-envs-option
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli authored Dec 3, 2022
2 parents 517355a + a91e100 commit 7cc9978
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
parseManifestFileOption,
parseLogFileOption,
parseWrapperEnvsOption,
typesHandler,
} from "../lib";
import { createLogger } from "./utils/createLogger";

Expand Down Expand Up @@ -156,7 +157,10 @@ const _run = async (options: WorkflowCommandOptions) => {
fs.writeFileSync(outputFile, yaml.stringify(printableOutput, null, 2));
break;
case "json":
fs.writeFileSync(outputFile, JSON.stringify(printableOutput, null, 2));
fs.writeFileSync(
outputFile,
JSON.stringify(printableOutput, typesHandler, 2)
);
break;
default:
throw new Error(
Expand Down
22 changes: 17 additions & 5 deletions packages/cli/src/lib/helpers/workflow-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export function cueExists(logger: Logger): boolean {
return stdout ? stdout.startsWith("cue version ") : false;
}

export const typesHandler = (_: unknown, value: unknown): unknown => {
if (value instanceof Map) {
return Array.from(value).reduce(
(obj: Record<string, unknown>, [key, value]) => {
obj[key] = value;
return obj;
},
{}
);
}

return value;
};

export function validateOutput(
output: WorkflowOutput,
validateScriptPath: string,
Expand All @@ -34,13 +48,11 @@ export function validateOutput(

fs.writeFileSync(
jsonOutput,
JSON.stringify({ data, error: error?.message }, null, 2)
JSON.stringify({ data, error: error?.message }, typesHandler, 2)
);

const { stderr } = runCommandSync(
`cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}`,
logger
);
const args = [selector, validateScriptPath, jsonOutput];
const { stderr } = runCommandSync(`cue vet -d ${args.join(" ")}`, logger);

if (fs.existsSync(jsonOutput)) {
fs.unlinkSync(jsonOutput);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/workflow/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { intlMsg } from "../intl";
import { WorkflowOutput } from "./types";
import { typesHandler } from "../helpers";

import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -44,7 +45,7 @@ export function printJobOutput(output: WorkflowOutput): void {
console.log(`Job status: ${output.status}`);

if (output.data !== undefined) {
console.log(`Data: ${JSON.stringify(output.data, null, 2)}`);
console.log(`Data: ${JSON.stringify(output.data, typesHandler, 2)}`);
}

if (output.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ jobs:
args:
x: "$cases.0.data"
y: "$cases.0.data"
case3:
steps:
- uri: fs/../run-test-wrapper/build
method: returnMap
args:
map:
nested_map:
Hello: 1
Heyo: 50
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Args_add,
Args_addInBox,
Args_addFromEnv,
Args_returnMap,
Num,
Env
} from "./wrap";
Expand All @@ -16,4 +17,8 @@ export function addInBox(args: Args_addInBox): Num {

export function addFromEnv(args: Args_addFromEnv, env: Env): i32 {
return args.x + env.value;
}
}

export function returnMap(args: Args_returnMap): Map<string, Map<string, i32>> {
return args.map;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Module {
addFromEnv(
x: Int32!
): Int32! @env(required: true)

returnMap(
map: Map! @annotate(type: "Map<String!, Map<String!, Int!>!>!")
): Map! @annotate(type: "Map<String!, Map<String!, Int!>!>!")
}

type Num {
Expand Down

0 comments on commit 7cc9978

Please sign in to comment.