Skip to content

Commit

Permalink
feat: add finalize command
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Aug 31, 2024
1 parent 817a7b5 commit 53ce57d
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 248 deletions.
129 changes: 66 additions & 63 deletions packages/api-client/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ export interface paths {
patch?: never;
trace?: never;
};
"/builds/{buildId}": {
"/builds/finalize": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put: operations["updateBuild"];
post?: never;
put?: never;
post: operations["finalizeBuilds"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/builds/{buildId}/finalize": {
"/builds/{buildId}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
post: operations["finalizeBuild"];
put: operations["updateBuild"];
post?: never;
delete?: never;
options?: never;
head?: never;
Expand Down Expand Up @@ -223,77 +223,29 @@ export interface operations {
};
};
};
updateBuild: {
finalizeBuilds: {
parameters: {
query?: never;
header?: never;
path: {
/** @description A unique identifier for the build */
buildId: components["schemas"]["buildId"];
};
path?: never;
cookie?: never;
};
requestBody?: {
content: {
"application/json": {
screenshots: {
key: string;
name: string;
baseName?: string | null;
metadata?: {
url?: string;
viewport?: {
width: number;
height: number;
};
/** @enum {string} */
colorScheme?: "light" | "dark";
/** @enum {string} */
mediaType?: "screen" | "print";
test?: {
id?: string;
title: string;
titlePath: string[];
retries?: number;
retry?: number;
repeat?: number;
location?: {
file: string;
line: number;
column: number;
};
} | null;
browser?: {
name: string;
version: string;
};
automationLibrary: {
name: string;
version: string;
};
sdk: {
name: string;
version: string;
};
} | null;
pwTraceKey?: string | null;
threshold?: number | null;
}[];
parallel?: boolean | null;
parallelTotal?: number | null;
parallelIndex?: number | null;
parallelNonce: string;
};
};
};
responses: {
/** @description Result of build update */
/** @description Result of build finalization */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
build: components["schemas"]["Build"];
builds: components["schemas"]["Build"][];
};
};
};
Expand Down Expand Up @@ -353,19 +305,70 @@ export interface operations {
};
};
};
finalizeBuild: {
updateBuild: {
parameters: {
query?: never;
header?: never;
path: {
/** @description A unique identifier for the build */
buildId: string;
buildId: components["schemas"]["buildId"];
};
cookie?: never;
};
requestBody?: never;
requestBody?: {
content: {
"application/json": {
screenshots: {
key: string;
name: string;
baseName?: string | null;
metadata?: {
url?: string;
viewport?: {
width: number;
height: number;
};
/** @enum {string} */
colorScheme?: "light" | "dark";
/** @enum {string} */
mediaType?: "screen" | "print";
test?: {
id?: string;
title: string;
titlePath: string[];
retries?: number;
retry?: number;
repeat?: number;
location?: {
file: string;
line: number;
column: number;
};
} | null;
browser?: {
name: string;
version: string;
};
automationLibrary: {
name: string;
version: string;
};
sdk: {
name: string;
version: string;
};
} | null;
pwTraceKey?: string | null;
threshold?: number | null;
}[];
parallel?: boolean | null;
parallelTotal?: number | null;
parallelIndex?: number | null;
};
};
};
responses: {
/** @description Result of build finalization */
/** @description Result of build update */
200: {
headers: {
[name: string]: unknown;
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/src/commands/finalize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ora from "ora";
import { Command } from "commander";
import { finalize } from "@argos-ci/core";
import { parallelNonce } from "../options";

export function finalizeCommand(program: Command) {
program
.command("finalize")
.description("Finalize pending parallel builds")
.addOption(parallelNonce)
.action(async (options) => {
const spinner = ora("Finalizing builds").start();
try {
const result = await finalize({
parallel: {
nonce: options.parallelNonce,
},
});
spinner.succeed(
`Builds finalized: ${result.builds.map((b) => b.url).join(", ")}`,
);
} catch (error) {
if (error instanceof Error) {
spinner.fail(`Failed to finalize: ${error.message}`);
console.error(error.stack);
}
process.exit(1);
}
});
}
108 changes: 108 additions & 0 deletions packages/cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Command, Option } from "commander";
import { upload } from "@argos-ci/core";
import ora from "ora";
import { parallelNonce } from "../options";

export function uploadCommand(program: Command) {
program
.command("upload")
.argument("<directory>", "Directory to upload")
.description("Upload screenshots to Argos")
.option(
"-f, --files <patterns...>",
"One or more globs matching image file paths to upload",
"**/*.{png,jpg,jpeg}",
)
.option(
"-i, --ignore <patterns...>",
'One or more globs matching image file paths to ignore (ex: "**/*.png **/diff.jpg")',
)
.addOption(
new Option("--token <token>", "Repository token").env("ARGOS_TOKEN"),
)
.addOption(
new Option(
"--build-name <string>",
"Name of the build, in case you want to run multiple Argos builds in a single CI job",
).env("ARGOS_BUILD_NAME"),
)
.addOption(
new Option(
"--mode <string>",
"Mode of comparison applied. CI for visual regression testing, monitoring for visual monitoring.",
)
.default("ci")
.choices(["ci", "monitoring"])
.env("ARGOS_MODE"),
)
.addOption(
new Option(
"--parallel",
"Enable parallel mode. Run multiple Argos builds and combine them at the end",
).env("ARGOS_PARALLEL"),
)
.addOption(
new Option(
"--parallel-total <number>",
"The number of parallel nodes being ran",
).env("ARGOS_PARALLEL_TOTAL"),
)
.addOption(parallelNonce)
.addOption(
new Option(
"--parallel-index <number>",
"The index of the parallel node being ran",
).env("ARGOS_PARALLEL_INDEX"),
)
.addOption(
new Option(
"--reference-branch <string>",
"Branch used as baseline for screenshot comparison",
).env("ARGOS_REFERENCE_BRANCH"),
)
.addOption(
new Option(
"--reference-commit <string>",
"Commit used as baseline for screenshot comparison",
).env("ARGOS_REFERENCE_COMMIT"),
)
.addOption(
new Option(
"--threshold <number>",
"Sensitivity threshold between 0 and 1. The higher the threshold, the less sensitive the diff will be. Default to 0.5",
).env("ARGOS_THRESHOLD"),
)
.action(async (directory, options) => {
const spinner = ora("Uploading screenshots").start();
try {
const result = await upload({
token: options.token,
root: directory,
buildName: options.buildName,
files: options.files,
ignore: options.ignore,
prNumber: options.pullRequest
? Number(options.pullRequest)
: undefined,
parallel: options.parallel
? {
nonce: options.parallelNonce,
total: options.parallelTotal,
index: options.parallelIndex,
}
: false,
referenceBranch: options.referenceBranch,
referenceCommit: options.referenceCommit,
mode: options.mode,
threshold: options.threshold,
});
spinner.succeed(`Build created: ${result.build.url}`);
} catch (error) {
if (error instanceof Error) {
spinner.fail(`Build failed: ${error.message}`);
console.error(error.stack);
}
process.exit(1);
}
});
}
Loading

0 comments on commit 53ce57d

Please sign in to comment.