@argos-ci/cli 0.3.2 → 0.3.3-alpha.2

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.mjs +118 -22
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -16,4 +16,4 @@ Argos CLI is used to interact with and upload screenshots to [argos-ci.com](http
16
16
 
17
17
  ## Links
18
18
 
19
- - [Official CLI Docs](https://docs.argos-ci.com)
19
+ - [Official CLI Docs](https://argos-ci.com/docs)
package/dist/index.mjs CHANGED
@@ -96,6 +96,11 @@ const schema = {
96
96
  default: null,
97
97
  nullable: true
98
98
  },
99
+ prNumber: {
100
+ format: String,
101
+ default: null,
102
+ nullable: true
103
+ },
99
104
  owner: {
100
105
  format: String,
101
106
  default: null,
@@ -125,7 +130,26 @@ const createConfig = ()=>{
125
130
  return result;
126
131
  };
127
132
 
128
- const service$1 = {
133
+ const service$4 = {
134
+ detect: ({ env })=>Boolean(env.BUILDKITE),
135
+ config: ({ env })=>{
136
+ const ciProps = envCiDetection({
137
+ env
138
+ });
139
+ return {
140
+ name: "Buildkite",
141
+ commit: ciProps?.commit || null,
142
+ branch: env.BUILDKITE_BRANCH || null,
143
+ owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
144
+ repository: env.BUILDKITE_PROJECT_SLUG || null,
145
+ jobId: env.BUILDKITE_JOB_ID || null,
146
+ runId: ciProps?.runId || null,
147
+ prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null
148
+ };
149
+ }
150
+ };
151
+
152
+ const service$3 = {
129
153
  detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
130
154
  config: ({ env })=>({
131
155
  name: "Heroku",
@@ -134,7 +158,8 @@ const service$1 = {
134
158
  owner: null,
135
159
  repository: null,
136
160
  jobId: env.HEROKU_TEST_RUN_ID || null,
137
- runId: null
161
+ runId: null,
162
+ prNumber: null
138
163
  })
139
164
  };
140
165
 
@@ -186,7 +211,15 @@ function getRepository({ env }) {
186
211
  if (!env.GITHUB_REPOSITORY) return null;
187
212
  return env.GITHUB_REPOSITORY.split("/")[1];
188
213
  }
189
- const service = {
214
+ const getPrNumber$1 = ({ env })=>{
215
+ const branchRegex = /refs\/pull\/(\d+)/;
216
+ const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
217
+ if (branchMatches) {
218
+ return Number(branchMatches[1]);
219
+ }
220
+ return null;
221
+ };
222
+ const service$2 = {
190
223
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
191
224
  config: ({ env })=>({
192
225
  name: "GitHub Actions",
@@ -201,24 +234,69 @@ const service = {
201
234
  env
202
235
  }),
203
236
  jobId: env.GITHUB_JOB || null,
204
- runId: env.GITHUB_RUN_ID || null
237
+ runId: env.GITHUB_RUN_ID || null,
238
+ prNumber: getPrNumber$1({
239
+ env
240
+ })
205
241
  })
206
242
  };
207
243
 
244
+ const getPrNumber = ({ env })=>{
245
+ const branchRegex = /pull\/(\d+)/;
246
+ const branchMatches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
247
+ if (branchMatches) {
248
+ return Number(branchMatches[1]);
249
+ }
250
+ return null;
251
+ };
252
+ const service$1 = {
253
+ detect: ({ env })=>Boolean(env.CIRCLECI),
254
+ config: ({ env })=>{
255
+ const ciProps = envCiDetection({
256
+ env
257
+ });
258
+ return {
259
+ name: "CircleCI",
260
+ commit: ciProps?.commit || null,
261
+ branch: ciProps?.branch || null,
262
+ owner: ciProps?.owner || null,
263
+ repository: ciProps?.repository || null,
264
+ jobId: ciProps?.jobId || null,
265
+ runId: ciProps?.runId || null,
266
+ prNumber: getPrNumber({
267
+ env
268
+ })
269
+ };
270
+ }
271
+ };
272
+
273
+ const service = {
274
+ detect: ({ env })=>Boolean(env.TRAVIS),
275
+ config: ({ env })=>{
276
+ const ciProps = envCiDetection({
277
+ env
278
+ });
279
+ return {
280
+ name: "Travis CI",
281
+ commit: ciProps?.commit || null,
282
+ branch: ciProps?.branch || null,
283
+ owner: ciProps?.owner || null,
284
+ repository: ciProps?.repository || null,
285
+ jobId: ciProps?.jobId || null,
286
+ runId: ciProps?.runId || null,
287
+ prNumber: env.TRAVIS_PULL_REQUEST ? Number(env.TRAVIS_PULL_REQUEST) : null
288
+ };
289
+ }
290
+ };
291
+
208
292
  const services = [
293
+ service$3,
294
+ service$2,
209
295
  service$1,
210
- service
296
+ service,
297
+ service$4
211
298
  ];
212
- const getCiEnvironment = ({ env =process.env } = {})=>{
213
- const ctx = {
214
- env
215
- };
216
- const service = services.find((service)=>service.detect(ctx));
217
- // Internal service matched
218
- if (service) {
219
- return service.config(ctx);
220
- }
221
- // Fallback on env-ci detection
299
+ const envCiDetection = (ctx)=>{
222
300
  const ciContext = envCi(ctx);
223
301
  const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
224
302
  const commit = ciContext.commit ?? null;
@@ -228,6 +306,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
228
306
  const repository = slug ? slug[1] : null;
229
307
  const jobId = ciContext.job ?? null;
230
308
  const runId = null;
309
+ const prNumber = null;
231
310
  return commit ? {
232
311
  name,
233
312
  commit,
@@ -235,9 +314,21 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
235
314
  owner,
236
315
  repository,
237
316
  jobId,
238
- runId
317
+ runId,
318
+ prNumber
239
319
  } : null;
240
320
  };
321
+ const getCiEnvironment = ({ env =process.env } = {})=>{
322
+ const ctx = {
323
+ env
324
+ };
325
+ const service = services.find((service)=>service.detect(ctx));
326
+ // Internal service matched
327
+ if (service) {
328
+ return service.config(ctx);
329
+ }
330
+ return envCiDetection(ctx);
331
+ };
241
332
 
242
333
  const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } = {})=>{
243
334
  const matches = await glob(patterns, {
@@ -276,7 +367,7 @@ const hashFile = async (filepath)=>{
276
367
  };
277
368
 
278
369
  const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
279
- const getBearerToken = ({ token , ciService , owner , repository , jobId , runId })=>{
370
+ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId , prNumber })=>{
280
371
  if (token) return `Bearer ${token}`;
281
372
  switch(ciService){
282
373
  case "GitHub Actions":
@@ -288,7 +379,8 @@ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId
288
379
  owner,
289
380
  repository,
290
381
  jobId,
291
- runId
382
+ runId,
383
+ prNumber
292
384
  })}`;
293
385
  }
294
386
  default:
@@ -348,13 +440,14 @@ const upload$1 = async (input)=>{
348
440
  const debug = createDebug("@argos-ci/core");
349
441
 
350
442
  const getConfigFromOptions = (options)=>{
351
- const { apiBaseUrl , commit , branch , token , buildName , parallel } = options;
443
+ const { apiBaseUrl , commit , branch , token , buildName , parallel , prNumber } = options;
352
444
  const config = createConfig();
353
445
  config.load(omitUndefined({
354
446
  apiBaseUrl,
355
447
  commit,
356
448
  branch,
357
449
  token,
450
+ prNumber,
358
451
  buildName,
359
452
  parallel: Boolean(parallel),
360
453
  parallelNonce: parallel ? parallel.nonce : null,
@@ -370,7 +463,8 @@ const getConfigFromOptions = (options)=>{
370
463
  owner: ciEnv.owner,
371
464
  repository: ciEnv.repository,
372
465
  jobId: ciEnv.jobId,
373
- runId: ciEnv.runId
466
+ runId: ciEnv.runId,
467
+ prNumber: ciEnv.prNumber
374
468
  }));
375
469
  }
376
470
  }
@@ -412,7 +506,8 @@ const getConfigFromOptions = (options)=>{
412
506
  name: config.buildName,
413
507
  parallel: config.parallel,
414
508
  parallelNonce: config.parallelNonce,
415
- screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash)))
509
+ screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash))),
510
+ prNumber: config.prNumber
416
511
  });
417
512
  debug("Got screenshots", result);
418
513
  // Upload screenshots
@@ -448,7 +543,7 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url));
448
543
  const rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
449
544
  const pkg = JSON.parse(rawPkg);
450
545
  program.name(pkg.name).description("Interact with and upload screenshots to argos-ci.com via command line.").version(pkg.version);
451
- program.command("upload").argument("<directory>", "Directory to upload").description("Upload screenshots to argos-ci.com").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")').option("--token <token>", "Repository token").option("--build-name <string>", "Name of the build, in case you want to run multiple Argos builds in a single CI job").option("--parallel", "Enable parallel mode. Run multiple Argos builds and combine them at the end").option("--parallel-total <number>", "The number of parallel nodes being ran").option("--parallel-nonce <string>", "A unique ID for this parallel build").action(async (directory, options)=>{
546
+ program.command("upload").argument("<directory>", "Directory to upload").description("Upload screenshots to argos-ci.com").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")').option("--token <token>", "Repository token").option("--pull-request <number>", "Pull-request number").option("--build-name <string>", "Name of the build, in case you want to run multiple Argos builds in a single CI job").option("--parallel", "Enable parallel mode. Run multiple Argos builds and combine them at the end").option("--parallel-total <number>", "The number of parallel nodes being ran").option("--parallel-nonce <string>", "A unique ID for this parallel build").action(async (directory, options)=>{
452
547
  const spinner = ora("Uploading screenshots").start();
453
548
  try {
454
549
  const result = await upload({
@@ -456,6 +551,7 @@ program.command("upload").argument("<directory>", "Directory to upload").descrip
456
551
  buildName: options.buildName,
457
552
  files: options.files,
458
553
  ignore: options.ignore,
554
+ prNumber: options.pullRequest,
459
555
  parallel: options.parallel ? {
460
556
  nonce: options.parallelNonce,
461
557
  total: options.parallelTotal
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/cli",
3
3
  "description": "Visual testing solution to avoid visual regression. Argos CLI is used to interact with and upload screenshots to argos-ci.com via command line.",
4
- "version": "0.3.2",
4
+ "version": "0.3.3-alpha.2+760abb1",
5
5
  "bin": {
6
6
  "argos": "./bin/argos-cli.js"
7
7
  },
@@ -40,7 +40,7 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/core": "^0.6.2",
43
+ "@argos-ci/core": "^0.6.3-alpha.2+760abb1",
44
44
  "commander": "^9.4.1",
45
45
  "ora": "^6.1.2",
46
46
  "update-notifier": "^6.0.2"
@@ -49,5 +49,5 @@
49
49
  "rollup": "^2.79.1",
50
50
  "rollup-plugin-swc3": "^0.6.0"
51
51
  },
52
- "gitHead": "bffcdb6010c67b9a77e94b79043a189e1086d1d8"
52
+ "gitHead": "760abb140949348929f833a68929744de146e127"
53
53
  }