Skip to content

Commit

Permalink
Merge branch 'develop' into devin/mixin-565343
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall authored Jul 31, 2024
2 parents c103007 + e00863e commit 741695c
Show file tree
Hide file tree
Showing 1,136 changed files with 64,896 additions and 17,734 deletions.
300 changes: 101 additions & 199 deletions .circleci/config.yml

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions .circleci/scripts/git-diff-develop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { hasProperty } from '@metamask/utils';
import { exec as execCallback } from 'child_process';
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';

const exec = promisify(execCallback);

/**
* Fetches the git repository with a specified depth.
*
* @param depth - The depth to use for the fetch command.
* @returns True if the fetch is successful, otherwise false.
*/
async function fetchWithDepth(depth: number): Promise<boolean> {
try {
await exec(`git fetch --depth ${depth} origin develop`);
await exec(`git fetch --depth ${depth} origin ${process.env.CIRCLE_BRANCH}`);
return true;
} catch (error: unknown) {
console.error(`Failed to fetch with depth ${depth}:`, error);
return false;
}
}

/**
* Attempts to fetch the necessary commits until the merge base is found.
* It tries different fetch depths and performs a full fetch if needed.
*
* @throws If an unexpected error occurs during the execution of git commands.
*/
async function fetchUntilMergeBaseFound() {
const depths = [1, 10, 100];
for (const depth of depths) {
console.log(`Attempting git diff with depth ${depth}...`);
await fetchWithDepth(depth);

try {
await exec(`git merge-base origin/HEAD HEAD`);
return;
} catch (error: unknown) {
if (
error instanceof Error &&
hasProperty(error, 'code') &&
error.code === 1
) {
console.error(`Error 'no merge base' encountered with depth ${depth}. Incrementing depth...`);
} else {
throw error;
}
}
}
await exec(`git fetch --unshallow origin develop`);
}

/**
* Performs a git diff command to get the list of files changed between the current branch and the origin.
* It first ensures that the necessary commits are fetched until the merge base is found.
*
* @returns The output of the git diff command, listing the changed files.
* @throws If unable to get the diff after fetching the merge base or if an unexpected error occurs.
*/
async function gitDiff(): Promise<string> {
await fetchUntilMergeBaseFound();
const { stdout: diffResult } = await exec(`git diff --name-only origin/HEAD...${process.env.CIRCLE_BRANCH}`);
if (!diffResult) {
throw new Error('Unable to get diff after full checkout.');
}
return diffResult;
}

/**
* Stores the output of git diff to a file.
*
* @returns Returns a promise that resolves when the git diff output is successfully stored.
*/
async function storeGitDiffOutput() {
try {
console.log("Attempting to get git diff...");
const diffOutput = await gitDiff();
console.log(diffOutput);

// Create the directory
const outputDir = 'changed-files';
fs.mkdirSync(outputDir, { recursive: true });

// Store the output of git diff
const outputPath = path.resolve(outputDir, 'changed-files.txt');
fs.writeFileSync(outputPath, diffOutput.trim());

console.log(`Git diff results saved to ${outputPath}`);
process.exit(0);
} catch (error: any) {
console.error('An error occurred:', error.message);
process.exit(1);
}
}

storeGitDiffOutput();
31 changes: 31 additions & 0 deletions .circleci/scripts/validate-locales-only.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { readChangedFiles } = require('../../test/e2e/changedFilesUtil.js');

/**
* Verifies that all changed files are in the /_locales/ directory.
* Fails the build if any changed files are outside of the /_locales/ directory.
* Fails if no changed files are detected.
*/
async function validateLocalesOnlyChangedFiles() {
const changedFiles = await readChangedFiles();
if (!changedFiles || changedFiles.length === 0) {
console.error('Failure: No changed files detected.');
process.exit(1);
}
const invalidFiles = changedFiles.filter(
(file) => !file.startsWith('app/_locales/'),
);
if (invalidFiles.length > 0) {
console.error(
'Failure: Changed files must be in the /_locales/ directory.\n Changed Files:',
changedFiles,
'\n Invalid Files:',
invalidFiles,
);
process.exit(1);
} else {
console.log('Passed validation');
process.exit(0);
}
}

