@argos-ci/cli 0.4.1 → 0.4.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/dist/index.mjs +87 -56
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -3,9 +3,10 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { program } from 'commander';
|
|
5
5
|
import convict from 'convict';
|
|
6
|
-
import
|
|
7
|
-
import { execSync } from 'child_process';
|
|
6
|
+
import { execSync } from 'node:child_process';
|
|
7
|
+
import { execSync as execSync$1 } from 'child_process';
|
|
8
8
|
import createDebug from 'debug';
|
|
9
|
+
import envCi from 'env-ci';
|
|
9
10
|
import glob from 'fast-glob';
|
|
10
11
|
import { promisify } from 'node:util';
|
|
11
12
|
import sharp from 'sharp';
|
|
@@ -118,20 +119,41 @@ const createConfig = ()=>{
|
|
|
118
119
|
});
|
|
119
120
|
};
|
|
120
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Returns the head commit.
|
|
124
|
+
*/ const head = ()=>{
|
|
125
|
+
try {
|
|
126
|
+
return execSync("git rev-parse HEAD").toString().trim();
|
|
127
|
+
} catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Returns the current branch.
|
|
133
|
+
*/ const branch = ()=>{
|
|
134
|
+
try {
|
|
135
|
+
const headRef = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
136
|
+
if (headRef === "HEAD") {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return headRef;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
121
145
|
const service$4 = {
|
|
122
146
|
name: "Buildkite",
|
|
123
147
|
detect: ({ env })=>Boolean(env.BUILDKITE),
|
|
124
148
|
config: ({ env })=>{
|
|
125
|
-
const ciProps = envCiDetection({
|
|
126
|
-
env
|
|
127
|
-
});
|
|
128
149
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
// Buildkite doesn't work well so we fallback to git to ensure we have commit and branch
|
|
151
|
+
commit: env.BUILDKITE_COMMIT || head() || null,
|
|
152
|
+
branch: env.BUILDKITE_BRANCH || branch() || null,
|
|
131
153
|
owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
|
|
132
154
|
repository: env.BUILDKITE_PROJECT_SLUG || null,
|
|
133
|
-
jobId:
|
|
134
|
-
runId:
|
|
155
|
+
jobId: null,
|
|
156
|
+
runId: null,
|
|
135
157
|
prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null
|
|
136
158
|
};
|
|
137
159
|
}
|
|
@@ -145,7 +167,7 @@ const service$3 = {
|
|
|
145
167
|
branch: env.HEROKU_TEST_RUN_BRANCH || null,
|
|
146
168
|
owner: null,
|
|
147
169
|
repository: null,
|
|
148
|
-
jobId:
|
|
170
|
+
jobId: null,
|
|
149
171
|
runId: null,
|
|
150
172
|
prNumber: null
|
|
151
173
|
})
|
|
@@ -155,7 +177,7 @@ const getSha = ({ env })=>{
|
|
|
155
177
|
const isPr = env.GITHUB_EVENT_NAME === "pull_request" || env.GITHUB_EVENT_NAME === "pull_request_target";
|
|
156
178
|
if (isPr) {
|
|
157
179
|
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
|
|
158
|
-
const mergeCommitMessage = execSync("git show --no-patch --format=%P").toString().trim();
|
|
180
|
+
const mergeCommitMessage = execSync$1("git show --no-patch --format=%P").toString().trim();
|
|
159
181
|
// console.log(
|
|
160
182
|
// `Handling PR with parent hash(es) '${mergeCommitMessage}' of current commit.`
|
|
161
183
|
// );
|
|
@@ -184,22 +206,22 @@ Please run "actions/checkout" with "fetch-depth: 2". Example:
|
|
|
184
206
|
}
|
|
185
207
|
return process.env.GITHUB_SHA ?? null;
|
|
186
208
|
};
|
|
187
|
-
|
|
209
|
+
const getBranch = ({ env })=>{
|
|
188
210
|
if (env.GITHUB_HEAD_REF) {
|
|
189
211
|
return env.GITHUB_HEAD_REF;
|
|
190
212
|
}
|
|
191
213
|
const branchRegex = /refs\/heads\/(.*)/;
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
return
|
|
214
|
+
const matches = branchRegex.exec(env.GITHUB_REF || "");
|
|
215
|
+
if (matches) {
|
|
216
|
+
return matches[1];
|
|
195
217
|
}
|
|
196
218
|
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
219
|
+
};
|
|
220
|
+
const getRepository$1 = ({ env })=>{
|
|
199
221
|
if (!env.GITHUB_REPOSITORY) return null;
|
|
200
222
|
return env.GITHUB_REPOSITORY.split("/")[1];
|
|
201
|
-
}
|
|
202
|
-
const getPrNumber$
|
|
223
|
+
};
|
|
224
|
+
const getPrNumber$2 = ({ env })=>{
|
|
203
225
|
const branchRegex = /refs\/pull\/(\d+)/;
|
|
204
226
|
const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
|
|
205
227
|
if (branchMatches) {
|
|
@@ -218,22 +240,22 @@ const service$2 = {
|
|
|
218
240
|
env
|
|
219
241
|
}),
|
|
220
242
|
owner: env.GITHUB_REPOSITORY_OWNER || null,
|
|
221
|
-
repository: getRepository({
|
|
243
|
+
repository: getRepository$1({
|
|
222
244
|
env
|
|
223
245
|
}),
|
|
224
246
|
jobId: env.GITHUB_JOB || null,
|
|
225
247
|
runId: env.GITHUB_RUN_ID || null,
|
|
226
|
-
prNumber: getPrNumber$
|
|
248
|
+
prNumber: getPrNumber$2({
|
|
227
249
|
env
|
|
228
250
|
})
|
|
229
251
|
})
|
|
230
252
|
};
|
|
231
253
|
|
|
232
|
-
const getPrNumber = ({ env })=>{
|
|
254
|
+
const getPrNumber$1 = ({ env })=>{
|
|
233
255
|
const branchRegex = /pull\/(\d+)/;
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
return Number(
|
|
256
|
+
const matches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
|
|
257
|
+
if (matches) {
|
|
258
|
+
return Number(matches[1]);
|
|
237
259
|
}
|
|
238
260
|
return null;
|
|
239
261
|
};
|
|
@@ -241,52 +263,52 @@ const service$1 = {
|
|
|
241
263
|
name: "CircleCI",
|
|
242
264
|
detect: ({ env })=>Boolean(env.CIRCLECI),
|
|
243
265
|
config: ({ env })=>{
|
|
244
|
-
const ciProps = envCiDetection({
|
|
245
|
-
env
|
|
246
|
-
});
|
|
247
266
|
return {
|
|
248
|
-
commit:
|
|
249
|
-
branch:
|
|
250
|
-
owner:
|
|
251
|
-
repository:
|
|
252
|
-
jobId:
|
|
253
|
-
runId:
|
|
254
|
-
prNumber: getPrNumber({
|
|
267
|
+
commit: env.CIRCLE_SHA1 || null,
|
|
268
|
+
branch: env.CIRCLE_BRANCH || null,
|
|
269
|
+
owner: env.CIRCLE_PROJECT_USERNAME || null,
|
|
270
|
+
repository: env.CIRCLE_PROJECT_REPONAME || null,
|
|
271
|
+
jobId: null,
|
|
272
|
+
runId: null,
|
|
273
|
+
prNumber: getPrNumber$1({
|
|
255
274
|
env
|
|
256
275
|
})
|
|
257
276
|
};
|
|
258
277
|
}
|
|
259
278
|
};
|
|
260
279
|
|
|
280
|
+
const getOwner = ({ env })=>{
|
|
281
|
+
if (!env.TRAVIS_REPO_SLUG) return null;
|
|
282
|
+
return env.TRAVIS_REPO_SLUG.split("/")[0] || null;
|
|
283
|
+
};
|
|
284
|
+
const getRepository = ({ env })=>{
|
|
285
|
+
if (!env.TRAVIS_REPO_SLUG) return null;
|
|
286
|
+
return env.TRAVIS_REPO_SLUG.split("/")[1] || null;
|
|
287
|
+
};
|
|
288
|
+
const getPrNumber = ({ env })=>{
|
|
289
|
+
if (env.TRAVIS_PULL_REQUEST) return Number(env.TRAVIS_PULL_REQUEST);
|
|
290
|
+
return null;
|
|
291
|
+
};
|
|
261
292
|
const service = {
|
|
262
293
|
name: "Travis CI",
|
|
263
294
|
detect: ({ env })=>Boolean(env.TRAVIS),
|
|
264
|
-
config: (
|
|
265
|
-
const
|
|
266
|
-
env
|
|
267
|
-
});
|
|
295
|
+
config: (ctx)=>{
|
|
296
|
+
const { env } = ctx;
|
|
268
297
|
return {
|
|
269
|
-
commit:
|
|
270
|
-
branch:
|
|
271
|
-
owner:
|
|
272
|
-
repository:
|
|
273
|
-
jobId:
|
|
274
|
-
runId:
|
|
275
|
-
prNumber:
|
|
298
|
+
commit: env.TRAVIS_COMMIT || null,
|
|
299
|
+
branch: env.TRAVIS_BRANCH || null,
|
|
300
|
+
owner: getOwner(ctx),
|
|
301
|
+
repository: getRepository(ctx),
|
|
302
|
+
jobId: null,
|
|
303
|
+
runId: null,
|
|
304
|
+
prNumber: getPrNumber(ctx)
|
|
276
305
|
};
|
|
277
306
|
}
|
|
278
307
|
};
|
|
279
308
|
|
|
280
309
|
const debug = createDebug("@argos-ci/core");
|
|
281
310
|
|
|
282
|
-
const
|
|
283
|
-
service$3,
|
|
284
|
-
service$2,
|
|
285
|
-
service$1,
|
|
286
|
-
service,
|
|
287
|
-
service$4
|
|
288
|
-
];
|
|
289
|
-
const envCiDetection = (ctx)=>{
|
|
311
|
+
const getCiEnvironmentFromEnvCi = (ctx)=>{
|
|
290
312
|
const ciContext = envCi(ctx);
|
|
291
313
|
const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
|
|
292
314
|
const commit = ciContext.commit ?? null;
|
|
@@ -308,6 +330,14 @@ const envCiDetection = (ctx)=>{
|
|
|
308
330
|
prNumber
|
|
309
331
|
} : null;
|
|
310
332
|
};
|
|
333
|
+
|
|
334
|
+
const services = [
|
|
335
|
+
service$3,
|
|
336
|
+
service$2,
|
|
337
|
+
service$1,
|
|
338
|
+
service,
|
|
339
|
+
service$4
|
|
340
|
+
];
|
|
311
341
|
const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
312
342
|
const ctx = {
|
|
313
343
|
env
|
|
@@ -316,7 +346,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
316
346
|
env
|
|
317
347
|
});
|
|
318
348
|
const service = services.find((service)=>service.detect(ctx));
|
|
319
|
-
//
|
|
349
|
+
// Service matched
|
|
320
350
|
if (service) {
|
|
321
351
|
debug("Internal service matched", service.name);
|
|
322
352
|
const variables = service.config(ctx);
|
|
@@ -327,8 +357,9 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
327
357
|
debug("CI environment", ciEnvironment);
|
|
328
358
|
return ciEnvironment;
|
|
329
359
|
}
|
|
360
|
+
// We fallback on "env-ci" library, not very good but it's better than nothing
|
|
330
361
|
debug("Falling back on env-ci");
|
|
331
|
-
const ciEnvironment1 =
|
|
362
|
+
const ciEnvironment1 = getCiEnvironmentFromEnvCi(ctx);
|
|
332
363
|
debug("CI environment", ciEnvironment1);
|
|
333
364
|
return ciEnvironment1;
|
|
334
365
|
};
|
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.4.
|
|
4
|
+
"version": "0.4.2",
|
|
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.7.
|
|
43
|
+
"@argos-ci/core": "^0.7.2",
|
|
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": "
|
|
52
|
+
"gitHead": "7adf2cb62ceb13887c7ddf675f4d19e2bd2572b9"
|
|
53
53
|
}
|