Skip to content

Commit b4ad95d

Browse files
authored
Merge branch 'main' into add-discover-network-button
2 parents 2e83629 + 0f1fade commit b4ad95d

File tree

320 files changed

+10782
-2630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+10782
-2630
lines changed

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ version: 2.1
33
executors:
44
node-browsers-small:
55
docker:
6-
- image: cimg/node:22.13-browsers
6+
- image: cimg/node:22.14-browsers
77
resource_class: small
88
environment:
99
NODE_OPTIONS: --max_old_space_size=2048
1010
node-browsers-medium:
1111
docker:
12-
- image: cimg/node:22.13-browsers
12+
- image: cimg/node:22.14-browsers
1313
resource_class: medium
1414
environment:
1515
NODE_OPTIONS: --max_old_space_size=3072
@@ -21,7 +21,7 @@ executors:
2121
NODE_OPTIONS: --max_old_space_size=6144
2222
node-browsers-medium-plus:
2323
docker:
24-
- image: cimg/node:22.13-browsers
24+
- image: cimg/node:22.14-browsers
2525
resource_class: medium+
2626
environment:
2727
NODE_OPTIONS: --max_old_space_size=4096

.circleci/scripts/bundle-stats-commit.sh

+27-32
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,38 @@ git config --global user.email "[email protected]"
3838

3939
git config --global user.name "MetaMask Bot"
4040

41-
git clone [email protected]:MetaMask/extension_bundlesize_stats.git temp
42-
43-
{
44-
echo " '${CIRCLE_SHA1}': ";
45-
cat test-artifacts/chrome/bundle_size_stats.json;
46-
echo ", ";
47-
} >> temp/stats/bundle_size_data.temp.js
48-
49-
cp temp/stats/bundle_size_data.temp.js temp/stats/bundle_size_data.js
50-
51-
echo " }" >> temp/stats/bundle_size_data.js
52-
53-
if [ -f temp/stats/bundle_size_data.json ]; then
54-
# copy bundle_size_data.json in bundle_size_data.temp.json without last 2 lines
55-
head -$(($(wc -l < temp/stats/bundle_size_data.json) - 2)) temp/stats/bundle_size_data.json > bundle_size_stats.temp.json
56-
57-
{
58-
echo "},";
59-
echo "\"$CIRCLE_SHA1\":";
60-
cat test-artifacts/chrome/bundle_size_stats.json;
61-
echo "}";
62-
} >> bundle_size_stats.temp.json
63-
else
64-
{
65-
echo "{";
66-
echo "\"$CIRCLE_SHA1\":";
67-
cat test-artifacts/chrome/bundle_size_stats.json;
68-
echo "}";
69-
} > bundle_size_stats.temp.json
41+
git clone --depth=1 [email protected]:MetaMask/extension_bundlesize_stats.git temp
42+
43+
BUNDLE_SIZE_FILE="test-artifacts/chrome/bundle_size_stats.json"
44+
STATS_FILE="temp/stats/bundle_size_data.json"
45+
TEMP_FILE="temp/stats/bundle_size_data.temp.json"
46+
47+
# Ensure the JSON file exists
48+
if [[ ! -f "$STATS_FILE" ]]; then
49+
echo "{}" > "$STATS_FILE"
7050
fi
7151

72-
jq . bundle_size_stats.temp.json > temp/stats/bundle_size_data.json
73-
rm bundle_size_stats.temp.json
52+
# Validate JSON files before modification
53+
jq . "$STATS_FILE" > /dev/null || { echo "Error: Existing stats JSON is invalid"; exit 1; }
54+
jq . "$BUNDLE_SIZE_FILE" > /dev/null || { echo "Error: New bundle size JSON is invalid"; exit 1; }
55+
56+
# Check if the SHA already exists in the stats file
57+
if jq -e "has(\"$CIRCLE_SHA1\")" "$STATS_FILE" > /dev/null; then
58+
echo "SHA $CIRCLE_SHA1 already exists in stats file. No new commit needed."
59+
exit 0
60+
fi
61+
62+
# Append new bundle size data correctly using jq
63+
jq --arg sha "$CIRCLE_SHA1" --argjson data "$(cat "$BUNDLE_SIZE_FILE")" \
64+
'. + {($sha): $data}' "$STATS_FILE" > "$TEMP_FILE"
65+
66+
# Overwrite the original JSON file with the corrected version
67+
mv "$TEMP_FILE" "$STATS_FILE"
7468

7569
cd temp
7670

77-
git add .
71+
# Only add the JSON file
72+
git add stats/bundle_size_data.json
7873

7974
git commit --message "Adding bundle size at commit: ${CIRCLE_SHA1}"
8075

.github/CODEOWNERS

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ ui/components/ui/deprecated-networks @MetaMask/metamask-assets
137137
ui/components/ui/nft-collection-image @MetaMask/metamask-assets
138138

139139
# Extension Platform
140-
yarnrc.yml @MetaMask/extension-platform
140+
yarnrc.yml @MetaMask/extension-platform
141+
test/e2e/mock-e2e-allowlist.js @MetaMask/extension-platform

.github/scripts/git-diff-default-branch.ts

+30-85
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
import { exec as execCallback } from 'child_process';
21
import fs from 'fs';
32
import path from 'path';
4-
import { promisify } from 'util';
5-
import { context } from '@actions/github';
3+
import { context, getOctokit } from '@actions/github';
64
import * as core from '@actions/core';
75

8-
const exec = promisify(execCallback);
9-
106
// Get PR number from GitHub Actions environment variables
117
const PR_NUMBER = context.payload.pull_request?.number;
128

