From 0a65a0b8e8f190d7d715d50548b7493b1a2a78bb Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 24 May 2023 14:43:36 -0700 Subject: [PATCH] devops: post merged report URL to the PR (#23266) Posting a comment to the PR using GITHUB_TOKEN requires elevated permissions, see https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs --- .github/workflows/tests_primary.yml | 46 +++++++++++++++++++++++++++ .github/workflows/tests_secondary.yml | 23 ++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/.github/workflows/tests_primary.yml b/.github/workflows/tests_primary.yml index e3f3655ae3..452293987a 100644 --- a/.github/workflows/tests_primary.yml +++ b/.github/workflows/tests_primary.yml @@ -64,6 +64,8 @@ jobs: merge_test_linux: if: ${{ always() && github.event_name != 'pull_request' }} + permissions: + pull-requests: write needs: [test_linux] timeout-minutes: 10 runs-on: ubuntu-latest @@ -87,6 +89,27 @@ jobs: run: | az storage blob upload-batch -s playwright-report -d '$web/run-${{ github.run_id }}-${{ github.sha }}-test_linux' --connection-string "${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}" echo "Report url: https://mspwblobreport.z1.web.core.windows.net/run-${{ github.run_id }}-${{ github.sha }}-test_linux/index.html" + - name: Comment on PR + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + ...context.repo, + commit_sha: context.sha, + }); + if (prs.length === 0) { + core.error('No pull request found for commit ' + context.sha); + return; + } + const reportUrl = `https://mspwblobreport.z1.web.core.windows.net/run-${context.runId}-${context.sha}-test_linux/index.html`; + core.notice('Report url: ' + reportUrl); + const { data: response } = await github.rest.issues.createComment({ + ...context.repo, + issue_number: prs[0].number, + body: 'Primary test results: ' + reportUrl, + }); + core.info('Posted comment: ' + response.html_url); test_linux_chromium_tot: name: ${{ matrix.os }} (chromium tip-of-tree) @@ -158,6 +181,8 @@ jobs: merge_test_test_runner: if: ${{ always() && github.event_name != 'pull_request' }} + permissions: + pull-requests: write needs: [test_test_runner] timeout-minutes: 10 runs-on: ubuntu-latest @@ -181,6 +206,27 @@ jobs: run: | az storage blob upload-batch -s playwright-report -d '$web/run-${{ github.run_id }}-${{ github.sha }}-test_test_runner' --connection-string "${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}" echo "Report url: https://mspwblobreport.z1.web.core.windows.net/run-${{ github.run_id }}-${{ github.sha }}-test_test_runner/index.html" + - name: Comment on PR + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + ...context.repo, + commit_sha: context.sha, + }); + if (prs.length === 0) { + core.error('No pull request found for commit ' + context.sha); + return; + } + const reportUrl = `https://mspwblobreport.z1.web.core.windows.net/run-${context.runId}-${context.sha}-test_test_runner/index.html`; + core.notice('Report url: ' + reportUrl); + const { data: response } = await github.rest.issues.createComment({ + ...context.repo, + issue_number: prs[0].number, + body: 'Test Runner test results: ' + reportUrl, + }); + core.info('Posted comment: ' + response.html_url); test_web_components: name: Web Components diff --git a/.github/workflows/tests_secondary.yml b/.github/workflows/tests_secondary.yml index 286e96196e..75d4d0ebca 100644 --- a/.github/workflows/tests_secondary.yml +++ b/.github/workflows/tests_secondary.yml @@ -214,6 +214,8 @@ jobs: merge_tracing_linux: if: ${{ always() && github.event_name != 'pull_request' }} + permissions: + pull-requests: write needs: [tracing_linux] timeout-minutes: 10 runs-on: ubuntu-latest @@ -237,6 +239,27 @@ jobs: run: | az storage blob upload-batch -s playwright-report -d '$web/run-${{ github.run_id }}-${{ github.sha }}-tracing_linux' --connection-string "${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}" echo "Report url: https://mspwblobreport.z1.web.core.windows.net/run-${{ github.run_id }}-${{ github.sha }}-tracing_linux/index.html" + - name: Comment on PR + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + ...context.repo, + commit_sha: context.sha, + }); + if (prs.length === 0) { + core.error('No pull request found for commit ' + context.sha); + return; + } + const reportUrl = `https://mspwblobreport.z1.web.core.windows.net/run-${context.runId}-${context.sha}-tracing_linux/index.html`; + core.notice('Report url: ' + reportUrl); + const { data: response } = await github.rest.issues.createComment({ + ...context.repo, + issue_number: prs[0].number, + body: 'Tracing test results: ' + reportUrl, + }); + core.info('Posted comment: ' + response.html_url); chrome_stable_linux: name: "Chrome Stable (Linux)"