Skip to content

Commit

Permalink
Merge pull request #28805 from MetaMask/Version-v12.9.0
Browse files Browse the repository at this point in the history
chore: Version v12.9.0
  • Loading branch information
danjm authored Dec 10, 2024
2 parents 884d810 + 8d86aea commit 26aae33
Show file tree
Hide file tree
Showing 736 changed files with 43,461 additions and 14,110 deletions.
41 changes: 35 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ version: 2.1
executors:
node-browsers-small:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: small
environment:
NODE_OPTIONS: --max_old_space_size=2048
node-browsers-medium:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: medium
environment:
NODE_OPTIONS: --max_old_space_size=3072
Expand All @@ -21,7 +21,7 @@ executors:
NODE_OPTIONS: --max_old_space_size=6144
node-browsers-medium-plus:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: medium+
environment:
NODE_OPTIONS: --max_old_space_size=4096
Expand Down Expand Up @@ -103,9 +103,11 @@ workflows:
test_and_release:
when:
not:
matches:
pattern: /^l10n_crowdin_action$/
value: << pipeline.git.branch >>
or:
- matches:
pattern: /^l10n_crowdin_action$/
value: << pipeline.git.branch >>
- equal: [rerun-from-failed, << pipeline.schedule.name >>]
jobs:
- create_release_pull_request:
<<: *rc_branch_only
Expand Down Expand Up @@ -176,6 +178,7 @@ workflows:
- prep-build-test-mmi:
requires:
- prep-deps
- check-mmi-trigger
- prep-build-test-mmi-playwright:
requires:
- prep-deps
Expand Down Expand Up @@ -356,6 +359,18 @@ workflows:
requires:
- prep-build-ts-migration-dashboard

rerun-from-failed:
when:
equal: [rerun-from-failed, << pipeline.schedule.name >>]
jobs:
- prep-deps
- rerun-workflows-from-failed:
filters:
branches:
only: develop
requires:
- prep-deps

locales_only:
when:
matches:
Expand Down Expand Up @@ -789,6 +804,7 @@ jobs:
- run: corepack enable
- attach_workspace:
at: .
- run: *check-mmi-trigger
- run:
name: Build extension for testing
command: yarn build:test:mmi
Expand Down Expand Up @@ -930,6 +946,17 @@ jobs:
paths:
- development/ts-migration-dashboard/build/final

rerun-workflows-from-failed:
executor: node-browsers-small
steps:
- run: *shallow-git-clone-and-enable-vnc
- run: sudo corepack enable
- attach_workspace:
at: .
- run:
name: Rerun workflows from failed
command: yarn ci-rerun-from-failed

test-yarn-dedupe:
executor: node-browsers-small
steps:
Expand Down Expand Up @@ -1172,6 +1199,7 @@ jobs:
- run: sudo corepack enable
- attach_workspace:
at: .
- run: *check-mmi-trigger
- run:
name: Move test build to dist
command: mv ./dist-test-mmi ./dist
Expand Down Expand Up @@ -1261,6 +1289,7 @@ jobs:
- run: sudo corepack enable
- attach_workspace:
at: .
- run: *check-mmi-trigger
- run:
name: Move test build to dist
command: mv ./dist-test-mmi ./dist
Expand Down
6 changes: 6 additions & 0 deletions .circleci/scripts/check_mmi_trigger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ if [ -z "$CIRCLE_PULL_REQUEST" ] || [ -z "$GITHUB_TOKEN" ]; then
exit 0
fi

if [[ $CIRCLE_BRANCH = 'develop' || $CIRCLE_BRANCH = 'master' || $CIRCLE_BRANCH =~ ^Version-v[0-9.]* ]]; then
echo "Long-running branch detected, running MMI tests."
echo "run_mmi_tests=true" > mmi_trigger.env
exit 0
fi

# Extract PR number from the pull request URL
PR_NUMBER=$(echo "$CIRCLE_PULL_REQUEST" | awk -F'/' '{print $NF}')

Expand Down
211 changes: 211 additions & 0 deletions .circleci/scripts/rerun-ci-workflow-from-failed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
const CIRCLE_TOKEN = process.env.API_V2_TOKEN;

interface Actor {
login: string;
avatar_url: string | null;
}

interface Trigger {
received_at: string;
type: string;
actor: Actor;
}

interface VCS {
origin_repository_url: string;
target_repository_url: string;
revision: string;
provider_name: string;
branch: string;
}

interface WorkflowItem {
id: string;
errors: string[];
project_slug: string;
updated_at: string;
number: number;
state: string;
created_at: string;
trigger: Trigger;
vcs: VCS;
}

interface CircleCIResponse {
next_page_token: string | null;
items: WorkflowItem[];
}

interface WorkflowStatusItem {
pipeline_id: string;
id: string;
name: string;
project_slug: string;
tag?: string;
status: string;
started_by: string;
pipeline_number: number;
created_at: string;
stopped_at: string;
}

