From 8fef33543d8c1aa89e2eb5fb638889d7a43353da Mon Sep 17 00:00:00 2001 From: rory Date: Thu, 14 Sep 2023 09:27:00 +0800 Subject: [PATCH 1/4] Only one active deploy at a time --- .github/workflows/platformDeploy.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index ad002e164837..5eef07f4c7f4 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -12,6 +12,10 @@ env: SHOULD_DEPLOY_PRODUCTION: ${{ github.event_name == 'release' }} DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }} + cancel-in-progress: true + jobs: validateActor: runs-on: ubuntu-latest From 83d2dbb3e8cc94ba36e231e3bddad42185278a6c Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 3 Nov 2023 16:06:11 -0700 Subject: [PATCH 2/4] Skip deploy comment if workflow was cancelled --- .github/workflows/platformDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index 5eef07f4c7f4..d6b66f33ffe8 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -410,7 +410,7 @@ jobs: postGithubComment: name: Post a GitHub comment when platforms are done building and deploying runs-on: ubuntu-latest - if: ${{ always() }} + if: ${{ always() && !cancelled() }} needs: [android, desktop, iOS, web] steps: - name: Checkout From b3712b3186d92d4da962af03f58af2b61834a9db Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 3 Nov 2023 16:44:31 -0700 Subject: [PATCH 3/4] Rebuild getDeployPullRequestList to look at completed deploys rather than tags/releases --- .../getDeployPullRequestList.js | 84 +++++------- .../getDeployPullRequestList/index.js | 129 ++++++++---------- 2 files changed, 94 insertions(+), 119 deletions(-) diff --git a/.github/actions/javascript/getDeployPullRequestList/getDeployPullRequestList.js b/.github/actions/javascript/getDeployPullRequestList/getDeployPullRequestList.js index 61e0eac5dc28..ad1668ecd597 100644 --- a/.github/actions/javascript/getDeployPullRequestList/getDeployPullRequestList.js +++ b/.github/actions/javascript/getDeployPullRequestList/getDeployPullRequestList.js @@ -5,58 +5,42 @@ const ActionUtils = require('../../../libs/ActionUtils'); const GitUtils = require('../../../libs/GitUtils'); const GithubUtils = require('../../../libs/GithubUtils'); -const inputTag = core.getInput('TAG', {required: true}); - -const isProductionDeploy = ActionUtils.getJSONInput('IS_PRODUCTION_DEPLOY', {required: false}, false); -const itemToFetch = isProductionDeploy ? 'release' : 'tag'; +async function run() { + try { + const inputTag = core.getInput('TAG', {required: true}); + const isProductionDeploy = ActionUtils.getJSONInput('IS_PRODUCTION_DEPLOY', {required: false}, false); + const deployEnv = isProductionDeploy ? 'production' : 'staging'; + + console.log(`Looking for PRs deployed to ${deployEnv} in ${inputTag}...`); + + const completedDeploys = ( + await GithubUtils.octokit.actions.listWorkflowRuns({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + workflow_id: 'platformDeploy.yml', + status: 'completed', + event: isProductionDeploy ? 'release' : 'push', + }) + ).data.workflow_runs; + + const inputTagIndex = _.findIndex(completedDeploys, (workflowRun) => workflowRun.head_branch === inputTag); + if (inputTagIndex < 0) { + throw new Error(`No completed deploy found for input tag ${inputTag}`); + } -/** - * Gets either releases or tags for a GitHub repo - * - * @param {boolean} fetchReleases - * @returns {*} - */ -function getTagsOrReleases(fetchReleases) { - if (fetchReleases) { - return GithubUtils.octokit.repos.listReleases({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - }); + const priorTag = completedDeploys[inputTagIndex + 1].head_branch; + console.log(`Looking for PRs deployed to ${deployEnv} between ${priorTag} and ${inputTag}`); + const prList = await GitUtils.getPullRequestsMergedBetween(priorTag, inputTag); + console.log(`Found the pull request list: ${prList}`); + core.setOutput('PR_LIST', prList); + } catch (err) { + console.error(err.message); + core.setFailed(err); } - - return GithubUtils.octokit.repos.listTags({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - }); } -console.log(`Fetching ${itemToFetch} list from github...`); -getTagsOrReleases(isProductionDeploy) - .catch((githubError) => core.setFailed(githubError)) - .then(({data}) => { - const keyToPluck = isProductionDeploy ? 'tag_name' : 'name'; - const tags = _.pluck(data, keyToPluck); - const priorTagIndex = _.indexOf(tags, inputTag) + 1; - - if (priorTagIndex === 0) { - console.log(`No ${itemToFetch} was found for input tag ${inputTag}. Comparing it to latest ${itemToFetch} ${tags[0]}`); - } - - if (priorTagIndex === tags.length) { - const err = new Error("Somehow, the input tag was at the end of the paginated result, so we don't have the prior tag"); - console.error(err.message); - core.setFailed(err); - return; - } - - const priorTag = tags[priorTagIndex]; - console.log(`Given ${itemToFetch}: ${inputTag}`); - console.log(`Prior ${itemToFetch}: ${priorTag}`); +if (require.main === module) { + run(); +} - return GitUtils.getPullRequestsMergedBetween(priorTag, inputTag); - }) - .then((pullRequestList) => { - console.log(`Found the pull request list: ${pullRequestList}`); - return core.setOutput('PR_LIST', pullRequestList); - }) - .catch((error) => core.setFailed(error)); +module.exports = run; diff --git a/.github/actions/javascript/getDeployPullRequestList/index.js b/.github/actions/javascript/getDeployPullRequestList/index.js index 96a6b0c4c2ac..a795b2bab9a7 100644 --- a/.github/actions/javascript/getDeployPullRequestList/index.js +++ b/.github/actions/javascript/getDeployPullRequestList/index.js @@ -4,6 +4,59 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ +/***/ 5847: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +const _ = __nccwpck_require__(5067); +const core = __nccwpck_require__(2186); +const github = __nccwpck_require__(5438); +const ActionUtils = __nccwpck_require__(970); +const GitUtils = __nccwpck_require__(669); +const GithubUtils = __nccwpck_require__(7999); + +async function run() { + try { + const inputTag = core.getInput('TAG', {required: true}); + const isProductionDeploy = ActionUtils.getJSONInput('IS_PRODUCTION_DEPLOY', {required: false}, false); + const deployEnv = isProductionDeploy ? 'production' : 'staging'; + + console.log(`Looking for PRs deployed to ${deployEnv} in ${inputTag}...`); + + const completedDeploys = ( + await GithubUtils.octokit.actions.listWorkflowRuns({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + workflow_id: 'platformDeploy.yml', + status: 'completed', + event: isProductionDeploy ? 'release' : 'push', + }) + ).data.workflow_runs; + + const inputTagIndex = _.findIndex(completedDeploys, (workflowRun) => workflowRun.head_branch === inputTag); + if (inputTagIndex < 0) { + throw new Error(`No completed deploy found for input tag ${inputTag}`); + } + + const priorTag = completedDeploys[inputTagIndex + 1].head_branch; + console.log(`Looking for PRs deployed to ${deployEnv} between ${priorTag} and ${inputTag}`); + const prList = await GitUtils.getPullRequestsMergedBetween(priorTag, inputTag); + console.log(`Found the pull request list: ${prList}`); + core.setOutput('PR_LIST', prList); + } catch (err) { + console.error(err.message); + core.setFailed(err); + } +} + +if (require.main === require.cache[eval('__filename')]) { + run(); +} + +module.exports = run; + + +/***/ }), + /***/ 970: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { @@ -19556,74 +19609,12 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ -var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. -(() => { -const _ = __nccwpck_require__(5067); -const core = __nccwpck_require__(2186); -const github = __nccwpck_require__(5438); -const ActionUtils = __nccwpck_require__(970); -const GitUtils = __nccwpck_require__(669); -const GithubUtils = __nccwpck_require__(7999); - -const inputTag = core.getInput('TAG', {required: true}); - -const isProductionDeploy = ActionUtils.getJSONInput('IS_PRODUCTION_DEPLOY', {required: false}, false); -const itemToFetch = isProductionDeploy ? 'release' : 'tag'; - -/** - * Gets either releases or tags for a GitHub repo - * - * @param {boolean} fetchReleases - * @returns {*} - */ -function getTagsOrReleases(fetchReleases) { - if (fetchReleases) { - return GithubUtils.octokit.repos.listReleases({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - }); - } - - return GithubUtils.octokit.repos.listTags({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - }); -} - -console.log(`Fetching ${itemToFetch} list from github...`); -getTagsOrReleases(isProductionDeploy) - .catch((githubError) => core.setFailed(githubError)) - .then(({data}) => { - const keyToPluck = isProductionDeploy ? 'tag_name' : 'name'; - const tags = _.pluck(data, keyToPluck); - const priorTagIndex = _.indexOf(tags, inputTag) + 1; - - if (priorTagIndex === 0) { - console.log(`No ${itemToFetch} was found for input tag ${inputTag}. Comparing it to latest ${itemToFetch} ${tags[0]}`); - } - - if (priorTagIndex === tags.length) { - const err = new Error("Somehow, the input tag was at the end of the paginated result, so we don't have the prior tag"); - console.error(err.message); - core.setFailed(err); - return; - } - - const priorTag = tags[priorTagIndex]; - console.log(`Given ${itemToFetch}: ${inputTag}`); - console.log(`Prior ${itemToFetch}: ${priorTag}`); - - return GitUtils.getPullRequestsMergedBetween(priorTag, inputTag); - }) - .then((pullRequestList) => { - console.log(`Found the pull request list: ${pullRequestList}`); - return core.setOutput('PR_LIST', pullRequestList); - }) - .catch((error) => core.setFailed(error)); - -})(); - -module.exports = __webpack_exports__; +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __nccwpck_require__(5847); +/******/ module.exports = __webpack_exports__; +/******/ /******/ })() ; From 8adb043b4f0ab4d3d5bd3e1ff0823f01cba1e459 Mon Sep 17 00:00:00 2001 From: Rory Abraham <47436092+roryabraham@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:44:39 -0800 Subject: [PATCH 4/4] Use not cancelled alone instead of always Co-authored-by: Carlos Martins --- .github/workflows/platformDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index 9346b1ff76cc..d494ea0d008b 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -424,7 +424,7 @@ jobs: postGithubComment: name: Post a GitHub comment when platforms are done building and deploying runs-on: ubuntu-latest - if: ${{ always() && !cancelled() }} + if: ${{ !cancelled() }} needs: [android, desktop, iOS, web] steps: - name: Checkout