From 85b0a7d1a4da5524e84c276a82885be47766874d Mon Sep 17 00:00:00 2001 From: Danielle Adams Date: Mon, 26 Feb 2024 10:53:58 -0700 Subject: [PATCH] ARCH-2011 - Add teardown step to neutralize the failing status check --- .github/workflows/build-and-review-pr.yml | 27 +++++++++--- test/update-failing-status-check.js | 50 +++++++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 test/update-failing-status-check.js diff --git a/.github/workflows/build-and-review-pr.yml b/.github/workflows/build-and-review-pr.yml index 75059fa..50de5c7 100644 --- a/.github/workflows/build-and-review-pr.yml +++ b/.github/workflows/build-and-review-pr.yml @@ -775,12 +775,12 @@ jobs: - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - - name: ' TEST 17 - STATUS CHECK - ACK FAILURES ' + - name: ' TEST 17 - STATUS CHECK - ALLOW FAILURES ' run: echo "" - name: 17 - When process-dotnet-test-results is called with test failures & ignore-test-failures=false if: always() - id: ack-failures + id: allow-failures uses: ./ with: github-token: '${{ secrets.GITHUB_TOKEN }}' @@ -792,15 +792,15 @@ jobs: - name: 17 - Then the action outcome should be success if: always() - run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.ack-failures.outcome }}" + run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.allow-failures.outcome }}" - name: 17 - And the status-check-ids output should be populated if: always() - run: ./test/assert-value-is-not-empty.sh --name "status-check-ids output" --value "${{ steps.ack-failures.outputs.status-check-ids }}" + run: ./test/assert-value-is-not-empty.sh --name "status-check-ids output" --value "${{ steps.allow-failures.outputs.status-check-ids }}" - name: 17 - And the test-outcome output should be Failed if: always() - run: ./test/assert-values-match.sh --name "test-outcome output" --expected "Failed" --actual "${{ steps.ack-failures.outputs.test-outcome }}" + run: ./test/assert-values-match.sh --name "test-outcome output" --expected "Failed" --actual "${{ steps.allow-failures.outputs.test-outcome }}" - name: 17 - And the status check should match the inputs if: always() @@ -811,7 +811,7 @@ jobs: const assertStatusCheckExists = require('./test/assert-status-checks-exist.js'); const assertStatusCheckMatchesExpectations = require('./test/assert-status-check-matches-expectations.js'); - const checkIds = '${{ steps.ack-failures.outputs.status-check-ids }}'; + const checkIds = '${{ steps.allow-failures.outputs.status-check-ids }}'; const actualStatusChecks = await assertStatusCheckExists(github, core, checkIds); const expectedBody = fs.readFileSync('./test-results.md', 'utf8'); @@ -827,6 +827,21 @@ jobs: - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" + - name: ' TEARDOWN ' + run: echo "" + + - name: Teardown - Modify failing Status Check conclusion + if: always() + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const updateFailingStatusCheck = require('./test/update-failing-status-check.js'); + + await updateFailingStatusCheck(github, core, '${{ steps.allow-failures.outputs.status-check-ids }}'); + + - name: '-------------------------------------------------------------------------------------------------------------' + run: echo "" test-pr-comments: runs-on: ubuntu-latest diff --git a/test/update-failing-status-check.js b/test/update-failing-status-check.js new file mode 100644 index 0000000..159e231 --- /dev/null +++ b/test/update-failing-status-check.js @@ -0,0 +1,50 @@ +module.exports = async (github, core, statusCheckId) => { + core.info(`\nUpdate purposely failing status checks: '${statusCheckId}'`); + + if (!statusCheckId || statusCheckId.trim() === '') { + return; + } + + let actualCheck; + await github.rest.checks + .get({ + owner: 'im-open', + repo: 'process-dotnet-test-results', + check_run_id: statusCheckId + }) + .then(response => { + core.info(`Status Check ${statusCheckId} exists.`); + console.log('respose:'); + console.log(response.data); + actualCheck = response.data; + }) + .catch(error => { + core.setFailed(`An error occurred retrieving status check ${statusCheckId}. Error: ${error.message}`); + }); + + if (!actualCheck) { + core.info('Returning since status check was not found.'); + return; + } + + await github.rest.checks + .update({ + owner: 'im-open', + repo: 'process-dotnet-test-results', + check_run_id: statusCheckId, + name: `${actualCheck.name} - UPDATED1`, + conclusion: 'neutral', + output: { + title: `${actualCheck.output.title} - Updated2`, + summary: `${actualCheck.output.summary} - Updated3`, + text: `# Test Update\nThis status check has been modified with a neutral status. It was purposely created with a 'failure' conclusion but we don't want this to prevent the PR from being merged, so it is being changed to neutral.\n${actualCheck.output.text}` + } + }) + .then(() => { + core.info(`The status check '${statusCheckId}' was updated successfully.`); + }) + .catch(error => { + core.info(`An error occurred updating status check '${statusCheckId}'. Error: ${error.message}`); + core.info(`This status check can be ignored when determining whether the PR is ready to merge.`); + }); +};