@argos-ci/core 0.6.2 → 0.6.3-alpha.1

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,7 @@ const createConfig = ()=>{
122
127
  return result;
123
128
  };
124
129
 
125
- const service$1 = {
130
+ const service$3 = {
126
131
  detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
127
132
  config: ({ env })=>({
128
133
  name: "Heroku",
@@ -131,7 +136,8 @@ const service$1 = {
131
136
  owner: null,
132
137
  repository: null,
133
138
  jobId: env.HEROKU_TEST_RUN_ID || null,
134
- runId: null
139
+ runId: null,
140
+ prNumber: null
135
141
  })
136
142
  };
137
143
 
@@ -183,7 +189,15 @@ function getRepository({ env }) {
183
189
  if (!env.GITHUB_REPOSITORY) return null;
184
190
  return env.GITHUB_REPOSITORY.split("/")[1];
185
191
  }
186
- const service = {
192
+ const getPrNumber$1 = ({ env })=>{
193
+ const branchRegex = /refs\/pull\/(\d+)/;
194
+ const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
195
+ if (branchMatches) {
196
+ branchMatches[1];
197
+ }
198
+ return null;
199
+ };
200
+ const service$2 = {
187
201
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
188
202
  config: ({ env })=>({
189
203
  name: "GitHub Actions",
@@ -198,24 +212,68 @@ const service = {
198
212
  env
199
213
  }),
200
214
  jobId: env.GITHUB_JOB || null,
201
- runId: env.GITHUB_RUN_ID || null
215
+ runId: env.GITHUB_RUN_ID || null,
216
+ prNumber: getPrNumber$1({
217
+ env
218
+ })
202
219
  })
203
220
  };
204
221
 
222
+ const getPrNumber = ({ env })=>{
223
+ const branchRegex = /pull\/(\d+)/;
224
+ const branchMatches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
225
+ if (branchMatches) {
226
+ branchMatches[1];
227
+ }
228
+ return null;
229
+ };
230
+ const service$1 = {
231
+ detect: ({ env })=>Boolean(env.CIRCLECI),
232
+ config: ({ env })=>{
233
+ const ciProps = envCiDetection({
234
+ env
235
+ });
236
+ return {
237
+ name: "CircleCI",
238
+ commit: ciProps?.commit || null,
239
+ branch: ciProps?.branch || null,
240
+ owner: ciProps?.owner || null,
241
+ repository: ciProps?.repository || null,
242
+ jobId: ciProps?.jobId || null,
243
+ runId: ciProps?.runId || null,
244
+ prNumber: getPrNumber({
245
+ env
246
+ })
247
+ };
248
+ }
249
+ };
250
+
251
+ const service = {
252
+ detect: ({ env })=>Boolean(env.TRAVIS),
253
+ config: ({ env })=>{
254
+ const ciProps = envCiDetection({
255
+ env
256
+ });
257
+ return {
258
+ name: "Travis CI",
259
+ commit: ciProps?.commit || null,
260
+ branch: ciProps?.branch || null,
261
+ owner: ciProps?.owner || null,
262
+ repository: ciProps?.repository || null,
263
+ jobId: ciProps?.jobId || null,
264
+ runId: ciProps?.runId || null,
265
+ prNumber: env.TRAVIS_PULL_REQUEST || null
266
+ };
267
+ }
268
+ };
269
+
205
270
  const services = [
271
+ service$3,
272
+ service$2,
206
273
  service$1,
207
274
  service
208
275
  ];
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
276
+ const envCiDetection = (ctx)=>{
219
277
  const ciContext = envCi(ctx);
220
278
  const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
221
279
  const commit = ciContext.commit ?? null;
@@ -225,6 +283,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
225
283
  const repository = slug ? slug[1] : null;
226
284
  const jobId = ciContext.job ?? null;
227
285
  const runId = null;
286
+ const prNumber = null;
228
287
  return commit ? {
229
288
  name,
230
289
  commit,
@@ -232,9 +291,21 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
232
291
  owner,
233
292
  repository,
234
293
  jobId,
235
- runId
294
+ runId,
295
+ prNumber
236
296
  } : null;
237
297
  };
298
+ const getCiEnvironment = ({ env =process.env } = {})=>{
299
+ const ctx = {
300
+ env
301
+ };
302
+ const service = services.find((service)=>service.detect(ctx));
303
+ // Internal service matched
304
+ if (service) {
305
+ return service.config(ctx);
306
+ }
307
+ return envCiDetection(ctx);
308
+ };
238
309
 
239
310
  const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } = {})=>{
240
311
  const matches = await glob(patterns, {
@@ -273,7 +344,7 @@ const hashFile = async (filepath)=>{
273
344
  };
274
345
 
275
346
  const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
276
- const getBearerToken = ({ token , ciService , owner , repository , jobId , runId })=>{
347
+ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId , prNumber })=>{
277
348
  if (token) return `Bearer ${token}`;
278
349
  switch(ciService){
279
350
  case "GitHub Actions":
@@ -285,7 +356,8 @@ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId
285
356
  owner,
286
357
  repository,
287
358
  jobId,
288
- runId
359
+ runId,
360
+ prNumber
289
361
  })}`;
290
362
  }
291
363
  default:
@@ -345,13 +417,14 @@ const upload$1 = async (input)=>{
345
417
  const debug = createDebug("@argos-ci/core");
346
418
 
347
419
  const getConfigFromOptions = (options)=>{
348
- const { apiBaseUrl , commit , branch , token , buildName , parallel } = options;
420
+ const { apiBaseUrl , commit , branch , token , buildName , parallel , prNumber } = options;
349
421
  const config = createConfig();
350
422
  config.load(omitUndefined({
351
423
  apiBaseUrl,
352
424
  commit,
353
425
  branch,
354
426
  token,
427
+ prNumber,
355
428
  buildName,
356
429
  parallel: Boolean(parallel),
357
430
  parallelNonce: parallel ? parallel.nonce : null,
@@ -367,7 +440,8 @@ const getConfigFromOptions = (options)=>{
367
440
  owner: ciEnv.owner,
368
441
  repository: ciEnv.repository,
369
442
  jobId: ciEnv.jobId,
370
- runId: ciEnv.runId
443
+ runId: ciEnv.runId,
444
+ prNumber: ciEnv.prNumber
371
445
  }));
372
446
  }
373
447
  }
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.1+46d7443",
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": "46d7443fe360fe5d42482e404bd3ab5c05116567"
64
64
  }