Skip to content

Commit

Permalink
ARCH-2011 - Fix assertion for status check & add check cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danielle-casella-adams committed Feb 26, 2024
1 parent 9eede81 commit b4f08a5
Show file tree
Hide file tree
Showing 8 changed files with 597 additions and 65 deletions.
316 changes: 297 additions & 19 deletions .github/workflows/build-and-review-pr.yml

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions test/assert-status-check-exists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = async (github, core, statusCheckId) => {
core.info(`\nAsserting that status check '${statusCheckId} exists`);

if (!statusCheckId || statusCheckId.trim() === '') {
core.setFailed('The statusCheckId was not provided');
return;
}

let statusCheckToReturn;
await github.rest.checks
.get({
owner: 'im-open',
repo: 'process-jest-test-results',
check_run_id: statusCheckId.trim()
})
.then(checkResponse => {
core.info(`Status Check ${statusCheckId} exists.`);
const rawCheck = checkResponse.data;

statusCheckToReturn = {
id: rawCheck.id,
name: rawCheck.name,
status: rawCheck.status,
conclusion: rawCheck.conclusion,
startedAt: rawCheck.started_at,
completedAt: rawCheck.completed_at,
title: rawCheck.output.title,
summary: rawCheck.output.summary,
prNumber: rawCheck.pull_requests.length > 0 ? rawCheck.pull_requests[0].number : null,
text: rawCheck.output.text
};
core.startGroup(`Check ${statusCheckId} details:`);
console.log(statusCheckToReturn);
core.endGroup();
})
.catch(error => {
core.setFailed(`An error occurred retrieving status check ${statusCheckId}. Error: ${error.message}`);
});

return statusCheckToReturn;
};
5 changes: 1 addition & 4 deletions test/assert-status-check-matches-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ module.exports = async (core, statusCheck, expectedValues) => {
assertValuesMatch('Status', expectedValues['status'], statusCheck.status);
assertValuesMatch('Conclusion', expectedValues['conclusion'], statusCheck.conclusion);
assertValuesMatch('Title', expectedValues['title'], statusCheck.title);
assertValuesMatch('Text', expectedValues['text'], statusCheck.text);

// The summary should be something like: 'This test run completed at `Wed, 21 Feb 2024 20:21:48 GMT`'
// so just check that it contains the static portion.
assertValueContainsSubstring('Summary', statusCheck.summary, 'This test run completed at `');

// The text will be a just the markdown for a single trx file. Check that the expected text
// (which is the markdown for all trx files) contains the subset.
assertValueContainsSubstring('Text', expectedValues['text'], statusCheck.text);
}

validateProps();
Expand Down
42 changes: 0 additions & 42 deletions test/assert-status-checks-exist.js

This file was deleted.

79 changes: 79 additions & 0 deletions test/files/expected-check-results-allow-failures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Allow Failures Scenario

