Skip to content

Commit

Permalink
Merge branch 'develop' into mrtenz/update-snaps-codeowners
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding authored Jul 11, 2024
2 parents 6101848 + b9403b8 commit f8fb24e
Show file tree
Hide file tree
Showing 469 changed files with 21,826 additions and 6,144 deletions.
143 changes: 75 additions & 68 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ develop_master_rc_only: &develop_master_rc_only
- master
- /^Version-v(\d+)[.](\d+)[.](\d+)/

exclude_develop_master_rc: &exclude_develop_master_rc
filters:
branches:
ignore:
- develop
- master
- /^Version-v(\d+)[.](\d+)[.](\d+)/
aliases:
# Shallow Git Clone
- &shallow-git-clone
Expand Down Expand Up @@ -105,6 +112,10 @@ workflows:
- prep-deps
- check-pr-tag
- prep-deps
- get-changed-files-with-git-diff:
<<: *exclude_develop_master_rc
requires:
- prep-deps
- test-deps-audit:
requires:
- prep-deps
Expand Down Expand Up @@ -187,41 +198,52 @@ workflows:
- test-e2e-chrome:
requires:
- prep-build-test
- get-changed-files-with-git-diff
- test-e2e-chrome-confirmation-redesign:
requires:
- prep-build-confirmation-redesign-test
- get-changed-files-with-git-diff
- test-e2e-firefox:
requires:
- prep-build-test-mv2
- get-changed-files-with-git-diff
- test-e2e-firefox-confirmation-redesign:
<<: *develop_master_rc_only
requires:
- prep-build-confirmation-redesign-test-mv2
- test-e2e-chrome-rpc:
requires:
- prep-build-test
- get-changed-files-with-git-diff
- test-api-specs:
requires:
- prep-build-test
- test-e2e-chrome-multiple-providers:
requires:
- prep-build-test
- get-changed-files-with-git-diff
- test-e2e-chrome-flask:
requires:
- prep-build-test-flask
- get-changed-files-with-git-diff
- test-e2e-firefox-flask:
<<: *develop_master_rc_only
requires:
- prep-build-test-flask-mv2
- test-e2e-chrome-mmi:
requires:
- prep-build-test-mmi
- get-changed-files-with-git-diff
- test-e2e-mmi-playwright - OPTIONAL:
requires:
- prep-build-test-mmi-playwright
- test-e2e-swap-playwright - OPTIONAL:
requires:
- prep-build
- test-e2e-chrome-rpc-mmi:
requires:
- prep-build-test-mmi
- get-changed-files-with-git-diff
- test-e2e-chrome-vault-decryption:
filters:
branches:
Expand All @@ -230,16 +252,6 @@ workflows:
- /^Version-v(\d+)[.](\d+)[.](\d+)/
requires:
- prep-build
- test-unit-jest-main:
requires:
- prep-deps
- test-unit-jest-development:
requires:
- prep-deps
- upload-coverage:
requires:
- test-unit-jest-main
- test-unit-jest-development
- test-unit-global:
requires:
- prep-deps
Expand Down Expand Up @@ -283,10 +295,7 @@ workflows:
- test-lint-shellcheck
- test-lint-lockfile
- test-lint-changelog
- test-unit-jest-main
- test-unit-jest-development
- test-unit-global
- upload-coverage
- validate-source-maps
- validate-source-maps-beta
- validate-source-maps-flask
Expand Down Expand Up @@ -472,6 +481,24 @@ jobs:
- node_modules
- build-artifacts

# This job is used for the e2e quality gate.
# It must be run before any job which uses the run-all.js script.
# The job is skipped in develop, master or RC branches.
get-changed-files-with-git-diff:
executor: node-browsers-small
steps:
- run: *shallow-git-clone
- run: sudo corepack enable
- attach_workspace:
at: .
- run:
name: Get changed files with git diff
command: npx tsx .circleci/scripts/git-diff-develop.ts
- persist_to_workspace:
root: .
paths:
- changed-files

