@argos-ci/cli 0.4.1 → 0.4.3
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 +99 -104
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -3,14 +3,14 @@ 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 {
|
|
6
|
+
import { execSync } from 'node:child_process';
|
|
7
|
+
import { existsSync, readFileSync, createReadStream } from 'node:fs';
|
|
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';
|
|
12
13
|
import tmp from 'tmp';
|
|
13
|
-
import { createReadStream } from 'node:fs';
|
|
14
14
|
import { createHash } from 'node:crypto';
|
|
15
15
|
import axios from 'axios';
|
|
16
16
|
import ora from 'ora';
|
|
@@ -118,20 +118,41 @@ const createConfig = ()=>{
|
|
|
118
118
|
});
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Returns the head commit.
|
|
123
|
+
*/ const head = ()=>{
|
|
124
|
+
try {
|
|
125
|
+
return execSync("git rev-parse HEAD").toString().trim();
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Returns the current branch.
|
|
132
|
+
*/ const branch = ()=>{
|
|
133
|
+
try {
|
|
134
|
+
const headRef = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
135
|
+
if (headRef === "HEAD") {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return headRef;
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
121
144
|
const service$4 = {
|
|
122
145
|
name: "Buildkite",
|
|
123
146
|
detect: ({ env })=>Boolean(env.BUILDKITE),
|
|
124
147
|
config: ({ env })=>{
|
|
125
|
-
const ciProps = envCiDetection({
|
|
126
|
-
env
|
|
127
|
-
});
|
|
128
148
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
149
|
+
// Buildkite doesn't work well so we fallback to git to ensure we have commit and branch
|
|
150
|
+
commit: env.BUILDKITE_COMMIT || head() || null,
|
|
151
|
+
branch: env.BUILDKITE_BRANCH || branch() || null,
|
|
131
152
|
owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
|
|
132
153
|
repository: env.BUILDKITE_PROJECT_SLUG || null,
|
|
133
|
-
jobId:
|
|
134
|
-
runId:
|
|
154
|
+
jobId: null,
|
|
155
|
+
runId: null,
|
|
135
156
|
prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null
|
|
136
157
|
};
|
|
137
158
|
}
|
|
@@ -145,95 +166,60 @@ const service$3 = {
|
|
|
145
166
|
branch: env.HEROKU_TEST_RUN_BRANCH || null,
|
|
146
167
|
owner: null,
|
|
147
168
|
repository: null,
|
|
148
|
-
jobId:
|
|
169
|
+
jobId: null,
|
|
149
170
|
runId: null,
|
|
150
171
|
prNumber: null
|
|
151
172
|
})
|
|
152
173
|
};
|
|
153
174
|
|
|
154
|
-
const
|
|
155
|
-
const isPr = env.GITHUB_EVENT_NAME === "pull_request" || env.GITHUB_EVENT_NAME === "pull_request_target";
|
|
156
|
-
if (isPr) {
|
|
157
|
-
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
|
|
158
|
-
const mergeCommitMessage = execSync("git show --no-patch --format=%P").toString().trim();
|
|
159
|
-
// console.log(
|
|
160
|
-
// `Handling PR with parent hash(es) '${mergeCommitMessage}' of current commit.`
|
|
161
|
-
// );
|
|
162
|
-
if (mergeCommitRegex.exec(mergeCommitMessage)) {
|
|
163
|
-
const mergeCommit = mergeCommitMessage.split(" ")[1];
|
|
164
|
-
// console.log(
|
|
165
|
-
// `Fixing merge commit SHA ${process.env.GITHUB_SHA} -> ${mergeCommit}`
|
|
166
|
-
// );
|
|
167
|
-
return mergeCommit;
|
|
168
|
-
} else if (mergeCommitMessage === "") {
|
|
169
|
-
console.error(`Error: automatic detection of commit SHA failed.
|
|
170
|
-
|
|
171
|
-
Please run "actions/checkout" with "fetch-depth: 2". Example:
|
|
172
|
-
|
|
173
|
-
steps:
|
|
174
|
-
- uses: actions/checkout@v3
|
|
175
|
-
with:
|
|
176
|
-
fetch-depth: 2
|
|
177
|
-
|
|
178
|
-
`);
|
|
179
|
-
process.exit(1);
|
|
180
|
-
} else {
|
|
181
|
-
console.error(`Commit with SHA ${process.env.GITHUB_SHA} is not a valid commit`);
|
|
182
|
-
process.exit(1);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return process.env.GITHUB_SHA ?? null;
|
|
186
|
-
};
|
|
187
|
-
function getBranch({ env }) {
|
|
175
|
+
const getBranch = ({ env })=>{
|
|
188
176
|
if (env.GITHUB_HEAD_REF) {
|
|
189
177
|
return env.GITHUB_HEAD_REF;
|
|
190
178
|
}
|
|
191
179
|
const branchRegex = /refs\/heads\/(.*)/;
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
return
|
|
180
|
+
const matches = branchRegex.exec(env.GITHUB_REF || "");
|
|
181
|
+
if (matches) {
|
|
182
|
+
return matches[1];
|
|
195
183
|
}
|
|
196
184
|
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
185
|
+
};
|
|
186
|
+
const getRepository$1 = ({ env })=>{
|
|
199
187
|
if (!env.GITHUB_REPOSITORY) return null;
|
|
200
188
|
return env.GITHUB_REPOSITORY.split("/")[1];
|
|
201
|
-
}
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return Number(branchMatches[1]);
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
189
|
+
};
|
|
190
|
+
const readEventPayload = ({ env })=>{
|
|
191
|
+
if (!env.GITHUB_EVENT_PATH) return null;
|
|
192
|
+
if (!existsSync(env.GITHUB_EVENT_PATH)) return null;
|
|
193
|
+
return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf-8"));
|
|
209
194
|
};
|
|
210
195
|
const service$2 = {
|
|
211
196
|
name: "GitHub Actions",
|
|
212
197
|
detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
|
|
213
|
-
config: ({ env })=>
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
198
|
+
config: ({ env })=>{
|
|
199
|
+
const payload = readEventPayload({
|
|
200
|
+
env
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
commit: payload?.pull_request?.head.sha || process.env.GITHUB_SHA || null,
|
|
204
|
+
branch: payload?.pull_request?.head.ref || getBranch({
|
|
218
205
|
env
|
|
219
|
-
}),
|
|
206
|
+
}) || null,
|
|
220
207
|
owner: env.GITHUB_REPOSITORY_OWNER || null,
|
|
221
|
-
repository: getRepository({
|
|
208
|
+
repository: getRepository$1({
|
|
222
209
|
env
|
|
223
210
|
}),
|
|
224
211
|
jobId: env.GITHUB_JOB || null,
|
|
225
212
|
runId: env.GITHUB_RUN_ID || null,
|
|
226
|
-
prNumber:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
})
|
|
213
|
+
prNumber: payload?.pull_request?.number || null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
230
216
|
};
|
|
231
217
|
|
|
232
|
-
const getPrNumber = ({ env })=>{
|
|
218
|
+
const getPrNumber$1 = ({ env })=>{
|
|
233
219
|
const branchRegex = /pull\/(\d+)/;
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
return Number(
|
|
220
|
+
const matches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
|
|
221
|
+
if (matches) {
|
|
222
|
+
return Number(matches[1]);
|
|
237
223
|
}
|
|
238
224
|
return null;
|
|
239
225
|
};
|
|
@@ -241,52 +227,52 @@ const service$1 = {
|
|
|
241
227
|
name: "CircleCI",
|
|
242
228
|
detect: ({ env })=>Boolean(env.CIRCLECI),
|
|
243
229
|
config: ({ env })=>{
|
|
244
|
-
const ciProps = envCiDetection({
|
|
245
|
-
env
|
|
246
|
-
});
|
|
247
230
|
return {
|
|
248
|
-
commit:
|
|
249
|
-
branch:
|
|
250
|
-
owner:
|
|
251
|
-
repository:
|
|
252
|
-
jobId:
|
|
253
|
-
runId:
|
|
254
|
-
prNumber: getPrNumber({
|
|
231
|
+
commit: env.CIRCLE_SHA1 || null,
|
|
232
|
+
branch: env.CIRCLE_BRANCH || null,
|
|
233
|
+
owner: env.CIRCLE_PROJECT_USERNAME || null,
|
|
234
|
+
repository: env.CIRCLE_PROJECT_REPONAME || null,
|
|
235
|
+
jobId: null,
|
|
236
|
+
runId: null,
|
|
237
|
+
prNumber: getPrNumber$1({
|
|
255
238
|
env
|
|
256
239
|
})
|
|
257
240
|
};
|
|
258
241
|
}
|
|
259
242
|
};
|
|
260
243
|
|
|
244
|
+
const getOwner = ({ env })=>{
|
|
245
|
+
if (!env.TRAVIS_REPO_SLUG) return null;
|
|
246
|
+
return env.TRAVIS_REPO_SLUG.split("/")[0] || null;
|
|
247
|
+
};
|
|
248
|
+
const getRepository = ({ env })=>{
|
|
249
|
+
if (!env.TRAVIS_REPO_SLUG) return null;
|
|
250
|
+
return env.TRAVIS_REPO_SLUG.split("/")[1] || null;
|
|
251
|
+
};
|
|
252
|
+
const getPrNumber = ({ env })=>{
|
|
253
|
+
if (env.TRAVIS_PULL_REQUEST) return Number(env.TRAVIS_PULL_REQUEST);
|
|
254
|
+
return null;
|
|
255
|
+
};
|
|
261
256
|
const service = {
|
|
262
257
|
name: "Travis CI",
|
|
263
258
|
detect: ({ env })=>Boolean(env.TRAVIS),
|
|
264
|
-
config: (
|
|
265
|
-
const
|
|
266
|
-
env
|
|
267
|
-
});
|
|
259
|
+
config: (ctx)=>{
|
|
260
|
+
const { env } = ctx;
|
|
268
261
|
return {
|
|
269
|
-
commit:
|
|
270
|
-
branch:
|
|
271
|
-
owner:
|
|
272
|
-
repository:
|
|
273
|
-
jobId:
|
|
274
|
-
runId:
|
|
275
|
-
prNumber:
|
|
262
|
+
commit: env.TRAVIS_COMMIT || null,
|
|
263
|
+
branch: env.TRAVIS_BRANCH || null,
|
|
264
|
+
owner: getOwner(ctx),
|
|
265
|
+
repository: getRepository(ctx),
|
|
266
|
+
jobId: null,
|
|
267
|
+
runId: null,
|
|
268
|
+
prNumber: getPrNumber(ctx)
|
|
276
269
|
};
|
|
277
270
|
}
|
|
278
271
|
};
|
|
279
272
|
|
|
280
273
|
const debug = createDebug("@argos-ci/core");
|
|
281
274
|
|
|
282
|
-
const
|
|
283
|
-
service$3,
|
|
284
|
-
service$2,
|
|
285
|
-
service$1,
|
|
286
|
-
service,
|
|
287
|
-
service$4
|
|
288
|
-
];
|
|
289
|
-
const envCiDetection = (ctx)=>{
|
|
275
|
+
const getCiEnvironmentFromEnvCi = (ctx)=>{
|
|
290
276
|
const ciContext = envCi(ctx);
|
|
291
277
|
const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
|
|
292
278
|
const commit = ciContext.commit ?? null;
|
|
@@ -308,6 +294,14 @@ const envCiDetection = (ctx)=>{
|
|
|
308
294
|
prNumber
|
|
309
295
|
} : null;
|
|
310
296
|
};
|
|
297
|
+
|
|
298
|
+
const services = [
|
|
299
|
+
service$3,
|
|
300
|
+
service$2,
|
|
301
|
+
service$1,
|
|
302
|
+
service,
|
|
303
|
+
service$4
|
|
304
|
+
];
|
|
311
305
|
const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
312
306
|
const ctx = {
|
|
313
307
|
env
|
|
@@ -316,7 +310,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
316
310
|
env
|
|
317
311
|
});
|
|
318
312
|
const service = services.find((service)=>service.detect(ctx));
|
|
319
|
-
//
|
|
313
|
+
// Service matched
|
|
320
314
|
if (service) {
|
|
321
315
|
debug("Internal service matched", service.name);
|
|
322
316
|
const variables = service.config(ctx);
|
|
@@ -327,8 +321,9 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
327
321
|
debug("CI environment", ciEnvironment);
|
|
328
322
|
return ciEnvironment;
|
|
329
323
|
}
|
|
324
|
+
// We fallback on "env-ci" library, not very good but it's better than nothing
|
|
330
325
|
debug("Falling back on env-ci");
|
|
331
|
-
const ciEnvironment1 =
|
|
326
|
+
const ciEnvironment1 = getCiEnvironmentFromEnvCi(ctx);
|
|
332
327
|
debug("CI environment", ciEnvironment1);
|
|
333
328
|
return ciEnvironment1;
|
|
334
329
|
};
|
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.3",
|
|
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.3",
|
|
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": "56d7e2259161c49265d8983ce0f0ecfe71910d2b"
|
|
53
53
|
}
|