![Generic badge](https://img.shields.io/badge/1/6-FAILED-red.svg)
<details>
<summary>Duration: 3.904 seconds</summary>
<table>
<tr>
<th>Start:</th>
<td><code>2024-02-23 20:44:35.369 UTC</code></td>
</tr>
<tr>
<th>Finish:</th>
<td><code>2024-02-23 20:44:39.273 UTC</code></td>
</tr>
<tr>
<th>Duration:</th>
<td><code>3.904 seconds</code></td>
</tr>
</table>
</details>
<details>
<summary>Outcome: Failed | Total Tests: 6 | Passed: 5 | Failed: 1</summary>
<table>
<tr>
<th>Total Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Total Tests:</th>
<td>6</td>
</tr>
<tr>
<th>Failed Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Failed Tests:</th>
<td>1</td>
</tr>
<tr>
<th>Passed Test Suites:</th>
<td>0</td>
</tr>
<tr>
<th>Passed Tests:</th>
<td>5</td>
</tr>
</table>
</details>
<details>
<summary>:x: should be able to open the additional reasons drawer and select a reason</summary>
<table>
<tr>
<th>Title:</th>
<td><code>should be able to open the additional reasons drawer and select a reason</code></td>
</tr>
<tr>
<th>Status:</th>
<td><code>failed</code></td>
</tr>
<tr>
<th>Location:</th>
<td><code>null</code></td>
</tr>
<tr>
<th>Failure Messages:</th>
<td><pre>Error: expect(jest.fn()).toHaveBeenCalledTimes(expected)

Expected number of calls: 3
Received number of calls: 1
at toHaveBeenCalledTimes (C:\code\Selector.test.js:69:20)
at call (C:\code\Selector.test.js:2:1)
at Generator.tryCatch (C:\code\Selector.test.js:2:1)
at Generator._invoke [as next] (C:\code\Selector.test.js:2:1)
at asyncGeneratorStep (C:\code\Selector.test.js:2:1)
at asyncGeneratorStep (C:\code\Selector.test.js:2:1)</pre></td>
</tr>
</table>
</details>
79 changes: 79 additions & 0 deletions test/files/expected-check-results-ignore-failures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Ignore Failures Scenario

![Generic badge](https://img.shields.io/badge/1/6-FAILED-red.svg)
<details>
<summary>Duration: 3.904 seconds</summary>
<table>
<tr>
<th>Start:</th>
<td><code>2024-02-23 20:44:35.369 UTC</code></td>
</tr>
<tr>
<th>Finish:</th>
<td><code>2024-02-23 20:44:39.273 UTC</code></td>
</tr>
<tr>
<th>Duration:</th>
<td><code>3.904 seconds</code></td>
</tr>
</table>
</details>
<details>
<summary>Outcome: Failed | Total Tests: 6 | Passed: 5 | Failed: 1</summary>
<table>
<tr>
<th>Total Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Total Tests:</th>
<td>6</td>
</tr>
<tr>
<th>Failed Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Failed Tests:</th>
<td>1</td>
</tr>
<tr>
<th>Passed Test Suites:</th>
<td>0</td>
</tr>
<tr>
<th>Passed Tests:</th>
<td>5</td>
</tr>
</table>
</details>
<details>
<summary>:x: should be able to open the additional reasons drawer and select a reason</summary>
<table>
<tr>
<th>Title:</th>
<td><code>should be able to open the additional reasons drawer and select a reason</code></td>
</tr>
<tr>
<th>Status:</th>
<td><code>failed</code></td>
</tr>
<tr>
<th>Location:</th>
<td><code>null</code></td>
</tr>
<tr>
<th>Failure Messages:</th>
<td><pre>Error: expect(jest.fn()).toHaveBeenCalledTimes(expected)

Expected number of calls: 3
Received number of calls: 1
at toHaveBeenCalledTimes (C:\code\Selector.test.js:69:20)
at call (C:\code\Selector.test.js:2:1)
at Generator.tryCatch (C:\code\Selector.test.js:2:1)
at Generator._invoke [as next] (C:\code\Selector.test.js:2:1)
at asyncGeneratorStep (C:\code\Selector.test.js:2:1)
at asyncGeneratorStep (C:\code\Selector.test.js:2:1)</pre></td>
</tr>
</table>
</details>
49 changes: 49 additions & 0 deletions test/files/expected-check-results-no-failures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# No Failures Scenario

![Generic badge](https://img.shields.io/badge/6/6-PASSED-brightgreen.svg)
<details>
<summary>Duration: 5.688 seconds</summary>
<table>
<tr>
<th>Start:</th>
<td><code>2024-02-23 20:43:06.979 UTC</code></td>
</tr>
<tr>
<th>Finish:</th>
<td><code>2024-02-23 20:43:12.667 UTC</code></td>
</tr>
<tr>
<th>Duration:</th>
<td><code>5.688 seconds</code></td>
</tr>
</table>
</details>
<details>
<summary>Outcome: Passed | Total Tests: 6 | Passed: 6 | Failed: 0</summary>
<table>
<tr>
<th>Total Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Total Tests:</th>
<td>6</td>
</tr>
<tr>
<th>Failed Test Suites:</th>
<td>0</td>
</tr>
<tr>
<th>Failed Tests:</th>
<td>0</td>
</tr>
<tr>
<th>Passed Test Suites:</th>
<td>1</td>
</tr>
<tr>
<th>Passed Tests:</th>
<td>6</td>
</tr>
</table>
</details>
51 changes: 51 additions & 0 deletions test/update-failing-status-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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-jest-test-results',
check_run_id: statusCheckId
})
.then(response => {
core.info(`Status Check ${statusCheckId} exists.`);
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;
}

const updatedText = `> [!IMPORTANT]
> This status check was purposely created with a \`failure\` conclusion. We don't want this to prevent the PR from being merged though, so change the conclusion to \`neutral\` after the tests have run.
${actualCheck.output.text}`;
await github.rest.checks
.update({
owner: 'im-open',
repo: 'process-jest-test-results',
check_run_id: statusCheckId,
name: `${actualCheck.name} - UPDATED`,
conclusion: 'neutral',
output: {
title: `${actualCheck.output.title}`,
summary: `${actualCheck.output.summary}`,
text: updatedText
}
})
.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 b4f08a5

Please sign in to comment.