From 065aa0f9b6f9a12c67dd2c0cfe338a78575b244b Mon Sep 17 00:00:00 2001 From: tamaina Date: Thu, 9 Jun 2022 05:49:00 +0900 Subject: [PATCH] Display the deploy status on checks (#8803) * Display deploy status on check suite * Display deploy status on check suite * fix * fix --- .github/workflows/pr-preview-deploy.yml | 57 ++++++++++++++++++------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pr-preview-deploy.yml b/.github/workflows/pr-preview-deploy.yml index 1b399264d..fd43bce9e 100644 --- a/.github/workflows/pr-preview-deploy.yml +++ b/.github/workflows/pr-preview-deploy.yml @@ -1,5 +1,7 @@ # Run secret-dependent integration tests only after /deploy approval on: + pull_request: + types: [opened, reopened, synchronize] repository_dispatch: types: [deploy-command] @@ -14,6 +16,43 @@ jobs: github.event.client_payload.slash_command.sha != '' && contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha) steps: + - uses: actions/github-script@v5 + id: check-id + env: + number: ${{ github.event.client_payload.pull_request.number }} + job: ${{ github.job }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + result-encoding: string + script: | + const { data: pull } = await github.rest.pulls.get({ + ...context.repo, + pull_number: process.env.number + }); + const ref = pull.head.sha; + + const { data: checks } = await github.rest.checks.listForRef({ + ...context.repo, + ref + }); + + const check = checks.check_runs.filter(c => c.name === process.env.job); + + return check[0].id; + + - uses: actions/github-script@v5 + env: + check_id: ${{ steps.check-id.outputs.result }} + details_url: ${{ github.server_url }}/${{ github.repository }}/runs/${{ github.run_id }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + await github.rest.checks.update({ + ...context.repo, + check_run_id: process.env.check_id, + status: 'in_progress', + details_url: process.env.details_url + }); # Check out merge commit - name: Fork based /deploy checkout @@ -40,29 +79,15 @@ jobs: id: update-check-run if: ${{ always() }} env: - number: ${{ github.event.client_payload.pull_request.number }} - job: ${{ github.job }} # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run conclusion: ${{ job.status }} + check_id: ${{ steps.check-id.outputs.result }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const { data: pull } = await github.rest.pulls.get({ - ...context.repo, - pull_number: process.env.number - }); - const ref = pull.head.sha; - - const { data: checks } = await github.rest.checks.listForRef({ - ...context.repo, - ref - }); - - const check = checks.check_runs.filter(c => c.name === process.env.job); - const { data: result } = await github.rest.checks.update({ ...context.repo, - check_run_id: check[0].id, + check_run_id: process.env.check_id, status: 'completed', conclusion: process.env.conclusion });