mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
91829bef5a
Summary: As part of the work to integrate libraries with our nightlies, we want to receive a message when the libraries are failing to build on discord. This will help us catch breaking changes early on and onboarding library maintainer as soon as possible. ## Changelog: [Internal] - Integrate with Discord when nightly fails Pull Request resolved: https://github.com/facebook/react-native/pull/50979 Test Plan: GHA Reviewed By: cortinico Differential Revision: D73845810 Pulled By: cipolleschi fbshipit-source-id: c6cfdf16b29642b1c3ad3872096c0e815fa88a0a
122 lines
3.3 KiB
JavaScript
122 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const {
|
|
prepareFailurePayload,
|
|
sendMessageToDiscord,
|
|
} = require('./notifyDiscord');
|
|
|
|
function readOutcomes() {
|
|
const baseDir = '/tmp';
|
|
let outcomes = [];
|
|
fs.readdirSync(baseDir).forEach(file => {
|
|
const fullPath = path.join(baseDir, file);
|
|
if (fullPath.endsWith('outcome') && fs.statSync(fullPath).isDirectory) {
|
|
fs.readdirSync(fullPath).forEach(subFile => {
|
|
const subFullPath = path.join(fullPath, subFile);
|
|
if (subFullPath.endsWith('outcome')) {
|
|
const [library, status] = String(fs.readFileSync(subFullPath, 'utf8'))
|
|
.trim()
|
|
.split(':');
|
|
const platform = subFile.includes('android') ? 'Android' : 'iOS';
|
|
console.log(
|
|
`[${platform}] ${library} completed with status ${status}`,
|
|
);
|
|
outcomes.push({
|
|
library: library.trim(),
|
|
platform,
|
|
status: status.trim(),
|
|
});
|
|
}
|
|
});
|
|
} else if (fullPath.endsWith('outcome')) {
|
|
const [library, status] = String(fs.readFileSync(fullPath, 'utf8'))
|
|
.trim()
|
|
.split(':');
|
|
const platform = file.includes('android') ? 'Android' : 'iOS';
|
|
console.log(`[${platform}] ${library} completed with status ${status}`);
|
|
outcomes.push({
|
|
library: library.trim(),
|
|
platform,
|
|
status: status.trim(),
|
|
});
|
|
}
|
|
});
|
|
return outcomes;
|
|
}
|
|
|
|
function printFailures(outcomes) {
|
|
console.log('Printing failures...');
|
|
let failedLibraries = [];
|
|
outcomes.forEach(entry => {
|
|
if (entry.status !== 'success') {
|
|
console.log(
|
|
`❌ [${entry.platform}] ${entry.library} failed with status ${entry.status}`,
|
|
);
|
|
failedLibraries.push({
|
|
library: entry.library,
|
|
platform: entry.platform,
|
|
});
|
|
}
|
|
});
|
|
return failedLibraries;
|
|
}
|
|
|
|
/**
|
|
* Sends a message to Discord with the list of failures.
|
|
* @param {string} webHook - The Discord webhook URL
|
|
* @param {Array<Object>} failures - List of failures to report
|
|
* @returns {Promise<void>} - A promise that resolves when the message is sent
|
|
*/
|
|
async function notifyDiscord(webHook, failures) {
|
|
if (!webHook) {
|
|
console.error('Discord webhook URL is missing');
|
|
return;
|
|
}
|
|
|
|
if (!failures || failures.length === 0) {
|
|
console.log('No failures to report to Discord');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Use the prepareFailurePayload function to format the message
|
|
const message = prepareFailurePayload(failures);
|
|
|
|
// Use the sendMessageToDiscord function to send the message
|
|
await sendMessageToDiscord(webHook, message);
|
|
} catch (error) {
|
|
console.error('Error in notifyDiscord function:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async function collectResults(discordWebHook) {
|
|
const outcomes = readOutcomes();
|
|
const failures = printFailures(outcomes);
|
|
|
|
if (failures.length > 0) {
|
|
if (discordWebHook) {
|
|
console.log('Sending to discord');
|
|
await notifyDiscord(discordWebHook, failures);
|
|
} else {
|
|
console.log('Web hook not set');
|
|
}
|
|
process.exit(1);
|
|
}
|
|
console.log('✅ All tests passed!');
|
|
}
|
|
|
|
module.exports = {
|
|
collectResults,
|
|
notifyDiscord,
|
|
};
|