Skip to content

Commit

Permalink
ARCH-2011 - Add teardown step to neutralize the failing status check
Browse files Browse the repository at this point in the history
  • Loading branch information
danielle-casella-adams committed Feb 26, 2024
1 parent a7d1946 commit 85b0a7d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Expand All @@ -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()
Expand All @@ -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');
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions test/update-failing-status-check.js
Original file line number Diff line number Diff line change
@@ -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.`);
});
};

0 comments on commit 85b0a7d

Please sign in to comment.