validateLocalesOnlyChangedFiles();
8 changes: 5 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ module.exports = {
* Mocha library.
*/
{
files: ['test/e2e/**/*.spec.js', 'test/unit-global/*.test.js'],
files: ['test/e2e/**/*.spec.js'],
extends: ['@metamask/eslint-config-mocha'],
rules: {
// In Mocha tests, it is common to use `this` to store values or do
Expand All @@ -281,7 +281,9 @@ module.exports = {
'app/scripts/controllers/mmi-controller.test.ts',
'app/scripts/metamask-controller.actions.test.js',
'app/scripts/detect-multiple-instances.test.js',
'app/scripts/controllers/swaps.test.js',
'app/scripts/controllers/bridge.test.ts',
'app/scripts/controllers/swaps/**/*.test.js',
'app/scripts/controllers/swaps/**/*.test.ts',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
Expand All @@ -297,6 +299,7 @@ module.exports = {
'test/jest/*.js',
'test/lib/timer-helpers.js',
'test/e2e/helpers.test.js',
'test/unit-global/*.test.js',
'ui/**/*.test.js',
'ui/__mocks__/*.js',
'shared/lib/error-utils.test.js',
Expand Down Expand Up @@ -365,7 +368,6 @@ module.exports = {
'development/**/*.js',
'test/e2e/benchmark.js',
'test/helpers/setup-helper.js',
'test/run-unit-tests.js',
],
rules: {
'node/no-process-exit': 'off',
Expand Down
13 changes: 11 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
# those changes on build, release and publishing outcomes.

* @MetaMask/extension-devs
**/snaps/** @MetaMask/snaps-devs
development/ @MetaMask/extension-devs @kumavis
lavamoat/ @MetaMask/extension-devs @MetaMask/supply-chain @MetaMask/snaps-devs

# The offscreen.ts script file that is included in the offscreedocument html
# The offscreen.ts script file that is included in the offscreen document html
# file is responsible, at present, for loading the snaps execution environment
# for MV3. Any changes to this file should require at least one member of the
# snaps development team to review and approve the changes.
Expand Down Expand Up @@ -84,3 +83,13 @@ ui/components/component-library @MetaMask/design-system-engineers
# Slack handle: @accounts-team-devs | Slack channel: #metamask-accounts-team

app/scripts/lib/snap-keyring @MetaMask/accounts-engineers

# Swaps team to own code for the swaps folder
ui/pages/swaps @MetaMask/swaps-engineers
app/scripts/controllers/swaps @MetaMask/swaps-engineers

# Snaps
**/snaps/** @MetaMask/snaps-devs
shared/constants/permissions.ts @MetaMask/snaps-devs
ui/helpers/utils/permission.js @MetaMask/snaps-devs
ui/hooks/useTransactionInsights.js @MetaMask/snaps-devs
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ body:
label: Error messages or log output
description: Please copy and paste any relevant error messages or log output. This will be automatically formatted, so there is no need for backticks.
render: shell
- type: dropdown
id: stage
attributes:
label: Detection stage
description: At what stage was the bug detected?
options:
- In production (default)
- In beta
- During release testing
- On the development branch
validations:
required: true
- type: input
id: version
attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ async function main(): Promise<void> {
// We can't use "GITHUB_TOKEN" here, as its permissions are scoped to the repository where the action is running.
// "GITHUB_TOKEN" does not have access to other repositories, even when they belong to the same organization.
// As we want to get files which are not necessarily located in the same repository,
// we need to create our own "RELEASE_LABEL_TOKEN" with "repo" permissions.
// we need to create our own "PERSONAL_ACCESS_TOKEN" with "repo" permissions.
// Such a token allows to access other repositories of the MetaMask organisation.
const personalAccessToken = process.env.RELEASE_LABEL_TOKEN;
const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN;
if (!personalAccessToken) {
core.setFailed('RELEASE_LABEL_TOKEN not found');
core.setFailed('PERSONAL_ACCESS_TOKEN not found');
process.exit(1);
}

Expand Down
Loading

0 comments on commit 741695c

Please sign in to comment.