@argos-ci/cli 6.1.1 → 6.2.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.
Files changed (2) hide show
  1. package/dist/index.mjs +44 -10
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -10,16 +10,17 @@ import { createServer } from "node:http";
10
10
  import { createHash, randomBytes } from "node:crypto";
11
11
  import open from "open";
12
12
  //#region src/options.ts
13
- const parallelNonceOption = new Option("--parallel-nonce <string>", "A unique ID for this parallel build").env("ARGOS_PARALLEL_NONCE");
14
- const tokenOption = new Option("--token <token>", "Repository token").env("ARGOS_TOKEN");
15
- const projectOption = new Option("--project <slug>", "Argos project slug (account/project), used to disambiguate tokenless authentication when multiple projects are linked to the same repository").env("ARGOS_PROJECT");
16
- const buildNameOption = 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");
13
+ const parallelNonceOption = new Option("--parallel-nonce <string>", "A unique ID for this parallel build");
14
+ const tokenOption = new Option("--token <token>", "Repository token");
15
+ const projectOption = new Option("--project <slug>", "Argos project slug (account/project), used to disambiguate tokenless authentication when multiple projects are linked to the same repository");
16
+ const buildNameOption = new Option("--build-name <string>", "Name of the build, in case you want to run multiple Argos builds in a single CI job");
17
+ const accountOption = new Option("--account <slug>", "Slug of the account (personal or team) that will own the project");
17
18
  const jsonOption = new Option("--json", "Output machine-readable JSON instead of human-readable text");
18
- const projectPathOption = new Option("--project <owner/project>", "Project path in owner/project format. Required for build-number references on review and comment commands").env("ARGOS_PROJECT");
19
+ const projectPathOption = new Option("--project <owner/project>", "Project path in owner/project format. Required for build-number references on review and comment commands");
19
20
  //#endregion
20
21
  //#region src/commands/upload.ts
