From 561b482a36f7400b0b8c7cc0194518aa49a6c639 Mon Sep 17 00:00:00 2001 From: Stuart Leeks Date: Fri, 25 Feb 2022 15:12:52 +0000 Subject: [PATCH] Fix ordering. Update to use PR merge ref (#1383) --- .github/workflows/pr_comment_bot.yml | 72 +++++++++++++++------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/.github/workflows/pr_comment_bot.yml b/.github/workflows/pr_comment_bot.yml index 0a214d6604..63fc00b987 100644 --- a/.github/workflows/pr_comment_bot.yml +++ b/.github/workflows/pr_comment_bot.yml @@ -71,40 +71,10 @@ jobs: echo "Showing help on PR ${PR_NUMBER}" gh pr comment ${PR_NUMBER} --repo $REPO --body "Hello

You can use the following commands:
/test - run tests on a PR
/force-approve - force approval of the PR (i.e. skip the deployment checks)
/help - show this help" - # Check if the PR build/test needs to run - - name: Checkout - if: ${{ steps.check_command.outputs.result == 'run-tests' || steps.check_command.outputs.result == 'force-approve' }} - uses: actions/checkout@v2 - with: - repository: ${{ inputs.prRepo }} - ref: ${{ inputs.prRef }} - persist-credentials: false - - - uses: dorny/paths-filter@v2 - id: filter - if: ${{ steps.check_command.outputs.result == 'run-tests' }} - with: - filters: | - not-md: - # we need to check for changes in files other than *.md - - '**/!(*.md)' - - # If we don't run the actual deploy (below) we won't receive a check-run status, - # and will have to send it "manually" - - name: Bypass E2E check-runs status - if: ${{ (steps.check_command.outputs.result == 'run-tests' && steps.filter.outputs.not-md == 'false') || steps.check_command.outputs.result == 'force-approve' }} - uses: LouisBrunner/checks-action@v1.1.1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - # the name must be identical to the one received by the real job - name: "Deploy PR / Run E2E Tests (Smoke)" - status: "completed" - conclusion: "success" - # Get PR commit details for running tests - id: get_pr_details name: Get PR details - if: ${{ steps.check_command.outputs.result == 'run-tests' && steps.filter.outputs.not-md == 'true' }} + if: ${{ steps.check_command.outputs.result == 'run-tests' }} env: PR_NUMBER: ${{ github.event.issue.number }} REPO: ${{ github.event.repository.full_name }} @@ -120,10 +90,13 @@ jobs: echo "Getting PR ref..." ref=$(gh pr view $PR_NUMBER --repo $REPO --json commits | jq -r ".[] | last | .oid") echo -e "\tLatest commit ref: $ref" + # Get the prMergeCommit as this is what the pull_request trigger would build + prMergeRef=$(gh pr view $PR_NUMBER --repo $REPO --json potentialMergeCommit | jq -r .potentialMergeCommit.oid) + echo -e "\tprMergeRef: $prMergeRef" echo echo "Setting outputs" - echo "::set-output name=prRef::${ref}" + echo "::set-output name=prRef::${prMergeRef}" echo "::set-output name=prRepo::${pr_owner}/${pr_repo}" echo "Done" @@ -134,6 +107,39 @@ jobs: echo "using id of: ${REFID} for GitHub Ref: ${github_pr_ref}" echo "::set-output name=refid::${REFID}" + + # Check if the PR build/test needs to run + - name: Checkout + if: ${{ steps.check_command.outputs.result == 'run-tests' || steps.check_command.outputs.result == 'force-approve' }} + uses: actions/checkout@v2 + with: + # repository: ${{ steps.get_pr_details.outputs.prRepo }} + ref: ${{ steps.get_pr_details.outputs.prRef }} + persist-credentials: false + + - uses: dorny/paths-filter@v2 + id: filter + if: ${{ steps.check_command.outputs.result == 'run-tests' }} + with: + base: main + ref: ${{ steps.get_pr_details.outputs.prRef }} + filters: | + not-md: + # we need to check for changes in files other than *.md + - '**/!(*.md)' + + # If we don't run the actual deploy (below) we won't receive a check-run status, + # and will have to send it "manually" + - name: Bypass E2E check-runs status + if: ${{ (steps.check_command.outputs.result == 'run-tests' && steps.filter.outputs.not-md == 'false') || steps.check_command.outputs.result == 'force-approve' }} + uses: LouisBrunner/checks-action@v1.1.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + # the name must be identical to the one received by the real job + name: "Deploy PR / Run E2E Tests (Smoke)" + status: "completed" + conclusion: "success" + run_test: # Run the tests with the re-usable workflow needs: [pr_comment] @@ -142,7 +148,7 @@ jobs: uses: ./.github/workflows/deploy_tre_reusable.yml with: prRef: ${{ needs.pr_comment.outputs.prRef }} - prRepo: ${{ needs.pr_comment.outputs.prRepo }} + # prRepo: ${{ needs.pr_comment.outputs.prRepo }} ciGitRef: ${{ needs.pr_comment.outputs.ciGitRef }} secrets: AAD_TENANT_ID: ${{ secrets.AAD_TENANT_ID }}