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