21
22
  function uploadCommand(program) {
22
- 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(tokenOption).addOption(projectOption).addOption(buildNameOption).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.\nCan also be set via the ARGOS_PARALLEL environment variable.")).addOption(new Option("--parallel-total <number>", "The number of parallel nodes being ran").env("ARGOS_PARALLEL_TOTAL")).addOption(parallelNonceOption).addOption(new Option("--parallel-index <number>", "The index of the parallel node being ran (must be at least 1)").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")).addOption(new Option("--subset", "Whether this build contains only a subset of screenshots.\nThis is useful when a build is created from an incomplete test suite where some tests are skipped.\nCan also be set via the ARGOS_SUBSET environment variable.")).action(async (directory, options) => {
23
+ 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(tokenOption).addOption(projectOption).addOption(buildNameOption).addOption(new Option("--mode <string>", "Mode of comparison applied. CI for visual regression testing, monitoring for visual monitoring.").default("ci").choices(["ci", "monitoring"])).addOption(new Option("--parallel", "Enable parallel mode. Run multiple Argos builds and combine them at the end.\nCan also be set via the ARGOS_PARALLEL environment variable.")).addOption(new Option("--parallel-total <number>", "The number of parallel nodes being ran")).addOption(parallelNonceOption).addOption(new Option("--parallel-index <number>", "The index of the parallel node being ran (must be at least 1)")).addOption(new Option("--reference-branch <string>", "Branch used as baseline for screenshot comparison")).addOption(new Option("--reference-commit <string>", "Commit used as baseline for screenshot comparison")).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")).addOption(new Option("--subset", "Whether this build contains only a subset of screenshots.\nThis is useful when a build is created from an incomplete test suite where some tests are skipped.\nCan also be set via the ARGOS_SUBSET environment variable.")).action(async (directory, options) => {
23
24
  const spinner = ora("Uploading screenshots").start();
24
25
  try {
25
26
  const parallel = (() => {
@@ -64,12 +65,18 @@ function uploadCommand(program) {
64
65
  }
65
66
  //#endregion
66
67
  //#region src/commands/finalize.ts
68
+ const skipIfEmptyOption = new Option("--skip-if-empty", "Create a skipped build when no parallel build matches the nonce.\nUseful when uploads are conditional (e.g. skipped by a CI cache) and Argos is a required status check: the skipped build reports a success status even though nothing was uploaded.");
67
69
  function finalizeCommand(program) {
68
- program.command("finalize").description("Finalize pending parallel builds").addOption(parallelNonceOption).action(async (options) => {
70
+ program.command("finalize").description("Finalize pending parallel builds").addOption(parallelNonceOption).addOption(tokenOption).addOption(skipIfEmptyOption).addOption(buildNameOption).action(async (options) => {
69
71
  const spinner = ora("Finalizing builds").start();
70
72
  try {
71
- const result = await finalize({ parallel: options.parallelNonce ? { nonce: options.parallelNonce } : void 0 });
72
- spinner.succeed(result.builds.length === 0 ? "No builds to finalize" : `Builds finalized: ${result.builds.map((b) => b.url).join(", ")}`);
73
+ const result = await finalize({
74
+ token: options.token,
75
+ parallel: options.parallelNonce ? { nonce: options.parallelNonce } : void 0,
76
+ skipIfEmpty: options.skipIfEmpty,
77
+ buildName: options.buildName
78
+ });
79
+ spinner.succeed(result.skippedBuild ? `No builds to finalize — skipped build created: ${result.skippedBuild.url}` : result.builds.length === 0 ? "No builds to finalize" : `Builds finalized: ${result.builds.map((b) => b.url).join(", ")}`);
73
80
  } catch (error) {
74
81
  if (error instanceof Error) {
75
82
  spinner.fail(`Failed to finalize: ${error.message}`);
@@ -139,6 +146,15 @@ function formatMe(user) {
139
146
  `Name: ${formatValue(user.name)}`
140
147
  ].join("\n");
141
148
  }
149
+ function formatProject(project) {
150
+ return [
151
+ `Created project ${project.account.slug}/${project.name}.`,
152
+ `ID: ${project.id}`,
153
+ `Name: ${project.name}`,
154
+ `Account: ${project.account.slug}`,
155
+ `Default base branch: ${formatValue(project.defaultBaseBranch)}`
156
+ ].join("\n");
157
+ }
142
158
  function formatStats(stats) {
143
159
  if (!stats) return "-";
144
160
  return [
@@ -414,7 +430,8 @@ function explicitProjectPath(reference, options) {
414
430
  owner: reference.owner,
415
431
  project: reference.project
416
432
  };
417
- if (options.project) return parseProjectPathOrFail(options.project);
433
+ const project = options.project || process.env["ARGOS_PROJECT"];
434
+ if (project) return parseProjectPathOrFail(project);
418
435
  return null;
419
436
  }
420
437
  /**
@@ -1092,6 +1109,22 @@ function whoamiCommand(program) {
1092
1109
  });
1093
1110
  }
1094
1111
  //#endregion
1112
+ //#region src/commands/create-project.ts
1113
+ function createProjectCommand(program) {
1114
+ program.command("create-project").argument("<name>", "Name of the project to create").description("Create a new project in an account you administer").addOption(accountOption).addOption(tokenOption).addOption(jsonOption).action(async (name, options) => {
1115
+ try {
1116
+ const accountSlug = options.account || process.env["ARGOS_ACCOUNT"];
1117
+ if (!accountSlug) fail("An account is required. Use --account <slug> or set ARGOS_ACCOUNT.");
1118
+ output(unwrap(await createApiClient(await resolveToken(options)).POST("/projects", { body: {
1119
+ name,
1120
+ accountSlug
1121
+ } })), options, formatProject);
1122
+ } catch (error) {
1123
+ handleCliError(error, "user");
1124
+ }
1125
+ });
1126
+ }
1127
+ //#endregion
1095
1128
  //#region src/index.ts
1096
1129
  const rawPkg = await readFile(resolve(fileURLToPath(new URL(".", import.meta.url)), "..", "package.json"), "utf8");
1097
1130
  const pkg = JSON.parse(rawPkg);
@@ -1106,6 +1139,7 @@ loginCommand(program);
1106
1139
  logoutCommand(program);
1107
1140
  deployCommand(program);
1108
1141
  whoamiCommand(program);
1142
+ createProjectCommand(program);
1109
1143
  if (!process.argv.slice(2).length) program.outputHelp();
1110
1144
  else program.parse(process.argv);
1111
1145
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/cli",
3
3
  "description": "Command-line (CLI) for visual testing with Argos.",
4
- "version": "6.1.1",
4
+ "version": "6.2.0",
5
5
  "bin": {
6
6
  "argos": "./bin/argos-cli.js"
7
7
  },
@@ -34,8 +34,8 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@argos-ci/api-client": "0.24.1",
38
- "@argos-ci/core": "6.5.0",
37
+ "@argos-ci/api-client": "0.25.0",
38
+ "@argos-ci/core": "6.6.0",
39
39
  "commander": "^15.0.0",
40
40
  "open": "^11.0.0",
41
41
  "ora": "^9.4.0",
@@ -54,5 +54,5 @@
54
54
  "check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
55
55
  "lint": "eslint ."
56
56
  },
57
- "gitHead": "7fddaad1a6bb251a1f2eecbf8f4ecfa3e84e9b97"
57
+ "gitHead": "686b6fa8385ed77598ec86f66b073e9897cef176"
58
58
  }