From eb2c7f5abcb6d17145cee7523bd64c8c673a4ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Thu, 12 Aug 2021 13:13:03 +0200 Subject: [PATCH 1/7] Assign cherry pick prs to the deployer --- .github/workflows/cherryPick.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/cherryPick.yml b/.github/workflows/cherryPick.yml index 8eaef2c1c80b..2710b2202390 100644 --- a/.github/workflows/cherryPick.yml +++ b/.github/workflows/cherryPick.yml @@ -151,6 +151,14 @@ jobs: Engineering Hourly + - name: Assign the PR to the deployer + if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }} + uses: actions-ecosystem/action-add-assignees@a73fcabd82d847c5e7433fcfdd58ef9f7e8a3993 + with: + number: ${{ steps.createPullRequest.outputs.pr_number }} + github_token: ${{ secrets.GITHUB_TOKEN }} + assignees: ${{ github.actor }} + - name: If PR has merge conflicts, comment with instructions for assignee if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }} uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac From 2a16ef8dab73eb1df7908922553aa25bc48adc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Fri, 13 Aug 2021 12:07:39 +0200 Subject: [PATCH 2/7] Output merge actor from getMergeCommitForPullRequest --- .../getMergeCommitForPullRequest.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js b/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js index 7d0e0b1f0e17..a83f5ae70683 100644 --- a/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js +++ b/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js @@ -9,7 +9,7 @@ const DEFAULT_PAYLOAD = { }; const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null); -const user = core.getInput('USER', {required: false}); +const user = core.getInput('USER', {required: true}); let titleRegex = core.getInput('TITLE_REGEX', {required: false}); if (pullRequestNumber) { @@ -41,6 +41,27 @@ function outputMergeCommitHash(PR) { } } +/** + * Process a pull request and outputs it's merge actor + * + * @param {Object} PR + */ +function outputMergeActor(PR) { + if (!_.isEmpty(PR)) { + console.log(`Found matching pull request: ${PR.html_url}`); + + if (user === 'OSBotify') { + core.setOutput('MERGE_ACTOR', PR.merged_by.login); + } else { + core.setOutput('MERGE_ACTOR', user); + } + } else { + const err = new Error('Could not find matching pull request'); + console.error(err); + core.setFailed(err); + } +} + /** * Handle an unknown API error. * @@ -56,7 +77,10 @@ if (pullRequestNumber) { ...DEFAULT_PAYLOAD, pull_number: pullRequestNumber, }) - .then(({data}) => outputMergeCommitHash(data)) + .then(({data}) => { + outputMergeCommitHash(data); + outputMergeActor(data); + }) .catch(handleUnknownError); } else { GithubUtils.octokit.pulls.list({ @@ -66,5 +90,6 @@ if (pullRequestNumber) { .then(({data}) => { const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title)); outputMergeCommitHash(matchingPR); + outputMergeActor(matchingPR); }); } From 6d0612a86bebe3b777a40a6053648bc6650a96e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Fri, 13 Aug 2021 12:08:12 +0200 Subject: [PATCH 3/7] Assign the PR to the merge actor --- .github/workflows/cherryPick.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cherryPick.yml b/.github/workflows/cherryPick.yml index 2710b2202390..c07812013050 100644 --- a/.github/workflows/cherryPick.yml +++ b/.github/workflows/cherryPick.yml @@ -80,6 +80,7 @@ jobs: uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@main with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + USER: ${{ github.actor }} PULL_REQUEST_NUMBER: ${{ github.event.inputs.PULL_REQUEST_NUMBER }} - name: Save correct NEW_VERSION to env @@ -157,7 +158,7 @@ jobs: with: number: ${{ steps.createPullRequest.outputs.pr_number }} github_token: ${{ secrets.GITHUB_TOKEN }} - assignees: ${{ github.actor }} + assignees: ${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }} - name: If PR has merge conflicts, comment with instructions for assignee if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }} From abd87015f68eab851d6527b3617020c58912759b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Fri, 13 Aug 2021 12:11:22 +0200 Subject: [PATCH 4/7] Build actions --- .../getMergeCommitForPullRequest/index.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/actions/getMergeCommitForPullRequest/index.js b/.github/actions/getMergeCommitForPullRequest/index.js index b3a71def18a9..461de9dacf02 100644 --- a/.github/actions/getMergeCommitForPullRequest/index.js +++ b/.github/actions/getMergeCommitForPullRequest/index.js @@ -19,7 +19,7 @@ const DEFAULT_PAYLOAD = { }; const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null); -const user = core.getInput('USER', {required: false}); +const user = core.getInput('USER', {required: true}); let titleRegex = core.getInput('TITLE_REGEX', {required: false}); if (pullRequestNumber) { @@ -51,6 +51,27 @@ function outputMergeCommitHash(PR) { } } +/** + * Process a pull request and outputs it's merge actor + * + * @param {Object} PR + */ +function outputMergeActor(PR) { + if (!_.isEmpty(PR)) { + console.log(`Found matching pull request: ${PR.html_url}`); + + if (user === 'OSBotify') { + core.setOutput('MERGE_ACTOR', PR.merged_by.login); + } else { + core.setOutput('MERGE_ACTOR', user); + } + } else { + const err = new Error('Could not find matching pull request'); + console.error(err); + core.setFailed(err); + } +} + /** * Handle an unknown API error. * @@ -66,7 +87,10 @@ if (pullRequestNumber) { ...DEFAULT_PAYLOAD, pull_number: pullRequestNumber, }) - .then(({data}) => outputMergeCommitHash(data)) + .then(({data}) => { + outputMergeCommitHash(data); + outputMergeActor(data); + }) .catch(handleUnknownError); } else { GithubUtils.octokit.pulls.list({ @@ -76,6 +100,7 @@ if (pullRequestNumber) { .then(({data}) => { const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title)); outputMergeCommitHash(matchingPR); + outputMergeActor(matchingPR); }); } From dd204b32ac2405e4c6bbafec7feaee287671fb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Tue, 17 Aug 2021 17:56:24 +0200 Subject: [PATCH 5/7] Rename action to getPullRequestDetails.js and add output --- .../action.yml | 6 ++++-- .../getPullRequestDetails.js} | 0 .../index.js | 4 ++-- .github/scripts/buildActions.sh | 2 +- .github/workflows/cherryPick.yml | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) rename .github/actions/{getMergeCommitForPullRequest => getPullRequestDetails}/action.yml (74%) rename .github/actions/{getMergeCommitForPullRequest/getMergeCommitForPullRequest.js => getPullRequestDetails/getPullRequestDetails.js} (100%) rename .github/actions/{getMergeCommitForPullRequest => getPullRequestDetails}/index.js (99%) diff --git a/.github/actions/getMergeCommitForPullRequest/action.yml b/.github/actions/getPullRequestDetails/action.yml similarity index 74% rename from .github/actions/getMergeCommitForPullRequest/action.yml rename to .github/actions/getPullRequestDetails/action.yml index 6ffcb5888598..e33aaef7cb38 100644 --- a/.github/actions/getMergeCommitForPullRequest/action.yml +++ b/.github/actions/getPullRequestDetails/action.yml @@ -1,5 +1,5 @@ -name: 'Get merge commit for a pull request' -description: 'Get the merge_commit_sha for a pull request' +name: 'Get the details of a pull request' +description: 'Get the details of a pull request' inputs: GITHUB_TOKEN: description: Auth token for New Expensify Github @@ -16,6 +16,8 @@ inputs: outputs: MERGE_COMMIT_SHA: description: 'The merge_commit_sha of the given pull request' + MERGE_ACTOR: + description: 'The actor who merged the pull request' runs: using: 'node12' main: './index.js' diff --git a/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js b/.github/actions/getPullRequestDetails/getPullRequestDetails.js similarity index 100% rename from .github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js rename to .github/actions/getPullRequestDetails/getPullRequestDetails.js diff --git a/.github/actions/getMergeCommitForPullRequest/index.js b/.github/actions/getPullRequestDetails/index.js similarity index 99% rename from .github/actions/getMergeCommitForPullRequest/index.js rename to .github/actions/getPullRequestDetails/index.js index 461de9dacf02..6982db60a6e0 100644 --- a/.github/actions/getMergeCommitForPullRequest/index.js +++ b/.github/actions/getPullRequestDetails/index.js @@ -5,7 +5,7 @@ module.exports = /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 265: +/***/ 1751: /***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { const _ = __nccwpck_require__(4987); @@ -15088,6 +15088,6 @@ module.exports = require("zlib");; /******/ // module exports must be returned from runtime so entry inlining is disabled /******/ // startup /******/ // Load entry module and return exports -/******/ return __nccwpck_require__(265); +/******/ return __nccwpck_require__(1751); /******/ })() ; diff --git a/.github/scripts/buildActions.sh b/.github/scripts/buildActions.sh index 5b417b094f99..79b80c0704c6 100755 --- a/.github/scripts/buildActions.sh +++ b/.github/scripts/buildActions.sh @@ -13,7 +13,7 @@ declare -r GITHUB_ACTIONS=( "$ACTIONS_DIR/checkDeployBlockers/checkDeployBlockers.js" "$ACTIONS_DIR/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.js" "$ACTIONS_DIR/getDeployPullRequestList/getDeployPullRequestList.js" - "$ACTIONS_DIR/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js" + "$ACTIONS_DIR/getPullRequestDetails/getPullRequestDetails.js" "$ACTIONS_DIR/getReleaseBody/getReleaseBody.js" "$ACTIONS_DIR/isPullRequestMergeable/isPullRequestMergeable.js" "$ACTIONS_DIR/isStagingDeployLocked/isStagingDeployLocked.js" diff --git a/.github/workflows/cherryPick.yml b/.github/workflows/cherryPick.yml index c07812013050..e13d81ae6918 100644 --- a/.github/workflows/cherryPick.yml +++ b/.github/workflows/cherryPick.yml @@ -77,7 +77,7 @@ jobs: - name: Get merge commit for CP pull request id: getCPMergeCommit - uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@main + uses: Expensify/App/.github/actions/getPullRequestDetails@main with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} USER: ${{ github.actor }} @@ -95,7 +95,7 @@ jobs: - name: Get merge commit for version-bump pull request id: getVersionBumpMergeCommit - uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@main + uses: Expensify/App/.github/actions/getPullRequestDetails@main with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} USER: OSBotify From 83cde1d57ae8179d1d08406183ed95f2d0ebd9a4 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Thu, 2 Sep 2021 12:50:11 +0200 Subject: [PATCH 6/7] Explicitly decode json variables Co-authored-by: Rory Abraham <47436092+roryabraham@users.noreply.github.com> --- .github/workflows/cherryPick.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cherryPick.yml b/.github/workflows/cherryPick.yml index e13d81ae6918..4f56cadbfa1a 100644 --- a/.github/workflows/cherryPick.yml +++ b/.github/workflows/cherryPick.yml @@ -153,7 +153,7 @@ jobs: Hourly - name: Assign the PR to the deployer - if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }} + if: ${{ !fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) || !fromJSON(steps.isPullRequestMergeable.outputs.IS_MERGEABLE) }} uses: actions-ecosystem/action-add-assignees@a73fcabd82d847c5e7433fcfdd58ef9f7e8a3993 with: number: ${{ steps.createPullRequest.outputs.pr_number }} From 158ec67befa07b8b1db1efeadd6390ffd087f8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horus=20Lugo=20L=C3=B3pez?= Date: Thu, 2 Sep 2021 12:55:28 +0200 Subject: [PATCH 7/7] Make USER input required --- .github/actions/getPullRequestDetails/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/getPullRequestDetails/action.yml b/.github/actions/getPullRequestDetails/action.yml index e33aaef7cb38..dbb3e2283686 100644 --- a/.github/actions/getPullRequestDetails/action.yml +++ b/.github/actions/getPullRequestDetails/action.yml @@ -12,7 +12,7 @@ inputs: required: false USER: description: The creator of the pull request - required: false + required: true outputs: MERGE_COMMIT_SHA: description: 'The merge_commit_sha of the given pull request'