-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into basic-func-search
- Loading branch information
Showing
2,058 changed files
with
125,404 additions
and
48,855 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script is based on the documentation from CircleCI, which does not work as written | ||
# https://circleci.com/docs/browser-testing/#interacting-with-the-browser-over-vnc | ||
|
||
set -e | ||
set -u | ||
set -o pipefail | ||
set -x | ||
|
||
cd "${HOME}/project" | ||
|
||
# Install a VNC server | ||
readonly LOCK_FILE="installed.lock" | ||
if [ ! -f "${LOCK_FILE}" ]; then | ||
sudo apt update | ||
sudo apt install -y x11vnc | ||
|
||
touch "${LOCK_FILE}" | ||
fi | ||
|
||
# Start VNC server | ||
if ! pgrep x11vnc > /dev/null; then | ||
x11vnc -display "$DISPLAY" -bg -forever -nopw -quiet -listen localhost -xkb -rfbport 5901 -passwd password | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
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); | ||
|
||
const MAIN_BRANCH = 'develop'; | ||
|
||
/** | ||
* Get the target branch for the given pull request. | ||
* | ||
* @returns The name of the branch targeted by the PR. | ||
*/ | ||
async function getBaseRef(): Promise<string | null> { | ||
if (!process.env.CIRCLE_PULL_REQUEST) { | ||
return null; | ||
} | ||
|
||
// We're referencing the CIRCLE_PULL_REQUEST environment variable within the script rather than | ||
// passing it in because this makes it easier to use Bash parameter expansion to extract the | ||
// PR number from the URL. | ||
const result = await exec(`gh pr view --json baseRefName "\${CIRCLE_PULL_REQUEST##*/}" --jq '.baseRefName'`); | ||
const baseRef = result.stdout.trim(); | ||
return baseRef; | ||
} | ||
|
||
/** | ||
* 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 { | ||
// Create the directory | ||
// This is done first because our CirleCI config requires that this directory is present, | ||
// even if we want to skip this step. | ||
const outputDir = 'changed-files'; | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
|
||
console.log(`Determining whether this run is for a PR targetting ${MAIN_BRANCH}`) | ||
if (!process.env.CIRCLE_PULL_REQUEST) { | ||
console.log("Not a PR, skipping git diff"); | ||
return; | ||
} | ||
|
||
const baseRef = await getBaseRef(); | ||
if (baseRef === null) { | ||
console.log("Not a PR, skipping git diff"); | ||
return; | ||
} else if (baseRef !== MAIN_BRANCH) { | ||
console.log(`This is for a PR targeting '${baseRef}', skipping git diff`); | ||
return; | ||
} | ||
|
||
console.log("Attempting to get git diff..."); | ||
const diffOutput = await gitDiff(); | ||
console.log(diffOutput); | ||
|
||
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.