From b66a9763c0a4a7095942d33d27810280c9aad7e1 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 11 Mar 2022 01:22:02 +0000 Subject: [PATCH 1/5] Make sure to use the login of the PR author --- .github/workflows/preDeploy.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index b82fda5c6aaf..3120febcbfde 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -216,12 +216,19 @@ jobs: IS_EXPENSIFY_EMPLOYEE: ${{ fromJSON(steps.checkActor.outputs.isTeamMember) }} steps: + - name: Get merged pull request + id: getMergedPullRequest + # TODO: Point back action actions-ecosystem after https://github.com/actions-ecosystem/action-get-merged-pull-request/pull/223 is merged + uses: roryabraham/action-get-merged-pull-request@7a7a194f6ff8f3eef58c822083695a97314ebec1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Check whether the actor is member of Expensify/expensify team id: checkActor uses: tspascoal/get-user-teams-membership@baf2e6adf4c3b897bd65a7e3184305c165aec872 with: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - username: ${{ github.actor }} + username: ${{ steps.getMergedPullRequest.outputs.author }} team: Expensify/expensify newContributorWelcomeMessage: From b36c2913e8cdea3f6acac42fc10f04e80abc946c Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 11 Mar 2022 20:33:17 +0000 Subject: [PATCH 2/5] Refactor the getMergedPullRequest step into a separate job --- .github/workflows/preDeploy.yml | 62 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 3120febcbfde..0d4e20adb1a6 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -44,11 +44,30 @@ jobs: GITHUB_TOKEN: ${{ github.token }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + # Get details about the merged pull request + getMergedPullRequest: + runs-on: ubuntu-latest + + outputs: + title: ${{ steps.getMergedPullRequest.outputs.title }} + body: ${{ steps.getMergedPullRequest.outputs.body }} + number: ${{ steps.getMergedPullRequest.outputs.number }} + labels: ${{ steps.getMergedPullRequest.outputs.labels }} + assignees: ${{ steps.getMergedPullRequest.outputs.assignees }} + + steps: + - name: Get merged pull request + id: getMergedPullRequest + # TODO: Point back action actions-ecosystem after https://github.com/actions-ecosystem/action-get-merged-pull-request/pull/223 is merged + uses: roryabraham/action-get-merged-pull-request@7a7a194f6ff8f3eef58c822083695a97314ebec1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + chooseDeployActions: runs-on: ubuntu-latest - needs: confirmPassingBuild + needs: [confirmPassingBuild, getMergedPullRequest] outputs: - mergedPullRequest: ${{ steps.getMergedPullRequest.outputs.number }} + mergedPullRequest: ${{ fromJSON(needs.getMergedPullRequest.outputs.number) }} isStagingDeployLocked: ${{ steps.isStagingDeployLocked.outputs.IS_LOCKED }} isAutomatedPullRequest: ${{ steps.isAutomatedPullRequest.outputs.IS_VERSION_BUMP_PR }} shouldCherryPick: ${{ steps.shouldCherryPick.outputs.SHOULD_CHERRY_PICK }} @@ -60,12 +79,6 @@ jobs: fetch-depth: 0 token: ${{ secrets.OS_BOTIFY_TOKEN }} - - name: Get merged pull request - id: getMergedPullRequest - uses: actions-ecosystem/action-get-merged-pull-request@59afe90821bb0b555082ce8ff1e36b03f91553d9 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Check if StagingDeployCash is locked id: isStagingDeployLocked uses: Expensify/App/.github/actions/isStagingDeployLocked@main @@ -78,7 +91,7 @@ jobs: - name: Check if merged pull request has `CP Staging` label id: shouldCherryPick - run: echo "::set-output name=SHOULD_CHERRY_PICK::${{ contains(steps.getMergedPullRequest.outputs.labels, 'CP Staging') }}" + run: echo "::set-output name=SHOULD_CHERRY_PICK::${{ contains(fromJSON(needs.getMergedPullRequest.outputs.labels), 'CP Staging') }}" skipDeploy: runs-on: ubuntu-latest @@ -211,29 +224,23 @@ jobs: # Check if actor is member of Expensify organization by looking for Expensify/expensify team isExpensifyEmployee: runs-on: ubuntu-latest + needs: getMergedPullRequest outputs: - IS_EXPENSIFY_EMPLOYEE: ${{ fromJSON(steps.checkActor.outputs.isTeamMember) }} + IS_EXPENSIFY_EMPLOYEE: ${{ steps.checkActor.outputs.isTeamMember }} steps: - - name: Get merged pull request - id: getMergedPullRequest - # TODO: Point back action actions-ecosystem after https://github.com/actions-ecosystem/action-get-merged-pull-request/pull/223 is merged - uses: roryabraham/action-get-merged-pull-request@7a7a194f6ff8f3eef58c822083695a97314ebec1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Check whether the actor is member of Expensify/expensify team id: checkActor uses: tspascoal/get-user-teams-membership@baf2e6adf4c3b897bd65a7e3184305c165aec872 with: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - username: ${{ steps.getMergedPullRequest.outputs.author }} + username: ${{ fromJSON(needs.getMergedPullRequest.outputs.author) }} team: Expensify/expensify newContributorWelcomeMessage: runs-on: ubuntu-latest - needs: isExpensifyEmployee + needs: [isExpensifyEmployee, getMergedPullRequest] if: ${{ github.actor != 'OSBotify' && !fromJSON(needs.isExpensifyEmployee.outputs.IS_EXPENSIFY_EMPLOYEE) }} steps: # Version: 2.3.4 @@ -241,26 +248,19 @@ jobs: with: token: ${{ secrets.OS_BOTIFY_TOKEN }} - - name: Get merged pull request - id: getMergedPullRequest - # TODO: Point back action actions-ecosystem after https://github.com/actions-ecosystem/action-get-merged-pull-request/pull/223 is merged - uses: roryabraham/action-get-merged-pull-request@7a7a194f6ff8f3eef58c822083695a97314ebec1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Get PR count for ${{ steps.getMergedPullRequest.outputs.author }} - run: echo "PR_COUNT=$(gh pr list --author ${{ steps.getMergedPullRequest.outputs.author }} --state any | grep -c '')" >> "$GITHUB_ENV" + - name: Get PR count for ${{ fromJSON(needs.getMergedPullRequest.outputs.author) }} + run: echo "PR_COUNT=$(gh pr list --author ${{ fromJSON(needs.getMergedPullRequest.outputs.author) }} --state any | grep -c '')" >> "$GITHUB_ENV" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Comment on ${{ steps.getMergedPullRequest.outputs.author }}\'s first pull request! + - name: Comment on ${{ fromJSON(needs.getMergedPullRequest.outputs.author) }}\'s first pull request! if: ${{ fromJSON(env.PR_COUNT) == 1 }} uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac with: github_token: ${{ secrets.OS_BOTIFY_TOKEN }} - number: ${{ steps.getMergedPullRequest.outputs.number }} + number: ${{ fromJSON(needs.getMergedPullRequest.outputs.number) }} body: | - @${{ steps.getMergedPullRequest.outputs.author }}, Great job getting your first Expensify/App pull request over the finish line! :tada: + @${{ fromJSON(needs.getMergedPullRequest.outputs.author) }}, Great job getting your first Expensify/App pull request over the finish line! :tada: I know there's a lot of information in our [contributing guidelines](https://github.com/Expensify/App/blob/main/CONTRIBUTING.md), so here are some points to take note of :memo:: From 67ebf6941867442bdbd245d2d972a586a36f33f6 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 11 Mar 2022 20:45:10 +0000 Subject: [PATCH 3/5] Include author input in getMergedPullRequest --- .github/workflows/preDeploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 0d4e20adb1a6..9d9646bce0f0 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -54,6 +54,7 @@ jobs: number: ${{ steps.getMergedPullRequest.outputs.number }} labels: ${{ steps.getMergedPullRequest.outputs.labels }} assignees: ${{ steps.getMergedPullRequest.outputs.assignees }} + author: ${{ steps.getMergedPullRequest.outputs.author }} steps: - name: Get merged pull request From 86ef8704ad2e8b789a9bb575d32d32521905e952 Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Tue, 15 Mar 2022 15:08:46 +0000 Subject: [PATCH 4/5] Update .github/workflows/preDeploy.yml Co-authored-by: Carlos Alvarez --- .github/workflows/preDeploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 9d9646bce0f0..6df4cda79a82 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -59,7 +59,6 @@ jobs: steps: - name: Get merged pull request id: getMergedPullRequest - # TODO: Point back action actions-ecosystem after https://github.com/actions-ecosystem/action-get-merged-pull-request/pull/223 is merged uses: roryabraham/action-get-merged-pull-request@7a7a194f6ff8f3eef58c822083695a97314ebec1 with: github_token: ${{ secrets.GITHUB_TOKEN }} From c8ac03283ffc49762f8e7acb619935de3bc99c23 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Wed, 16 Mar 2022 18:55:08 +0000 Subject: [PATCH 5/5] Make the other jobs in preDeploy dependent directly on getMergedPullRequest --- .github/workflows/preDeploy.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 871874dca00a..5f47b061813b 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -68,7 +68,6 @@ jobs: runs-on: ubuntu-latest needs: [confirmPassingBuild, getMergedPullRequest] outputs: - mergedPullRequest: ${{ fromJSON(needs.getMergedPullRequest.outputs.number) }} isStagingDeployLocked: ${{ steps.isStagingDeployLocked.outputs.IS_LOCKED }} isAutomatedPullRequest: ${{ steps.isAutomatedPullRequest.outputs.IS_VERSION_BUMP_PR }} shouldCherryPick: ${{ steps.shouldCherryPick.outputs.SHOULD_CHERRY_PICK }} @@ -96,7 +95,7 @@ jobs: skipDeploy: runs-on: ubuntu-latest - needs: chooseDeployActions + needs: [chooseDeployActions, getMergedPullRequest] if: ${{ fromJSON(needs.chooseDeployActions.outputs.isStagingDeployLocked) && !fromJSON(needs.chooseDeployActions.outputs.isAutomatedPullRequest) && !fromJSON(needs.chooseDeployActions.outputs.shouldCherryPick) }} steps: @@ -104,13 +103,13 @@ jobs: uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac with: github_token: ${{ secrets.OS_BOTIFY_TOKEN }} - number: ${{ needs.chooseDeployActions.outputs.mergedPullRequest }} + number: ${{ needs.getMergedPullRequest.outputs.number }} body: | :hand: This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. version: runs-on: ubuntu-latest - needs: chooseDeployActions + needs: [chooseDeployActions, getMergedPullRequest] if: ${{ fromJSON(needs.chooseDeployActions.outputs.shouldCherryPick) || (!fromJSON(needs.chooseDeployActions.outputs.isStagingDeployLocked) && !fromJSON(needs.chooseDeployActions.outputs.isAutomatedPullRequest)) }} steps: @@ -156,7 +155,7 @@ jobs: with: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} WORKFLOW: cherryPick.yml - INPUTS: '{ "PULL_REQUEST_NUMBER": "${{ needs.chooseDeployActions.outputs.mergedPullRequest }}", "NEW_VERSION": "${{ env.NEW_VERSION }}" }' + INPUTS: '{ "PULL_REQUEST_NUMBER": "${{ needs.getMergedPullRequest.outputs.number }}", "NEW_VERSION": "${{ env.NEW_VERSION }}" }' # Create a local git tag on staging so that GitUtils.getPullRequestsMergedBetween can use `git log` to generate a # list of pull requests that were merged between this version tag and another. @@ -177,7 +176,7 @@ jobs: - name: Comment in StagingDeployCash to alert Applause that a new pull request has been cherry-picked if: ${{ fromJSON(env.DO_CHERRY_PICK) }} run: | - PR_URL="https://github.com/Expensify/App/pull/${{ needs.chooseDeployActions.outputs.mergedPullRequest }}" + PR_URL="https://github.com/Expensify/App/pull/${{ needs.getMergedPullRequest.outputs.number }}" printf -v COMMENT ":clap: Heads up @Expensify/applauseleads :clap:\nA [new pull request](%s) has been :cherries: cherry-picked :cherries: to staging, and will be deployed to staging in version \`%s\` :rocket:" "$PR_URL" ${{ env.NEW_VERSION }} gh issue comment \ "$(gh issue list --label StagingDeployCash --json number --jq '.[0].number')" \