@argos-ci/core 0.6.2 → 0.6.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.
package/README.md CHANGED
@@ -16,5 +16,5 @@ Argos Core JavaScript SDK contains interface definitions, base classes and utili
16
16
 
17
17
  ## Links
18
18
 
19
- - [Official SDK Docs](https://docs.argos-ci.com)
19
+ - [Official SDK Docs](https://argos-ci.com/docs)
20
20
  - [API Reference](https://js-sdk-reference.argos-ci.com)
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ interface UploadParameters {
13
13
  branch?: string;
14
14
  /** Argos repository token */
15
15
  token?: string;
16
+ /** Pull-request number */
17
+ prNumber?: number;
16
18
  /** Name of the build used to trigger multiple Argos builds on one commit */
17
19
  buildName?: string;
18
20
  /** Parallel test suite mode */
package/dist/index.mjs CHANGED
@@ -93,6 +93,11 @@ const schema = {
93
93
  default: null,
94
94
  nullable: true
95
95
  },
96
+ prNumber: {
97
+ format: String,
98
+ default: null,
99
+ nullable: true
100
+ },
96
101
  owner: {
97
102
  format: String,
98
103
  default: null,
@@ -122,7 +127,26 @@ const createConfig = ()=>{
122
127
  return result;
123
128
  };
124
129
 
125
- const service$1 = {
130
+ const service$4 = {
131
+ detect: ({ env })=>Boolean(env.BUILDKITE),
132
+ config: ({ env })=>{
133
+ const ciProps = envCiDetection({
134
+ env
135
+ });
136
+ return {
137
+ name: "Buildkite",
138
+ commit: ciProps?.commit || null,
139
+ branch: env.BUILDKITE_BRANCH || null,
140
+ owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
141
+ repository: env.BUILDKITE_PROJECT_SLUG || null,
142
+ jobId: env.BUILDKITE_JOB_ID || null,
143
+ runId: ciProps?.runId || null,
144
+ prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null
145
+ };
146
+ }
147
+ };
148
+
149
+ const service$3 = {
126
150
  detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
127
151
  config: ({ env })=>({
128
152
  name: "Heroku",
@@ -131,7 +155,8 @@ const service$1 = {
131
155
  owner: null,
132
156
  repository: null,
133
157
  jobId: env.HEROKU_TEST_RUN_ID || null,
134
- runId: null
158
+ runId: null,
159
+ prNumber: null
135
160
  })
136
161
  };
137
162
 
@@ -183,7 +208,15 @@ function getRepository({ env }) {
183
208
  if (!env.GITHUB_REPOSITORY) return null;
184
209
  return env.GITHUB_REPOSITORY.split("/")[1];
185
210
  }
186
- const service = {
211
+ const getPrNumber$1 = ({ env })=>{
212
+ const branchRegex = /refs\/pull\/(\d+)/;
213
+ const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
214
+ if (branchMatches) {
215
+ return Number(branchMatches[1]);
216
+ }
217
+ return null;
218
+ };
219
+ const service$2 = {
187
220
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
188
221
  config: ({ env })=>({
189
222
  name: "GitHub Actions",
@@ -198,24 +231,69 @@ const service = {
198
231
  env
199
232
  }),
200
233
  jobId: env.GITHUB_JOB || null,
201
- runId: env.GITHUB_RUN_ID || null
234
+ runId: env.GITHUB_RUN_ID || null,
235
+ prNumber: getPrNumber$1({
236
+ env
237
+ })
202
238
  })
203
239
  };
204
240
 
241
+ const getPrNumber = ({ env })=>{
242
+ const branchRegex = /pull\/(\d+)/;
243
+ const branchMatches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
244
+ if (branchMatches) {
245
+ return Number(branchMatches[1]);
246
+ }
247
+ return null;
248
+ };
249
+ const service$1 = {
250
+ detect: ({ env })=>Boolean(env.CIRCLECI),
251
+ config: ({ env })=>{
252
+ const ciProps = envCiDetection({
253
+ env
254
+ });
255
+ return {
256
+ name: "CircleCI",
257
+ commit: ciProps?.commit || null,
258
+ branch: ciProps?.branch || null,
259
+ owner: ciProps?.owner || null,
260
+ repository: ciProps?.repository || null,
261
+ jobId: ciProps?.jobId || null,
262
+ runId: ciProps?.runId || null,
263
+ prNumber: getPrNumber({
264
+ env
265
+ })
266
+ };
267
+ }
268
+ };
269
+
270
+ const service = {
271
+ detect: ({ env })=>Boolean(env.TRAVIS),
272
+ config: ({ env })=>{
273
+ const ciProps = envCiDetection({
274
+ env
275
+ });
276
+ return {
277
+ name: "Travis CI",
278
+ commit: ciProps?.commit || null,
279
+ branch: ciProps?.branch || null,
280
+ owner: ciProps?.owner || null,
281
+ repository: ciProps?.repository || null,
282
+ jobId: ciProps?.jobId || null,
283
+ runId: ciProps?.runId || null,
284
+ prNumber: env.TRAVIS_PULL_REQUEST ? Number(env.TRAVIS_PULL_REQUEST) : null
285
+ };
286
+ }
287
+ };
288
+
205
289
  const services = [
290
+ service$3,
291
+ service$2,
206
292
  service$1,
207
- service
293
+ service,
294
+ service$4
208
295
  ];
209
- const getCiEnvironment = ({ env =process.env } = {})=>{
210
- const ctx = {
211
- env
212
- };
213
- const service = services.find((service)=>service.detect(ctx));
214
- // Internal service matched
215
- if (service) {
216
- return service.config(ctx);
217
- }
218
- // Fallback on env-ci detection
296
+ const envCiDetection = (ctx)=>{
219
297
  const ciContext = envCi(ctx);
220
298
  const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
221
299
  const commit = ciContext.commit ?? null;
@@ -225,6 +303,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
225
303
  const repository = slug ? slug[1] : null;
226
304
  const jobId = ciContext.job ?? null;
227
305
  const runId = null;
306
+ const prNumber = null;
228
307
  return commit ? {
229
308
  name,
230
309
  commit,
@@ -232,9 +311,21 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
232
311
  owner,
233
312
  repository,
234
313
  jobId,
235
- runId
314
+ runId,
315
+ prNumber
236
316
  } : null;
237
317
  };
318
+ const getCiEnvironment = ({ env =process.env } = {})=>{
319
+ const ctx = {
320
+ env
321
+ };
322
+ const service = services.find((service)=>service.detect(ctx));
323
+ // Internal service matched
324
+ if (service) {
325
+ return service.config(ctx);
326
+ }
327
+ return envCiDetection(ctx);
328
+ };
238
329
 
239
330
  const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } = {})=>{
240
331
  const matches = await glob(patterns, {
@@ -273,7 +364,7 @@ const hashFile = async (filepath)=>{
273
364
  };
274
365
 
275
366
  const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
276
- const getBearerToken = ({ token , ciService , owner , repository , jobId , runId })=>{
367
+ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId , prNumber })=>{
277
368
  if (token) return `Bearer ${token}`;
278
369
  switch(ciService){
279
370
  case "GitHub Actions":
@@ -285,7 +376,8 @@ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId
285
376
  owner,
286
377
  repository,
287
378
  jobId,
288
- runId
379
+ runId,
380
+ prNumber
289
381
  })}`;
290
382
  }
291
383
  default:
@@ -345,13 +437,14 @@ const upload$1 = async (input)=>{
345
437
  const debug = createDebug("@argos-ci/core");
346
438
 
347
439
  const getConfigFromOptions = (options)=>{
348
- const { apiBaseUrl , commit , branch , token , buildName , parallel } = options;
440
+ const { apiBaseUrl , commit , branch , token , buildName , parallel , prNumber } = options;
349
441
  const config = createConfig();
350
442
  config.load(omitUndefined({
351
443
  apiBaseUrl,
352
444
  commit,
353
445
  branch,
354
446
  token,
447
+ prNumber,
355
448
  buildName,
356
449
  parallel: Boolean(parallel),
357
450
  parallelNonce: parallel ? parallel.nonce : null,
@@ -367,7 +460,8 @@ const getConfigFromOptions = (options)=>{
367
460
  owner: ciEnv.owner,
368
461
  repository: ciEnv.repository,
369
462
  jobId: ciEnv.jobId,
370
- runId: ciEnv.runId
463
+ runId: ciEnv.runId,
464
+ prNumber: ciEnv.prNumber
371
465
  }));
372
466
  }
373
467
  }
@@ -409,7 +503,8 @@ const getConfigFromOptions = (options)=>{
409
503
  name: config.buildName,
410
504
  parallel: config.parallel,
411
505
  parallelNonce: config.parallelNonce,
412
- screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash)))
506
+ screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash))),
507
+ prNumber: config.prNumber
413
508
  });
414
509
  debug("Got screenshots", result);
415
510
  // Upload screenshots
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
4
- "version": "0.6.2",
4
+ "version": "0.6.3-alpha.2+760abb1",
5
5
  "scripts": {
6
6
  "prebuild": "rm -rf dist",
7
7
  "build": "rollup -c",
@@ -60,5 +60,5 @@
60
60
  "rollup-plugin-dts": "^4.2.3",
61
61
  "rollup-plugin-swc3": "^0.6.0"
62
62
  },
63
- "gitHead": "bffcdb6010c67b9a77e94b79043a189e1086d1d8"
63
+ "gitHead": "760abb140949348929f833a68929744de146e127"
64
64
  }