interface WorkflowStatusResponse {
next_page_token: string | null;
items: WorkflowStatusItem[];
}

/**
* Fetches the last 20 CircleCI workflows for the given branch.
* Note: the API returns the first 20 workflows by default.
* If we wanted to get older workflows, we would need to use the 'page-token' we would get in the first response
* and perform a subsequent request with the 'page-token' parameter.
* This seems unnecessary as of today, as the amount of daily PRs merged to develop is not that high.
*
* @returns {Promise<WorkflowItem[]>} A promise that resolves to an array of workflow items.
* @throws Will throw an error if the CircleCI token is not defined or if the HTTP request fails.
*/
async function getCircleCiWorkflowsByBranch(branch: string): Promise<WorkflowItem[]> {
if (!CIRCLE_TOKEN) {
throw new Error('CircleCI token is not defined');
}

const url = `https://circleci.com/api/v2/project/github/${process.env.CIRCLE_PROJECT_USERNAME}/${process.env.CIRCLE_PROJECT_REPONAME}/pipeline?branch=${branch}`;
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
};

try {
const response = await fetch(url, options);
if (!response.ok) {
const errorBody = await response.text();
console.error('HTTP error response:', errorBody);
throw new Error(`HTTP error! status: ${response.status}`);
}
const body = await response.json();
console.log('Circle Ci workflows fetched successfully!');
return body.items;
} catch (error) {
console.error('Error:', error);
throw error;
}
}

/**
* Fetches the status of a specific CircleCI workflow.
*
* @param {string} workflowId - The ID of the workflow to fetch the status for.
* @returns {Promise<WorkflowStatusResponse>} A promise that resolves to the workflow status response.
* @throws Will throw an error if the CircleCI token is not defined or if the HTTP request fails.
*/
async function getWorkflowStatusById(workflowId: string): Promise<WorkflowStatusResponse> {
if (!CIRCLE_TOKEN) {
throw new Error('CircleCI token is not defined');
}

const url = `https://circleci.com/api/v2/pipeline/${workflowId}/workflow`;
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
};

try {
console.log(`Fetching workflow ${workflowId}...`);

const response = await fetch(url, options);
if (!response.ok) {
const errorBody = await response.text();
console.error('HTTP error response:', errorBody);
throw new Error(`HTTP error! status: ${response.status}`);
}
const workflowStatus = await response.json();

console.log(`Number of runs: ${workflowStatus.items.length}`);
console.log(`Workflow status from last run: ${workflowStatus.items[0].status}`);

return workflowStatus;

} catch (error) {
console.error('Error:', error);
throw error;
}
}

/**
* Reruns a CircleCI workflow by its ID.
*
* @param {string} workflowId - The ID of the workflow to rerun.
* @throws Will throw an error if the CircleCI token is not defined or if the HTTP request fails.
*/
async function rerunWorkflowById(workflowId: string) {
if (!CIRCLE_TOKEN) {
throw new Error('CircleCI token is not defined');
}

const url = `https://circleci.com/api/v2/workflow/${workflowId}/rerun`;
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Circle-Token': CIRCLE_TOKEN,
},
body: JSON.stringify({
enable_ssh: false,
from_failed: true,
sparse_tree: false, // mutually exclusive with the from_failed parameter
})
};

try {
console.log(`Rerunning workflow ${workflowId}...`);
const response = await fetch(url, options);
if (!response.ok) {
const errorBody = await response.text();
console.error('HTTP error response:', errorBody);
throw new Error(`HTTP error! status: ${response.status}`);
}
const body = await response.json();
console.log('Workflow rerun successfully!');
console.log(body);
} catch (error) {
console.error('Error:', error);
}
}

/**
* Re-runs failed CircleCI workflows from develop branch.
* The workflow will only be re-runed if:
* 1. It has the status of 'failed'
* 2. It has only been run once
* 3. It is among the most recent 20 workflows
* 4. It was triggered by the 'github-merge-queue[bot]' user
*
* @throws Will throw an error if fetching the workflows or re-running a workflow fails.
*/
async function rerunFailedWorkflowsFromDevelop() {
console.log('Getting Circle Ci workflows from develop branch...');
const workflows = await getCircleCiWorkflowsByBranch('develop');

console.log('Assessing if any of the workflows needs to be rerun...');
for (const item of workflows) {
if (item.trigger.actor.login === 'github-merge-queue[bot]') {
const workflowStatus = await getWorkflowStatusById(item.id);

if (workflowStatus.items.length === 1 && workflowStatus.items[0].status === 'failed') {
await rerunWorkflowById(workflowStatus.items[0].id);
console.log(`Rerun workflow with ID: ${workflowStatus.items[0].id}`);
}
}
}
console.log('Task completed successfully!');
}

rerunFailedWorkflowsFromDevelop()
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: SonarCloud
on:
workflow_run:
workflows:
- Run tests
- Main
types:
- completed

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.17
v20.18
Loading

0 comments on commit 26aae33

Please sign in to comment.