validate-lavamoat-allow-scripts:
executor: node-browsers-small
steps:
Expand Down Expand Up @@ -1134,7 +1161,7 @@ jobs:
fi
no_output_timeout: 5m
environment:
ENABLE_CONFIRMATION_REDESIGN: "true"
ENABLE_CONFIRMATION_REDESIGN: 'true'
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down Expand Up @@ -1349,9 +1376,9 @@ jobs:
- run:
name: test:e2e:chrome:mmi
command: |
TESTFILES=$(circleci tests glob "test/e2e/mmi/**/*.spec.ts")
TESTFILES=$(circleci tests glob "test/e2e/playwright/mmi/**/*.spec.ts")
echo "$TESTFILES"
echo "$TESTFILES" | timeout 20m circleci tests run --command="xvfb-run xargs yarn playwright test" verbose --split-by=timings
echo "$TESTFILES" | timeout 20m circleci tests run --command="xvfb-run xargs yarn playwright test --project=mmi" verbose --split-by=timings
no_output_timeout: 10m
- slack/notify:
branch_pattern: Version-v*
Expand All @@ -1372,6 +1399,37 @@ jobs:
name: report for pipeline integration
path: public/playwright/playwright-reports/junit/test-results.xml

test-e2e-swap-playwright - OPTIONAL:
executor: playwright
parallelism: 2
steps:
- run: *shallow-git-clone
- run: corepack enable
- attach_workspace:
at: .
- run:
name: Install chromium
command: |
yarn playwright install chromium
- run:
name: test:e2e:chrome:swap
command: |
TESTFILES=$(circleci tests glob "test/e2e/playwright/swap/**/*.spec.ts")
echo "$TESTFILES"
echo "$TESTFILES" | timeout 20m circleci tests run --command="xvfb-run xargs yarn playwright test --project=swap" verbose
no_output_timeout: 10m
- slack/notify:
event: fail
mentions: <@davide.brocchetto>
template: basic_fail_1
channel: C06BEG71R1S
- store_artifacts:
name: html-report and artifacts
path: public/playwright/playwright-reports
- store_test_results:
name: report for pipeline integration
path: public/playwright/playwright-reports/junit/test-results.xml

test-e2e-firefox:
executor: node-browsers-medium-plus
parallelism: 24
Expand Down Expand Up @@ -1425,7 +1483,7 @@ jobs:
fi
no_output_timeout: 5m
environment:
ENABLE_CONFIRMATION_REDESIGN: "true"
ENABLE_CONFIRMATION_REDESIGN: 'true'
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down Expand Up @@ -1559,9 +1617,6 @@ jobs:
path: builds-test
- store_artifacts:
path: builds-test-flask
- store_artifacts:
path: coverage
destination: coverage
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down Expand Up @@ -1642,54 +1697,6 @@ jobs:
git config user.email [email protected]
yarn ts-migration:dashboard:deploy
test-unit-jest-development:
executor: node-browsers-small
steps:
- run: *shallow-git-clone
- run: sudo corepack enable
- attach_workspace:
at: .
- run:
name: jest development unit tests
command: yarn test:coverage:jest:dev
- persist_to_workspace:
root: .
paths:
- coverage
- store_test_results:
path: test/test-results/junit.xml

test-unit-jest-main:
executor: node-browsers-medium-plus
parallelism: 8
steps:
- run: *shallow-git-clone
- run: sudo corepack enable
- attach_workspace:
at: .
- run:
name: test:coverage:jest
command: yarn test:coverage:jest
- persist_to_workspace:
root: .
paths:
- coverage
- store_test_results:
path: test/test-results/junit.xml

upload-coverage:
executor: node-browsers-small
steps:
- run: *shallow-git-clone
- run: sudo corepack enable
- attach_workspace:
at: .
- codecov/upload
- persist_to_workspace:
root: .
paths:
- coverage

test-unit-global:
executor: node-browsers-small
steps:
Expand Down
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);

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();
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ 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/bridge.test.ts',
'app/scripts/controllers/swaps.test.js',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
Expand Down
17 changes: 17 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Setup environment'
description: 'Setup environment'
runs:
using: 'composite'
steps:
- run: corepack enable
shell: bash

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Install dependencies
run: yarn --immutable
shell: bash
Loading

0 comments on commit f8fb24e

Please sign in to comment.