@argos-ci/core
Advanced tools
Comparing version 2.11.1 to 2.12.0
@@ -184,8 +184,12 @@ // src/upload.ts | ||
` | ||
Running argos from a "deployment_status" event requires a GITHUB_TOKEN. | ||
Please add \`GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}\` as environment variable. | ||
Argos couldn\u2019t find a relevant pull request in the current environment. | ||
To resolve this, Argos requires a GITHUB_TOKEN to fetch the pull request associated with the head SHA. Please ensure the following environment variable is added: | ||
Read more at https://argos-ci.com/docs/run-on-preview-deployment | ||
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} | ||
To disable this warning, add \`DISABLE_GITHUB_TOKEN_WARNING: true\` as environment variable. | ||
For more details, check out the documentation: Read more at https://argos-ci.com/docs/run-on-preview-deployment | ||
If you want to disable this warning, you can set the following environment variable: | ||
DISABLE_GITHUB_TOKEN_WARNING: true | ||
`.trim() | ||
@@ -229,6 +233,3 @@ ); | ||
} | ||
function getBranch(context, eventPayload) { | ||
if (eventPayload?.pull_request?.head.ref) { | ||
return eventPayload.pull_request.head.ref; | ||
} | ||
function getBranchFromContext(context) { | ||
const { env } = context; | ||
@@ -245,3 +246,12 @@ if (env.GITHUB_HEAD_REF) { | ||
} | ||
function getRepository({ env }) { | ||
function getBranchFromPayload(payload) { | ||
if ("workflow_run" in payload && payload.workflow_run) { | ||
return payload.workflow_run.head_branch; | ||
} | ||
if ("deployment" in payload && payload.deployment) { | ||
return payload.deployment.environment; | ||
} | ||
return null; | ||
} | ||
function getRepositoryFromContext({ env }) { | ||
if (!env.GITHUB_REPOSITORY) return null; | ||
@@ -255,2 +265,14 @@ return env.GITHUB_REPOSITORY.split("/")[1] || null; | ||
} | ||
function getPullRequestFromPayload(payload) { | ||
if ("pull_request" in payload && payload.pull_request && payload.pull_request) { | ||
return payload.pull_request; | ||
} | ||
if ("workflow_run" in payload && payload.workflow_run && payload.workflow_run.pull_requests[0]) { | ||
return payload.workflow_run.pull_requests[0]; | ||
} | ||
if ("check_run" in payload && payload.check_run && "pull_requests" in payload.check_run && payload.check_run.pull_requests[0]) { | ||
return payload.check_run.pull_requests[0]; | ||
} | ||
return null; | ||
} | ||
var service4 = { | ||
@@ -267,31 +289,16 @@ name: "GitHub Actions", | ||
} | ||
const commonConfig = { | ||
const pullRequest = payload ? getPullRequestFromPayload(payload) : await getPullRequestFromHeadSha(context, sha); | ||
return { | ||
commit: sha, | ||
owner: env.GITHUB_REPOSITORY_OWNER || null, | ||
repository: getRepository(context), | ||
repository: getRepositoryFromContext(context), | ||
jobId: env.GITHUB_JOB || null, | ||
runId: env.GITHUB_RUN_ID || null, | ||
runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null, | ||
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null | ||
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null, | ||
branch: getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null, | ||
prNumber: pullRequest?.number || null, | ||
prHeadCommit: pullRequest?.head.sha ?? null, | ||
prBaseBranch: pullRequest?.base.ref ?? null | ||
}; | ||
if (payload?.deployment) { | ||
debug("Deployment event detected"); | ||
const pullRequest = await getPullRequestFromHeadSha(context, sha); | ||
return { | ||
...commonConfig, | ||
// If no pull request is found, we fallback to the deployment environment as branch name | ||
// Branch name is required to create a build but has no real impact on the build. | ||
branch: pullRequest?.head.ref || payload.deployment.environment || null, | ||
prNumber: pullRequest?.number || null, | ||
prHeadCommit: pullRequest?.head.sha || null, | ||
prBaseBranch: null | ||
}; | ||
} | ||
return { | ||
...commonConfig, | ||
branch: payload?.pull_request?.head.ref || getBranch(context, payload) || null, | ||
prNumber: payload?.pull_request?.number || null, | ||
prHeadCommit: payload?.pull_request?.head.sha ?? null, | ||
prBaseBranch: payload?.pull_request?.base.ref ?? null | ||
}; | ||
}, | ||
@@ -341,3 +348,3 @@ getMergeBaseCommitSha, | ||
}; | ||
var getRepository2 = ({ env }) => { | ||
var getRepository = ({ env }) => { | ||
if (!env.TRAVIS_REPO_SLUG) return null; | ||
@@ -360,3 +367,3 @@ return env.TRAVIS_REPO_SLUG.split("/")[1] || null; | ||
owner: getOwner(ctx), | ||
repository: getRepository2(ctx), | ||
repository: getRepository(ctx), | ||
jobId: null, | ||
@@ -363,0 +370,0 @@ runId: null, |
{ | ||
"name": "@argos-ci/core", | ||
"description": "Node.js SDK for visual testing with Argos.", | ||
"version": "2.11.1", | ||
"version": "2.12.0", | ||
"type": "module", | ||
@@ -53,2 +53,3 @@ "main": "./dist/index.cjs", | ||
"devDependencies": { | ||
"@octokit/webhooks": "^13.4.1", | ||
"@types/convict": "^6.1.6", | ||
@@ -63,3 +64,3 @@ "@types/debug": "^4.1.12", | ||
}, | ||
"gitHead": "1dd8b4240b76b0756d8784e3320b7f57d915aeaf" | ||
"gitHead": "88672d5cd06a792974844d1cb798641cec6e0562" | ||
} |
40990
1298
5