Skip to content

Commit

Permalink
Merge branch 'develop' into move-unit-tests-to-github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyoboieltr committed Jul 1, 2024
2 parents ce18831 + 3ea381d commit 766a339
Show file tree
Hide file tree
Showing 165 changed files with 4,532 additions and 2,181 deletions.
35 changes: 33 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ workflows:
- prep-deps
- check-pr-tag
- prep-deps
- get-changed-files-with-git-diff:
requires:
- prep-deps
- test-deps-audit:
requires:
- prep-deps
Expand Down Expand Up @@ -187,41 +190,51 @@ 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
- get-changed-files-with-git-diff
- 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
- get-changed-files-with-git-diff
- 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-chrome-rpc-mmi:
requires:
- prep-build-test-mmi
- get-changed-files-with-git-diff
- test-e2e-chrome-vault-decryption:
filters:
branches:
Expand All @@ -230,6 +243,7 @@ workflows:
- /^Version-v(\d+)[.](\d+)[.](\d+)/
requires:
- prep-build
- get-changed-files-with-git-diff
- test-unit-global:
requires:
- prep-deps
Expand Down Expand Up @@ -459,6 +473,23 @@ 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.
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 @@ -1121,7 +1152,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 @@ -1412,7 +1443,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
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
22 changes: 6 additions & 16 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
name: Sonar
on:
workflow_call:
secrets:
SONAR_TOKEN:
required: true
# pull_request:
# branches:
# - develop
# types:
# - opened
# - reopened
# - synchronize
# - labeled
# - unlabeled
push:
branches:
- develop
pull_request:
branches:
- develop

jobs:
sonarcloud:
Expand All @@ -25,8 +18,5 @@ jobs:
- name: SonarCloud Scan
# This is SonarSource/[email protected]
uses: SonarSource/sonarcloud-github-action@4b4d7634dab97dcee0b75763a54a6dc92a9e6bc1
with:
args: >
-Dsonar.javascript.lcov.reportPaths=tests/coverage/lcov.info
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1 change: 1 addition & 0 deletions .metamaskrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ INFURA_PROJECT_ID=00000000000

;PASSWORD=METAMASK PASSWORD
;SEGMENT_WRITE_KEY=
;BRIDGE_USE_DEV_APIS=
;SWAPS_USE_DEV_APIS=
;PORTFOLIO_URL=
;TRANSACTION_SECURITY_PROVIDER=
Expand Down
5 changes: 1 addition & 4 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 766a339

Please sign in to comment.