From aa91089861d3c051af871f9f290fe15b605c13cd Mon Sep 17 00:00:00 2001 From: hhimanshu Date: Mon, 19 Apr 2021 10:21:33 -0700 Subject: [PATCH] ci: update status of staging tests using GitHub REST API --- .github/workflows/preview-ci.yml | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-ci.yml b/.github/workflows/preview-ci.yml index 6ed0b02..7ffb27f 100644 --- a/.github/workflows/preview-ci.yml +++ b/.github/workflows/preview-ci.yml @@ -20,4 +20,40 @@ jobs: - name: Test run: yarn test:integration --ci --coverage --maxWorkers=2 env: - STAGING_URL: ${{ github.event.deployment_status.target_url }} \ No newline at end of file + STAGING_URL: ${{ github.event.deployment_status.target_url }} + + # We must set the commit status manually + # Reference: https://github.com/bahmutov/eleventy-example/blob/main/.github/workflows/ci.yml#L27 + - name: Staging Tests ✅ + if: ${{ success() }} + # set the merge commit status check + # using GitHub REST API + # see https://docs.github.com/en/rest/reference/repos#create-a-commit-status + run: | + curl --request POST \ + --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "context": "Staging Tests", + "state": "success", + "description": "Staging tests passed", + "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + }' + + - name: Staging Tests 🚨 + if: ${{ failure() }} + # set the merge commit status check + # using GitHub REST API + # see https://docs.github.com/en/rest/reference/repos#create-a-commit-status + run: | + curl --request POST \ + --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "context": "Staging Tests", + "state": "failure", + "description": "Staging tests failed", + "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + }' \ No newline at end of file