Skip to content

Commit

Permalink
Fix comment body
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfaraazkhan committed Feb 16, 2025
1 parent 9ef9334 commit 9658441
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/e2e-functional-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ jobs:
run:
shell: bash
outputs:
COMMENT_BODY: ${{ steps.analyze-flaky-tests.outputs.COMMENT_BODY }}
COMMENT_BODY_LINUX: ${{ steps.analyze-flaky-tests.outputs.COMMENT_BODY_LINUX }}
COMMENT_BODY_MACOS: ${{ steps.analyze-flaky-tests.outputs.COMMENT_BODY_MACOS }}
COMMENT_BODY_WINDOWS: ${{ steps.analyze-flaky-tests.outputs.COMMENT_BODY_WINDOWS }}

steps:
- name: e2e/set-required-variables
Expand Down Expand Up @@ -175,8 +177,12 @@ jobs:
script: |
process.chdir('./e2e');
const { analyzeFlakyTests } = require('./utils/analyze-flaky-test.js');
const { commentBody, newFailedTests } = analyzeFlakyTests();
core.setOutput('COMMENT_BODY', commentBody);
const { linuxResults, macosResults, windowsResults, newFailedTests } = analyzeFlakyTests();
core.setOutput('COMMENT_BODY_LINUX', linuxResults);
core.setOutput('COMMENT_BODY_MACOS', macosResults);
core.setOutput('COMMENT_BODY_WINDOWS', windowsResults);
if (newFailedTests.length > 0) {
core.setFailed('E2E tests failed.');
}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/e2e-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ jobs:
echo "### E2E Test Results"
echo
echo "#### Linux Results:"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY }}"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY_LINUX }}"
echo
echo "#### macOS Results:"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY }}"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY_MACOS }}"
echo
echo "#### Windows Results:"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY }}"
echo "${{ needs.e2e-tests.outputs.COMMENT_BODY_WINDOWS }}"
echo
echo "EOF"
} >> $GITHUB_ENV
Expand Down
87 changes: 39 additions & 48 deletions e2e/utils/analyze-flaky-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,57 @@ const {
} = require('./report');

function analyzeFlakyTests() {
const os = process.platform;
try {
// Import
const jsonReport = readJsonFromFile(path.join(MOCHAWESOME_REPORT_DIR, 'mochawesome.json'));

const {failedFullTitles} = generateShortSummary(jsonReport);

// Get the list of known flaky tests for the provided operating system
const knownFlakyTestsForOS = new Set(knownFlakyTests[os] || []);

// Filter out the known flaky tests from the failed test titles
const newFailedTests = failedFullTitles.filter((test) => !knownFlakyTestsForOS.has(test));

// Check if any known failed tests are fixed
const fixedTests = [...knownFlakyTestsForOS].filter((test) => !failedFullTitles.includes(test));
// Define platform mapping
const platforms = {
linux: 'linux',
macos: 'darwin',
windows: 'win32'

Check failure on line 22 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Missing trailing comma

Check failure on line 22 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Missing trailing comma

Check failure on line 22 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Missing trailing comma
};

const commentBody = generateCommentBodyFunctionalTest(newFailedTests, fixedTests);
let results = {

Check failure on line 25 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

'results' is never reassigned. Use 'const' instead

Check failure on line 25 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

'results' is never reassigned. Use 'const' instead

Check failure on line 25 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

'results' is never reassigned. Use 'const' instead
linux: "Linux Results:\n",

Check failure on line 26 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Strings must use singlequote

Check failure on line 26 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Strings must use singlequote

Check failure on line 26 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Strings must use singlequote
macos: "macOS Results:\n",

Check failure on line 27 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Strings must use singlequote

Check failure on line 27 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Strings must use singlequote

Check failure on line 27 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Strings must use singlequote
windows: "Windows Results:\n"

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Strings must use singlequote

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Missing trailing comma

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Strings must use singlequote

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Missing trailing comma

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Strings must use singlequote

Check failure on line 28 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Missing trailing comma
};

// Print on CI
console.log(commentBody);
let newFailedTests = [];

return {commentBody, newFailedTests};
} catch (error) {
console.error('Error analyzing failures:', error);
return {};
}
}
for (const [key, osName] of Object.entries(platforms)) {
const knownFlakyTestsForOS = new Set(knownFlakyTests[osName] || []);

function generateCommentBodyFunctionalTest(newFailedTests, fixedTests) {
const osName = process.env.RUNNER_OS;
const build = process.env.BUILD_TAG;
// Instead of filtering, assume all failed tests belong to all OSes
const failedTestsForOS = failedFullTitles;
const newFailures = failedTestsForOS.filter((test) => !knownFlakyTestsForOS.has(test));

let commentBody = `
## Test Summary for ${osName} on commit ${build}
`;
results[key] += failedTestsForOS.length
? failedTestsForOS.join('\n')

Check failure on line 41 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

'?' should be placed at the end of the line

Check failure on line 41 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

'?' should be placed at the end of the line

Check failure on line 41 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

'?' should be placed at the end of the line
: "All stable tests passed.";

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

':' should be placed at the end of the line

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Strings must use singlequote

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

':' should be placed at the end of the line

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Strings must use singlequote

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

':' should be placed at the end of the line

Check failure on line 42 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Strings must use singlequote

if (newFailedTests.length === 0 && fixedTests.length === 0) {
commentBody += `
All stable tests passed on ${osName}.
`;
return commentBody;
}
newFailedTests = [...newFailedTests, ...newFailures];

if (newFailedTests.length > 0) {
const newTestFailure = `New failed tests found on ${osName}:\n${newFailedTests.map((test) => `- ${test}`).join('\n')}`;
commentBody += `
${newTestFailure}
`;
}
console.log(`Analyzing ${key} tests...`);
console.log(`Results for ${key}:`, results[key]); // Debug log
}

if (fixedTests.length > 0) {
const fixedTestMessage = `The following known failed tests have been fixed on ${osName}:\n\t${fixedTests.map((test) => `- ${test}`).join('\n\t')}`;
commentBody += `
${fixedTestMessage}
`;
return {
COMMENT_BODY_LINUX: results.linux || "No results for Linux.",

Check failure on line 51 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Strings must use singlequote

Check failure on line 51 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-linux

Strings must use singlequote

Check failure on line 51 in e2e/utils/analyze-flaky-test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Strings must use singlequote
COMMENT_BODY_MACOS: results.macos || "No results for macOS.",
COMMENT_BODY_WINDOWS: results.windows || "No results for Windows.",
newFailedTests
};
} catch (error) {
console.error("Error analyzing flaky tests:", error);
return {
COMMENT_BODY_LINUX: "Error analyzing Linux tests.",
COMMENT_BODY_MACOS: "Error analyzing macOS tests.",
COMMENT_BODY_WINDOWS: "Error analyzing Windows tests.",
newFailedTests: []
};
}

return commentBody;
}

module.exports = {
analyzeFlakyTests,
};
module.exports = { analyzeFlakyTests };

0 comments on commit 9658441

Please sign in to comment.