Skip to content

Commit

Permalink
Merge branch 'main' into salim/fix-network-selector-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Dec 13, 2024
2 parents 639de84 + 30e8f6d commit 5a5d644
Show file tree
Hide file tree
Showing 227 changed files with 13,438 additions and 4,185 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ app/util/walletconnect.js @MetaMask/sdk-devs

# Accounts Team
app/core/Encryptor/ @MetaMask/accounts-engineers
app/core/Engine/controllers/accounts @MetaMask/accounts-engineers
app/core/Engine/controllers/AccountsController @MetaMask/accounts-engineers

# Swaps Team
app/components/UI/Swaps @MetaMask/swaps-engineers
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ body:
- In production (default)
- In beta
- During release testing
- On the development branch
- On main branch
- On a feature branch
validations:
required: true
- type: input
Expand Down
3 changes: 2 additions & 1 deletion .github/guidelines/LABELING_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ To merge your PR one of the following QA labels are required:
- **Run E2E Smoke**: This label will kick-off E2E testing and trigger a check to make sure the E2E tests pass.

### Optional labels:
- **regression-develop**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on the development branch, i.e., `main`, but is not yet released in production.
- **regression-main**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on the development branch, i.e., `main`, but is not yet released in production.
- **feature-branch-bug**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on a feature branch, i.e., before merging to `main`.

### Labels prohibited when PR needs to be merged:
Any PR that includes one of the following labels can not be merged:
Expand Down
238 changes: 114 additions & 124 deletions .github/scripts/bitrise/run-bitrise-e2e-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,107 @@ import {
} from '../scripts.types';
import axios from 'axios';

let octokitInstance: InstanceType<typeof GitHub> | null = null;
let owner: string;
let repo: string;

main().catch((error: Error): void => {
console.error(error);
process.exit(1);
});



function getOctokitInstance(): InstanceType<typeof GitHub> {
if (!octokitInstance) {
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
throw new Error("GitHub token is not set in the environment variables");
}
octokitInstance = getOctokit(githubToken);
}
return octokitInstance;
}

async function upsertStatusCheck(
statusCheckName: string,
commitHash: string,
status: StatusCheckStatusType,
conclusion: CompletedConclusionType | undefined,
summary: string
): Promise<void> {
const octokit = getOctokitInstance();

// List existing checks
const listResponse = await octokit.rest.checks.listForRef({
owner,
repo,
ref: commitHash,
});

if (listResponse.status !== 200) {
core.setFailed(
`Failed to list checks for commit ${commitHash}, received status code ${listResponse.status}`,
);
process.exit(1);
}

const existingCheck = listResponse.data.check_runs.find(check => check.name === statusCheckName);

if (existingCheck) {
console.log(`Check already exists: ${existingCheck.name}, updating...`);
// Update the existing check
const updateCheckResponse = await octokit.rest.checks.update({
owner,
repo,
check_run_id: existingCheck.id,
name: statusCheckName,
status: status,
conclusion: conclusion,
output: {
title: `${statusCheckName} Status Check`,
summary: summary,
},
});

if (updateCheckResponse.status !== 200) {
core.setFailed(
`Failed to update '${statusCheckName}' check with status ${status} for commit ${commitHash}, got status code ${updateCheckResponse.status}`,
);
process.exit(1);
}

console.log(`Updated existing check: ${statusCheckName} with id ${existingCheck.id} & status ${status} for commit ${commitHash}`);



} else {
console.log(`Check does not exist: ${statusCheckName}, creating...`);
// Create a new status check
const createCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: commitHash,
status: status,
conclusion: conclusion,
started_at: new Date().toISOString(),
output: {
title: `${statusCheckName} Status Check`,
summary: summary,
},
});

if (createCheckResponse.status !== 201) {
core.setFailed(
`Failed to create '${statusCheckName}' check with status ${status} for commit ${commitHash}, got status code ${createCheckResponse.status}`,
);
process.exit(1);
}

