From 6b2e997d823a5ffbc744423591f7ade1e376691f Mon Sep 17 00:00:00 2001 From: Ming Yu Wang <90855268+mwangggg@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:39:47 -0500 Subject: [PATCH] ci(gh): add comment when /build_test is finished (#745) --- .github/workflows/test-ci-command.yml | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/test-ci-command.yml b/.github/workflows/test-ci-command.yml index d8e45a85..2e1ffce2 100644 --- a/.github/workflows/test-ci-command.yml +++ b/.github/workflows/test-ci-command.yml @@ -95,3 +95,40 @@ jobs: ref: ${{ needs.checkout-branch.outputs.PR_head_ref }} tag: ${{ needs.get-test-image-tag.outputs.tag }} sha: ${{ needs.checkout-branch.outputs.PR_head_sha }} + + successful-test: + runs-on: ubuntu-latest + needs: [run-test-jobs] + permissions: + pull-requests: write + steps: + - name: Leave Actions Run Comment + uses: actions/github-script@v6 + with: + script: | + const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`; + const commentBody = `\`/build_test\` completed successfully ✅. \n[View Actions Run](${runURL}).`; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + + cancelled-test: + if: (always() && contains(needs.*.result, 'failure')) + runs-on: ubuntu-latest + needs: [run-test-jobs] + steps: + - name: Leave Actions Run Comment + uses: actions/github-script@v6 + with: + script: | + const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`; + const commentBody = `\`/build_test\` : At least one test failed ❌. \n[View Actions Run](${runURL}).`; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + });