Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { Octokit } from '@octokit/rest';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ export function partitionSummary(summary) {
export function allocateBucketSlots(topN, counts) {
const { broken = 0, flaky = 0, watch = 0, infra = 0 } = counts;

let maxBroken = Math.min(
const maxBroken = Math.min(
broken,
Math.max(Math.ceil(topN * 0.4), broken > 0 ? 2 : 0),
);
let maxFlaky = Math.min(
const maxFlaky = Math.min(
flaky,
Math.max(Math.ceil(topN * 0.25), flaky > 0 ? 2 : 0),
);
let maxInfra = Math.min(
const maxInfra = Math.min(
infra,
Math.max(Math.ceil(topN * 0.1), infra > 0 ? 1 : 0),
);
let maxWatch = Math.min(watch, topN - maxBroken - maxFlaky - maxInfra);
const maxWatch = Math.min(watch, topN - maxBroken - maxFlaky - maxInfra);

let remaining = topN - (maxBroken + maxFlaky + maxWatch + maxInfra);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,41 @@
* - Optional testDir prefix (e.g. accounts/foo.spec.ts → tests/smoke-appium/accounts/foo.spec.ts)
* - Idempotent when the path already starts with the prefix or `tests/`
*
* @param {string} filePath
* @param {{ prefix?: string }} [options]
* @returns {string}
* @param {string} filePath - The test file path to normalize.
* @param {{ prefix?: string }} [options] - The options, where `prefix` is the test directory prepended to relative paths.
* @returns {string} The normalized repo relative path.
*/
export function normalizeRepoFilePath(filePath, { prefix } = {}) {
if (!filePath) {
return filePath;
}

let normalized = String(filePath).replace(/\\/g, '/');
let normalized = String(filePath).replace(/\\/gu, '/');

const isAbsolute =
normalized.startsWith('/') || /^[A-Za-z]:\//.test(normalized);
normalized.startsWith('/') || /^[A-Za-z]:\//u.test(normalized);
if (isAbsolute) {
const testsMatch = normalized.match(/(?:^|\/)(tests\/.+)$/);
const testsMatch = normalized.match(/(?:^|\/)(tests\/.+)$/u);
if (testsMatch) {
normalized = testsMatch[1];
} else {
const runnerMatch = normalized.match(/\/work\/[^/]+\/[^/]+\/(.+)$/);
const runnerMatch = normalized.match(/\/work\/[^/]+\/[^/]+\/(.+)$/u);
if (runnerMatch) {
normalized = runnerMatch[1];
} else {
normalized = normalized.replace(/^\/+/, '').replace(/^[A-Za-z]:\//, '');
normalized = normalized
.replace(/^\/+/u, '')
.replace(/^[A-Za-z]:\//u, '');
}
}
}

normalized = normalized.replace(/^\/+/, '');
normalized = normalized.replace(/^\/+/u, '');

const cleanPrefix = prefix
?.trim()
.replace(/\\/g, '/')
.replace(/^\/+|\/+$/g, '');
.replace(/\\/gu, '/')
.replace(/^\/+|\/+$/gu, '');
if (cleanPrefix) {
const alreadyPrefixed =
normalized === cleanPrefix ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export function normalizeErrorForSlack(message, maxLength = 120) {
}

const withoutEmojiShortcodes = String(message).replace(
/:[a-z0-9_+\-]+:/gi,
/:[a-z0-9_+-]+:/giu,
' ',
);
const firstMeaningfulLine = withoutEmojiShortcodes
.split(/\r?\n/)
.split(/\r?\n/u)
.map((line) => line.trim())
.find(Boolean);
const normalized = (firstMeaningfulLine || withoutEmojiShortcodes)
.replace(/\s+/g, ' ')
.replace(/\s+/gu, ' ')
.trim();

if (!normalized) {
Expand Down
14 changes: 7 additions & 7 deletions .github/scripts/clean-release-changelog.mts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function splitReleaseSectionIntoChunks(
const entries: CategorizedEntry[] = [];
let category: string | undefined;
let currentEntry: string[] = [];
const endEntry = () => {
const endEntry = (): void => {
if (category && currentEntry.length > 0) {
entries.push({ category, text: currentEntry.join('\n').trimEnd() });
}
Expand All @@ -179,7 +179,7 @@ export function splitReleaseSectionIntoChunks(
let chunkEntries = new Map<string, string[]>();
let chunkEntryCount = 0;
let chunkPrNumbers: string[] = [];
const addChunk = () => {
const addChunk = (): void => {
if (chunkEntryCount === 0) {
return;
}
Expand Down Expand Up @@ -291,7 +291,7 @@ function getCategorizedBlocks(
const blocks = new Map<string, string[]>();
let category: string | undefined;
let categoryEntries: string[] = [];
const addCategory = () => {
const addCategory = (): void => {
if (!category) {
return;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ export function validateReplacement(
const categoryNames = new Set<string>();
let category: string | undefined;
let categoryEntryCount = 0;
const endCategory = () => {
const endCategory = (): void => {
if (category && categoryEntryCount === 0) {
throw new Error(`Category ${category} must not be empty`);
}
Expand Down Expand Up @@ -525,7 +525,7 @@ export async function requestGhApiWithRetry(
request: GhApiRequest = executeGhApi,
sleep?: (milliseconds: number) => Promise<void>,
): Promise<string> {
return await retry(async () => request(argumentsList), {
return await retry(async () => await request(argumentsList), {
delayMilliseconds: GH_API_RETRY_DELAY_MS,
maxAttempts: GH_API_MAX_ATTEMPTS,
onRetry: ({ attempt, delayMilliseconds }) => {
Expand Down Expand Up @@ -763,7 +763,7 @@ export async function requestCleanRoomRewrite({
],
};

return retry(
return await retry(
async () => {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs);
Expand Down Expand Up @@ -839,7 +839,7 @@ export async function requestValidatedRewrite(
prNumbers: readonly string[],
maxAttempts = MAX_VALIDATION_ATTEMPTS,
): Promise<string> {
return retry(
return await retry(
async () => {
const section = await requestCleanRoomRewrite(options);
try {
Expand Down
36 changes: 18 additions & 18 deletions .github/scripts/create-flaky-test-report.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node

// Based on the original script done by @itsyoboieltr on Extension repo

import { Octokit } from '@octokit/rest';
import { IncomingWebhook } from '@slack/webhook';
import unzipper from 'unzipper';

const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) throw new Error('Missing GITHUB_TOKEN env var');
if (!githubToken) {
throw new Error('Missing GITHUB_TOKEN env var');
}

const env = {
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
LOOKBACK_DAYS: parseInt(process.env.LOOKBACK_DAYS ?? '1'),
LOOKBACK_DAYS: parseInt(process.env.LOOKBACK_DAYS ?? '1', 10),
TEST_RESULTS_FILE_PATTERN:
process.env.TEST_RESULTS_FILE_PATTERN || 'test-runs',
OWNER: process.env.OWNER || 'MetaMask',
Expand Down Expand Up @@ -184,7 +184,7 @@ function extractRealFailures(testData) {
jobId: testSuite.job?.id,
runId: testSuite.job?.runId,
date: new Date(testSuite.date || Date.now()),
retryCount: retryCount,
retryCount,
type: 'real_failure',
});
}
Expand Down Expand Up @@ -237,7 +237,7 @@ function extractFlakyTests(testData) {
jobId: failureInfo.jobId,
runId: failureInfo.runId,
date: failureInfo.date,
retryCount: retryCount,
retryCount,
type: 'flaky',
});
}
Expand Down Expand Up @@ -450,7 +450,7 @@ function createSlackBlocks(
// Each failure
top10
.filter((test) => test.realFailures > 0)
.forEach((test, idx) => {
.forEach((test) => {
const globalIndex = top10.indexOf(test) + 1;
const failText = test.realFailures === 1 ? 'time' : 'times';
const retryText = test.totalRetries === 1 ? 'retry' : 'retries';
Expand Down Expand Up @@ -482,7 +482,7 @@ function createSlackBlocks(
elements: [
{
type: 'rich_text_section',
elements: elements,
elements,
},
],
});
Expand All @@ -491,7 +491,7 @@ function createSlackBlocks(
const error = test.lastRealFailureError;
if (error) {
const errorPreview =
error.length > 150 ? error.substring(0, 150) + '...' : error;
error.length > 150 ? `${error.substring(0, 150)}...` : error;
blocks.push({
type: 'rich_text',
elements: [
Expand All @@ -500,7 +500,7 @@ function createSlackBlocks(
elements: [
{
type: 'text',
text: ` ${errorPreview.replace(/\n/g, ' ')}`,
text: ` ${errorPreview.replace(/\n/gu, ' ')}`,
style: { italic: true },
},
],
Expand Down Expand Up @@ -577,7 +577,7 @@ function createSlackBlocks(
elements: [
{
type: 'rich_text_section',
elements: elements,
elements,
},
],
});
Expand All @@ -586,7 +586,7 @@ function createSlackBlocks(
const error = test.flakyFailureError;
if (error) {
const errorPreview =
error.length > 150 ? error.substring(0, 150) + '...' : error;
error.length > 150 ? `${error.substring(0, 150)}...` : error;
blocks.push({
type: 'rich_text',
elements: [
Expand All @@ -595,7 +595,7 @@ function createSlackBlocks(
elements: [
{
type: 'text',
text: ` ${errorPreview.replace(/\n/g, ' ')}`,
text: ` ${errorPreview.replace(/\n/gu, ' ')}`,
style: { italic: true },
},
],
Expand All @@ -610,7 +610,7 @@ function createSlackBlocks(
}

function displayResults(summary, dateDisplay) {
console.log('\n' + '='.repeat(80));
console.log(`\n${'='.repeat(80)}`);
console.log(`📊 REPORT - ${dateDisplay}`);
console.log('='.repeat(80));

Expand Down Expand Up @@ -662,9 +662,9 @@ function displayResults(summary, dateDisplay) {
if (test.lastRealFailureError) {
const errorPreview =
test.lastRealFailureError.length > 100
? test.lastRealFailureError.substring(0, 100) + '...'
? `${test.lastRealFailureError.substring(0, 100)}...`
: test.lastRealFailureError;
console.log(` 💥 Error: ${errorPreview.replace(/\n/g, ' ')}`);
console.log(` 💥 Error: ${errorPreview.replace(/\n/gu, ' ')}`);
}
} else {
// Flaky tests (failed initially but eventually passed)
Expand All @@ -684,10 +684,10 @@ function displayResults(summary, dateDisplay) {
if (test.flakyFailureError) {
const errorPreview =
test.flakyFailureError.length > 100
? test.flakyFailureError.substring(0, 100) + '...'
? `${test.flakyFailureError.substring(0, 100)}...`
: test.flakyFailureError;
console.log(
` 💥 Initial error: ${errorPreview.replace(/\n/g, ' ')}`,
` 💥 Initial error: ${errorPreview.replace(/\n/gu, ' ')}`,
);
}
}
Expand Down
Loading
Loading