console.log(`Created check: ${statusCheckName} with id ${createCheckResponse.data.id} & status ${status} for commit ${commitHash}`);
}
}
// Determine whether E2E should run and provide the associated reason
function shouldRunBitriseE2E(antiLabel: boolean, hasSmokeTestLabel: boolean, isDocs: boolean, isFork: boolean, isMergeQueue: boolean): [boolean, string] {

Expand Down Expand Up @@ -43,7 +139,11 @@ async function main(): Promise<void> {
const e2ePipeline = process.env.E2E_PIPELINE;
const workflowName = process.env.WORKFLOW_NAME;
const triggerAction = context.payload.action as PullRequestTriggerType;
const { owner, repo, number: pullRequestNumber } = context.issue;
// Assuming context.issue comes populated with owner and repo, as typical with GitHub Actions
const { owner: contextOwner, repo: contextRepo, number: pullRequestNumber } = context.issue;
owner = contextOwner;
repo = contextRepo;

const removeAndApplyInstructions = `Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`;
const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`;
const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${pullRequestNumber}`;
Expand Down Expand Up @@ -80,7 +180,7 @@ async function main(): Promise<void> {
const mqCommitHash = context.payload?.merge_group?.head_sha;


const octokit: InstanceType<typeof GitHub> = getOctokit(githubToken);
const octokit = getOctokitInstance();

const { data: prData } = await octokit.rest.pulls.get({
owner,
Expand Down Expand Up @@ -114,67 +214,18 @@ async function main(): Promise<void> {
if (!mergeQueue && !hasSmokeTestLabel && !hasAntiLabel) {

// Fail Status due to missing labels
const createStatusCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: latestCommitHash,
status: StatusCheckStatusType.Completed,
conclusion: CompletedConclusionType.Failure,
started_at: new Date().toISOString(),
output: {
title: statusCheckTitle,
summary: `Failed due to missing labels. Please apply either ${e2eLabel} or ${antiLabel}.`,
},
});

if (createStatusCheckResponse.status === 201) {
console.log(
`Created '${statusCheckName}' check with failed status for commit ${latestCommitHash}`,
);
} else {
core.setFailed(
`Failed to create '${statusCheckName}' check with failed status for commit ${latestCommitHash} with status code ${createStatusCheckResponse.status}`,
);
process.exit(1);
}
core.setFailed(
`At least 1 E2E Label must be Applied either ${e2eLabel} or ${antiLabel}`,
);
process.exit(1);
await upsertStatusCheck(statusCheckName, latestCommitHash, StatusCheckStatusType.Completed,
CompletedConclusionType.Failure, `Failed due to missing labels. Please apply either ${e2eLabel} or ${antiLabel}.`);
return
}

if (!shouldRun) {
console.log(
`Skipping Bitrise status check. due to the following reason: ${reason}`,
);


// Post success status (skipped)
const createStatusCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: latestCommitHash,
status: StatusCheckStatusType.Completed,
conclusion: CompletedConclusionType.Success,
started_at: new Date().toISOString(),
output: {
title: statusCheckTitle,
summary: `Skip run since ${reason}`,
},
});

if (createStatusCheckResponse.status === 201) {
console.log(
`Created '${statusCheckName}' check with skipped status for commit ${latestCommitHash}`,
);
} else {
core.setFailed(
`Failed to create '${statusCheckName}' check with skipped status for commit ${latestCommitHash} with status code ${createStatusCheckResponse.status}`,
);
process.exit(1);
}
await upsertStatusCheck(statusCheckName, latestCommitHash, StatusCheckStatusType.Completed, CompletedConclusionType.Success,
`Skip run since ${reason}`);
return;
}

Expand Down Expand Up @@ -314,29 +365,9 @@ async function main(): Promise<void> {
// Post pending status
console.log(`Posting pending status for commit ${latestCommitHash}`);

const createStatusCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: latestCommitHash,
status: StatusCheckStatusType.InProgress,
started_at: new Date().toISOString(),
output: {
title: statusCheckTitle,
summary: `Test runs in progress... You can view them at ${buildLink}`,
},
});
await upsertStatusCheck( statusCheckName, latestCommitHash, StatusCheckStatusType.InProgress, undefined, `Test runs in progress... You can view them at ${buildLink}`);


if (createStatusCheckResponse.status === 201) {
console.log(
`Created '${statusCheckName}' check for commit ${latestCommitHash}`,
);
} else {
core.setFailed(
`Failed to create '${statusCheckName}' check for commit ${latestCommitHash} with status code ${createStatusCheckResponse.status}`,
);
process.exit(1);
}
return;
}