13-
const GITHUB_DEFAULT_BRANCH = 'main';
14-
const SOURCE_BRANCH = PR_NUMBER ? `refs/pull/${PR_NUMBER}/head` : '';
15-
169
const CHANGED_FILES_DIR = 'changed-files';
1710

11+
const octokit = getOctokit(process.env.GITHUB_TOKEN || '');
12+
1813
type PRInfo = {
1914
base: {
2015
ref: string;
@@ -35,86 +30,36 @@ async function getPrInfo(): Promise<PRInfo | null> {
3530

3631
const { owner, repo } = context.repo;
3732

38-
const response = await fetch(
39-
`https://api.github.com/repos/${owner}/${repo}/pulls/${PR_NUMBER}`,
40-
{
41-
headers: {
42-
Authorization: `token ${process.env.GITHUB_TOKEN}`,
43-
Accept: 'application/vnd.github.v3+json',
44-
},
45-
},
46-
);
47-
48-
return await response.json();
49-
}
50-
51-
/**
52-
* Fetches the git repository with a specified depth.
53-
*
54-
* @param depth - The depth to use for the fetch command.
55-
* @returns True if the fetch is successful, otherwise false.
56-
*/
57-
async function fetchWithDepth(depth: number): Promise<boolean> {
58-
try {
59-
await exec(`git fetch --depth ${depth} origin "${GITHUB_DEFAULT_BRANCH}"`);
60-
if (SOURCE_BRANCH) {
61-
await exec(
62-
`git fetch --depth ${depth} origin "${SOURCE_BRANCH}:${SOURCE_BRANCH}"`,
63-
);
64-
}
65-
return true;
66-
} catch (error) {
67-
core.warning(`Failed to fetch with depth ${depth}:`, error);
68-
return false;
69-
}
33+
return (
34+
await octokit.request(`GET /repos/${owner}/${repo}/pulls/${PR_NUMBER}`)
35+
).data;
7036
}
7137

7238
/**
73-
* Attempts to fetch the necessary commits until the merge base is found.
74-
* It tries different fetch depths and performs a full fetch if needed.
39+
* Get the list of files changed in the pull request using GraphQL
7540
*
76-
* @throws If an unexpected error occurs during the execution of git commands.
41+
* @returns List of files changed in the PR
7742
*/
78-
async function fetchUntilMergeBaseFound() {
79-
const depths = [1, 10, 100];
80-
for (const depth of depths) {
81-
core.info(`Attempting git diff with depth ${depth}...`);
82-
await fetchWithDepth(depth);
83-
84-
try {
85-
await exec(`git merge-base origin/${GITHUB_DEFAULT_BRANCH} HEAD`);
86-
return;
87-
} catch (error: unknown) {
88-
if (error instanceof Error && 'code' in error) {
89-
core.warning(
90-
`Error 'no merge base' encountered with depth ${depth}. Incrementing depth...`,
91-
);
92-
} else {
93-
throw error;
94-
}
95-
}
96-
}
97-
await exec(`git fetch --unshallow origin "${GITHUB_DEFAULT_BRANCH}"`);
98-
}
43+
async function getPrFilesChanged() {
44+
const { owner, repo } = context.repo;
9945

100-
/**
101-
* Performs a git diff command to get the list of files changed between the current branch and the origin.
102-
* It first ensures that the necessary commits are fetched until the merge base is found.
103-
*
104-
* @returns The output of the git diff command, listing the file paths with status (A, M, D).
105-
* @throws If unable to get the diff after fetching the merge base or if an unexpected error occurs.
106-
*/
107-
async function gitDiff(): Promise<string> {
108-
await fetchUntilMergeBaseFound();
109-
const { stdout: diffResult } = await exec(
110-
`git diff --name-status "origin/${GITHUB_DEFAULT_BRANCH}...${
111-
SOURCE_BRANCH || 'HEAD'
112-
}"`,
113-
);
114-
if (!diffResult) {
115-
throw new Error('Unable to get diff after full checkout.');
116-
}
117-
return diffResult;
46+
const response = await octokit.graphql({
47+
query: `
48+
{
49+
repository(owner: "${owner}", name: "${repo}") {
50+
pullRequest(number: ${PR_NUMBER}) {
51+
files(first: 100) {
52+
nodes {
53+
changeType
54+
path,
55+
}
56+
}
57+
}
58+
}
59+
}`,
60+
});
61+
62+
return response.repository.pullRequest.files.nodes;
11863
}
11964

12065
function writePrBodyAndInfoToFile(prInfo: PRInfo) {
@@ -153,12 +98,12 @@ async function storeGitDiffOutputAndPrBody() {
15398
// We perform git diff even if the PR base is not main or skip-e2e-quality-gate label is applied
15499
// because we rely on the git diff results for other jobs
155100
core.info('Attempting to get git diff...');
156-
const diffOutput = await gitDiff();
101+
const diffOutput = JSON.stringify(await getPrFilesChanged());
157102
core.info(diffOutput);
158103

159104
// Store the output of git diff
160-
const outputPath = path.resolve(CHANGED_FILES_DIR, 'changed-files.txt');
161-
fs.writeFileSync(outputPath, diffOutput.trim());
105+
const outputPath = path.resolve(CHANGED_FILES_DIR, 'changed-files.json');
106+
fs.writeFileSync(outputPath, diffOutput);
162107
core.info(`Git diff results saved to ${outputPath}`);
163108

164109
writePrBodyAndInfoToFile(prInfo);

0 commit comments

Comments
 (0)