@argos-ci/core 0.7.2 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +16 -52
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import convict from 'convict';
2
2
  import { execSync } from 'node:child_process';
3
- import { execSync as execSync$1 } from 'child_process';
3
+ import { existsSync, readFileSync, createReadStream } from 'node:fs';
4
4
  import createDebug from 'debug';
5
5
  import envCi from 'env-ci';
6
6
  import { resolve } from 'node:path';
@@ -8,7 +8,6 @@ import glob from 'fast-glob';
8
8
  import { promisify } from 'node:util';
9
9
  import sharp from 'sharp';
10
10
  import tmp from 'tmp';
11
- import { createReadStream } from 'node:fs';
12
11
  import { createHash } from 'node:crypto';
13
12
  import axios from 'axios';
14
13
  import { readFile } from 'node:fs/promises';
@@ -170,39 +169,6 @@ const service$3 = {
170
169
  })
171
170
  };
172
171
 
173
- const getSha = ({ env })=>{
174
- const isPr = env.GITHUB_EVENT_NAME === "pull_request" || env.GITHUB_EVENT_NAME === "pull_request_target";
175
- if (isPr) {
176
- const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
177
- const mergeCommitMessage = execSync$1("git show --no-patch --format=%P").toString().trim();
178
- // console.log(
179
- // `Handling PR with parent hash(es) '${mergeCommitMessage}' of current commit.`
180
- // );
181
- if (mergeCommitRegex.exec(mergeCommitMessage)) {
182
- const mergeCommit = mergeCommitMessage.split(" ")[1];
183
- // console.log(
184
- // `Fixing merge commit SHA ${process.env.GITHUB_SHA} -> ${mergeCommit}`
185
- // );
186
- return mergeCommit;
187
- } else if (mergeCommitMessage === "") {
188
- console.error(`Error: automatic detection of commit SHA failed.
189
-
190
- Please run "actions/checkout" with "fetch-depth: 2". Example:
191
-
192
- steps:
193
- - uses: actions/checkout@v3
194
- with:
195
- fetch-depth: 2
196
-
197
- `);
198
- process.exit(1);
199
- } else {
200
- console.error(`Commit with SHA ${process.env.GITHUB_SHA} is not a valid commit`);
201
- process.exit(1);
202
- }
203
- }
204
- return process.env.GITHUB_SHA ?? null;
205
- };
206
172
  const getBranch = ({ env })=>{
207
173
  if (env.GITHUB_HEAD_REF) {
208
174
  return env.GITHUB_HEAD_REF;
@@ -218,34 +184,32 @@ const getRepository$1 = ({ env })=>{
218
184
  if (!env.GITHUB_REPOSITORY) return null;
219
185
  return env.GITHUB_REPOSITORY.split("/")[1];
220
186
  };
221
- const getPrNumber$2 = ({ env })=>{
222
- const branchRegex = /refs\/pull\/(\d+)/;
223
- const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
224
- if (branchMatches) {
225
- return Number(branchMatches[1]);
226
- }
227
- return null;
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"));
228
191
  };
229
192
  const service$2 = {
230
193
  name: "GitHub Actions",
231
194
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
232
- config: ({ env })=>({
233
- commit: getSha({
234
- env
235
- }),
236
- branch: getBranch({
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({
237
202
  env
238
- }),
203
+ }) || null,
239
204
  owner: env.GITHUB_REPOSITORY_OWNER || null,
240
205
  repository: getRepository$1({
241
206
  env
242
207
  }),
243
208
  jobId: env.GITHUB_JOB || null,
244
209
  runId: env.GITHUB_RUN_ID || null,
245
- prNumber: getPrNumber$2({
246
- env
247
- })
248
- })
210
+ prNumber: payload?.pull_request?.number || null
211
+ };
212
+ }
249
213
  };
250
214
 
251
215
  const getPrNumber$1 = ({ env })=>{
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.2",
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": "7adf2cb62ceb13887c7ddf675f4d19e2bd2572b9"
63
+ "gitHead": "56d7e2259161c49265d8983ce0f0ecfe71910d2b"
64
64
  }