From 776ea57cf923b4b6935f794acb736ea2f7120663 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Fri, 20 May 2022 08:56:27 -0500 Subject: [PATCH] fix(set-latest-pipeline-status): stop failing when no deployments found (#202) --- dist/0.index.js | 4 ++-- dist/0.index.js.map | 2 +- src/helpers/set-latest-pipeline-status.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/0.index.js b/dist/0.index.js index fc5937843..cb6036a7d 100644 --- a/dist/0.index.js +++ b/dist/0.index.js @@ -105,8 +105,8 @@ const setLatestPipelineStatus = ({ sha, context = _constants__WEBPACK_IMPORTED_M const { data: deployments } = yield _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit.repos.listDeployments */ .K.repos.listDeployments(Object.assign(Object.assign({ environment }, _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_1__/* .GITHUB_OPTIONS */ .Cc)); const deployment_id = (_a = deployments.find(Boolean)) === null || _a === void 0 ? void 0 : _a.id; if (!deployment_id) { - _actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed('No deployments found. There must be a GitHub deployment on your repository before this helper can run.'); - throw new Error(); + _actions_core__WEBPACK_IMPORTED_MODULE_0__.info('No deployments found. Pipeline is clear!'); + return; } const { data: deploymentStatuses } = yield _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit.repos.listDeploymentStatuses */ .K.repos.listDeploymentStatuses(Object.assign(Object.assign({ deployment_id }, _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_1__/* .GITHUB_OPTIONS */ .Cc)); const deploymentStatus = (_b = deploymentStatuses.find(Boolean)) !== null && _b !== void 0 ? _b : {}; diff --git a/dist/0.index.js.map b/dist/0.index.js.map index 11c526c10..00e351ce6 100644 --- a/dist/0.index.js.map +++ b/dist/0.index.js.map @@ -1 +1 @@ -{"version":3,"file":"0.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AACA;AAEA;AAAA;AACA;AAGA;AAAA;AAEA;;AAKA;AAKA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AAEA;AAGA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;AC9DA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/set-latest-pipeline-status.ts","webpack://github-helpers/./src/octokit.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const DEFAULT_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { DeploymentStatus, PipelineState } from '../types';\nimport { context as githubContext } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class SetLatestPipelineStatus {\n sha = '';\n context?: string;\n environment?: string;\n}\n\nexport const setLatestPipelineStatus = async ({\n sha,\n context = DEFAULT_PIPELINE_STATUS,\n environment = PRODUCTION_ENVIRONMENT\n}: SetLatestPipelineStatus) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) {\n core.setFailed('No deployments found. There must be a GitHub deployment on your repository before this helper can run.');\n throw new Error();\n }\n const { data: deploymentStatuses } = await octokit.repos.listDeploymentStatuses({\n deployment_id,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deploymentStatus = deploymentStatuses.find(Boolean) ?? ({} as DeploymentStatus);\n const { state, description, target_url } = deploymentStatus;\n return octokit.repos.createCommitStatus({\n sha,\n context,\n state: deploymentStateToPipelineStateMap[state] ?? 'pending',\n description,\n target_url,\n ...githubContext.repo\n });\n};\n\nconst deploymentStateToPipelineStateMap: { [deploymentState: string]: PipelineState } = {\n in_progress: 'pending',\n success: 'success',\n failure: 'failure',\n inactive: 'error'\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const octokit = getOctokit(githubToken, { request: { fetch } }).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"0.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AACA;AAEA;AAAA;AACA;AAGA;AAAA;AAEA;;AAKA;AAKA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AAEA;AAGA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;AC9DA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/set-latest-pipeline-status.ts","webpack://github-helpers/./src/octokit.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const DEFAULT_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { DeploymentStatus, PipelineState } from '../types';\nimport { context as githubContext } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class SetLatestPipelineStatus {\n sha = '';\n context?: string;\n environment?: string;\n}\n\nexport const setLatestPipelineStatus = async ({\n sha,\n context = DEFAULT_PIPELINE_STATUS,\n environment = PRODUCTION_ENVIRONMENT\n}: SetLatestPipelineStatus) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) {\n core.info('No deployments found. Pipeline is clear!');\n return;\n }\n const { data: deploymentStatuses } = await octokit.repos.listDeploymentStatuses({\n deployment_id,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deploymentStatus = deploymentStatuses.find(Boolean) ?? ({} as DeploymentStatus);\n const { state, description, target_url } = deploymentStatus;\n return octokit.repos.createCommitStatus({\n sha,\n context,\n state: deploymentStateToPipelineStateMap[state] ?? 'pending',\n description,\n target_url,\n ...githubContext.repo\n });\n};\n\nconst deploymentStateToPipelineStateMap: { [deploymentState: string]: PipelineState } = {\n in_progress: 'pending',\n success: 'success',\n failure: 'failure',\n inactive: 'error'\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const octokit = getOctokit(githubToken, { request: { fetch } }).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/set-latest-pipeline-status.ts b/src/helpers/set-latest-pipeline-status.ts index 56bb97f1e..76e5babc3 100644 --- a/src/helpers/set-latest-pipeline-status.ts +++ b/src/helpers/set-latest-pipeline-status.ts @@ -35,8 +35,8 @@ export const setLatestPipelineStatus = async ({ }); const deployment_id = deployments.find(Boolean)?.id; if (!deployment_id) { - core.setFailed('No deployments found. There must be a GitHub deployment on your repository before this helper can run.'); - throw new Error(); + core.info('No deployments found. Pipeline is clear!'); + return; } const { data: deploymentStatuses } = await octokit.repos.listDeploymentStatuses({ deployment_id,