mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
cd71c9620c
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53132 This will prevent the Firebase script from running at all. I'm removing it. Changelog: [Internal] [Changed] - Reviewed By: cipolleschi Differential Revision: D79801691 fbshipit-source-id: 2705dff93fc9dbbcfaf97a1ba29b69d4d0a8143c
175 lines
5.3 KiB
JavaScript
175 lines
5.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,
|
|
prepareComparisonPayload,
|
|
sendMessageToDiscord,
|
|
} = require('./notifyDiscord');
|
|
const {
|
|
FirebaseClient,
|
|
compareResults,
|
|
getYesterdayDate,
|
|
getTodayDate,
|
|
} = require('./firebaseUtils');
|
|
|
|
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);
|
|
|
|
// Send failure notification if there are current failures
|
|
if (failures.length > 0) {
|
|
if (discordWebHook) {
|
|
console.log('Sending current failures to Discord...');
|
|
await notifyDiscord(discordWebHook, failures);
|
|
} else {
|
|
console.log('Discord webhook not set');
|
|
}
|
|
}
|
|
|
|
// Initialize Firebase client
|
|
const firebaseClient = new FirebaseClient();
|
|
const today = getTodayDate();
|
|
|
|
try {
|
|
// Store today's results in Firebase
|
|
console.log(`Storing results for ${today} in Firebase...`);
|
|
await firebaseClient.storeResults(today, outcomes);
|
|
|
|
// Get the most recent previous results for comparison
|
|
console.log(`Looking for most recent previous results before ${today}...`);
|
|
const {results: previousResults, date: previousDate} =
|
|
await firebaseClient.getLatestResults(today);
|
|
|
|
let broken = [];
|
|
let recovered = [];
|
|
|
|
if (previousResults) {
|
|
console.log(`Comparing with results from ${previousDate}`);
|
|
// Compare results and identify broken/recovered jobs
|
|
const comparison = compareResults(outcomes, previousResults);
|
|
broken = comparison.broken;
|
|
recovered = comparison.recovered;
|
|
|
|
console.log(
|
|
`Found ${broken.length} newly broken jobs and ${recovered.length} recovered jobs compared to ${previousDate}`,
|
|
);
|
|
} else {
|
|
console.log(
|
|
'No previous results found for comparison - this might be the first run or no recent data available',
|
|
);
|
|
}
|
|
|
|
// Send comparison message to Discord if there are changes
|
|
if (discordWebHook && (broken.length > 0 || recovered.length > 0)) {
|
|
console.log('Sending comparison results to Discord...');
|
|
const comparisonMessage = prepareComparisonPayload(broken, recovered);
|
|
await sendMessageToDiscord(discordWebHook, comparisonMessage);
|
|
}
|
|
|
|
console.log('✅ All tests passed!');
|
|
} catch (error) {
|
|
console.error('Error in collectResults:', error);
|
|
// If Firebase fails but there are no test failures, don't fail the workflow
|
|
console.log('⚠️ Firebase operations failed, but all tests passed');
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
collectResults,
|
|
notifyDiscord,
|
|
};
|