Expand Down Expand Up @@ -383,31 +414,11 @@ async function main(): Promise<void> {
if (!bitriseComment) {

console.log(`Bitrise comment not detected for commit ${latestCommitHash}`);
// Post fail status
const createStatusCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: latestCommitHash,
status: StatusCheckStatusType.Completed,
conclusion: CompletedConclusionType.Failure,
started_at: new Date().toISOString(),
output: {
title: statusCheckTitle,
summary: `No Bitrise comment found for commit ${latestCommitHash}. Try re-applying the '${e2eLabel}' label.`,
},
});

if (createStatusCheckResponse.status === 201) {
console.log(
`Created '${statusCheckName}' check for commit ${latestCommitHash}`,
);
} else {
core.setFailed(
`Failed to create '${statusCheckName}' check for commit ${latestCommitHash} with status code ${createStatusCheckResponse.status}`,
);
process.exit(1);
}
await upsertStatusCheck(statusCheckName, latestCommitHash, StatusCheckStatusType.Completed,
CompletedConclusionType.Failure,
`No Bitrise comment found for commit ${latestCommitHash}. Try re-applying the '${e2eLabel}' label.`);

return;
}

Expand Down Expand Up @@ -498,27 +509,6 @@ async function main(): Promise<void> {
}

// Post status check
const createStatusCheckResponse = await octokit.rest.checks.create({
owner,
repo,
name: statusCheckName,
head_sha: latestCommitHash,
started_at: new Date().toISOString(),
output: {
title: statusCheckTitle,
summary: statusMessage,
},
...checkStatus,
});
await upsertStatusCheck(statusCheckName, latestCommitHash, checkStatus.status, checkStatus.conclusion, statusMessage);

if (createStatusCheckResponse.status === 201) {
console.log(
`Created '${statusCheckName}' check for commit ${latestCommitHash}`,
);
} else {
core.setFailed(
`Failed to create '${statusCheckName}' check for commit ${latestCommitHash} with status code ${createStatusCheckResponse.status}`,
);
process.exit(1);
}
}
20 changes: 15 additions & 5 deletions .github/scripts/check-template-and-add-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { TemplateType, templates } from './shared/template';
import { retrievePullRequest } from './shared/pull-request';

enum RegressionStage {
Development,
DevelopmentFeature,
DevelopmentMain,
Testing,
Beta,
Production
Expand Down Expand Up @@ -202,8 +203,10 @@ function extractRegressionStageFromBugReportIssueBody(
const extractedAnswer = match ? match[1].trim() : undefined;

switch (extractedAnswer) {
case 'On the development branch':
return RegressionStage.Development;
case 'On a feature branch':
return RegressionStage.DevelopmentFeature;
case 'On main branch':
return RegressionStage.DevelopmentMain;
case 'During release testing':
return RegressionStage.Testing;
case 'In beta':
Expand Down Expand Up @@ -317,11 +320,18 @@ async function userBelongsToMetaMaskOrg(
// This function crafts appropriate label, corresponding to regression stage and release version.
function craftRegressionLabel(regressionStage: RegressionStage | undefined, releaseVersion: string | undefined): Label {
switch (regressionStage) {
case RegressionStage.Development:
case RegressionStage.DevelopmentFeature:
return {
name: `feature-branch-bug`,
color: '5319E7', // violet
description: `bug that was found on a feature branch, but not yet merged in main branch`,
};

case RegressionStage.DevelopmentMain:
return {
name: `regression-develop`,
color: '5319E7', // violet
description: `Regression bug that was found on development branch, but not yet present in production`,
description: `Regression bug that was found on main branch, but not yet present in production`,
};

case RegressionStage.Testing:
Expand Down
Loading

0 comments on commit 5a5d644

Please sign in to comment.