Skip to content

Commit

Permalink
feat: build beta (#29712)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29712?quickstart=1)

This PR migrates the beta build from CircleCI to GitHub Actions. 

## **Related issues**

Fixes: #28572,
#29446

## **Manual testing steps**

For commit messages matching the pattern: `Version v0.0.0-beta.0` on any
branch other than `master,` the following should happen:

1. Build should run on GH Actions
2. Build should be uploaded on S3
3. Build should appear in the metamaskbot comment

## **Screenshots/Recordings**

Not applicable

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
itsyoboieltr authored Jan 22, 2025
1 parent 615c469 commit 5024615
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 113 deletions.
55 changes: 0 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ workflows:
<<: *rc_branch_only
requires:
- prep-deps
- trigger-beta-build:
requires:
- prep-deps
- prep-deps
- get-changed-files-with-git-diff:
filters:
Expand Down Expand Up @@ -198,9 +195,6 @@ workflows:
- validate-source-maps-mv2:
requires:
- prep-build-mv2
- validate-source-maps-beta:
requires:
- trigger-beta-build
- validate-source-maps-flask:
requires:
- prep-build-flask
Expand All @@ -218,7 +212,6 @@ workflows:
- all-tests-pass:
requires:
- validate-source-maps
- validate-source-maps-beta
- validate-source-maps-flask
- test-mozilla-lint-mv2
- test-mozilla-lint-flask-mv2
Expand Down Expand Up @@ -250,7 +243,6 @@ workflows:
- prep-build-test-mv2
- prep-build-test-flask
- prep-build-test-flask-mv2
- trigger-beta-build
- prep-build-storybook
- prep-build-ts-migration-dashboard
- benchmark
Expand Down Expand Up @@ -316,35 +308,6 @@ workflows:
- validate-locales-only

jobs:
trigger-beta-build:
executor: node-browsers-small
steps:
- run: *shallow-git-clone-and-enable-vnc
- run: sudo corepack enable
- attach_workspace:
at: .
- when:
condition:
not:
matches:
pattern: /^master$/
value: << pipeline.git.branch >>
steps:
- run:
name: Build beta prod
command: .circleci/scripts/trigger-beta-build.sh
- run:
name: Move beta build to 'dist-beta' to avoid conflict with production build
command: mv ./dist ./dist-beta
- run:
name: Move beta zips to 'builds-beta' to avoid conflict with production build
command: mv ./builds ./builds-beta
- persist_to_workspace:
root: .
paths:
- dist-beta
- builds-beta

create_release_pull_request:
executor: node-browsers-medium
steps:
Expand Down Expand Up @@ -1089,25 +1052,18 @@ jobs:
- store_artifacts:
path: dist/sourcemaps
destination: builds/sourcemaps
- store_artifacts:
path: dist-beta/sourcemaps
destination: builds-beta/sourcemaps
- store_artifacts:
path: dist-flask/sourcemaps
destination: builds-flask/sourcemaps
- store_artifacts:
path: builds
destination: builds
- store_artifacts:
path: builds-beta
destination: builds-beta
- store_artifacts:
path: builds-flask
destination: builds-flask
- store_artifacts:
path: builds-flask-mv2
destination: builds-flask-mv2

- store_artifacts:
path: builds-mv2
destination: builds-mv2
Expand Down Expand Up @@ -1204,17 +1160,6 @@ jobs:
name: Validate source maps
command: yarn validate-source-maps

validate-source-maps-beta:
executor: node-browsers-small
steps:
- run: *shallow-git-clone-and-enable-vnc
- run: sudo corepack enable
- attach_workspace:
at: .
- run:
name: Validate source maps
command: .circleci/scripts/validate-source-maps-beta.sh

validate-source-maps-flask:
executor: node-browsers-small
steps:
Expand Down
11 changes: 0 additions & 11 deletions .circleci/scripts/check-working-tree.sh

This file was deleted.

25 changes: 0 additions & 25 deletions .circleci/scripts/trigger-beta-build.sh

This file was deleted.

22 changes: 0 additions & 22 deletions .circleci/scripts/validate-source-maps-beta.sh

This file was deleted.

78 changes: 78 additions & 0 deletions .github/workflows/build-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build beta

on:
workflow_call:

jobs:
build-beta:
name: Build beta
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# By default, the checkout action checks out the last merge commit for pull requests.
# Source: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request
# However, we need the head commit (the latest commit pushed to the source branch)
# because in the workflow, we would like to parse the latest commit message.
# Specifying `ref` ensures that the head commit is checked out directly.
# For a `pull_request` event, the head commit hash is `github.event.pull_request.head.sha`.
# For a `push` event, the head commit hash is `github.sha`.
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Needs beta build
# For a `pull_request` event, the branch is `github.head_ref``.
# For a `push` event, the branch is `github.ref_name`.
if: ${{ (github.head_ref || github.ref_name) != 'master' }}
id: needs-beta-build
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
version="${BRANCH/Version-v/}"
commit_message=$(git show -s --format=%s HEAD)
beta_version_regex="Version v[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+"
if [[ "$commit_message" =~ $beta_version_regex ]]; then
printf '%s\n' "Creating a build for $version with $commit_message"
echo "NEEDS_BETA_BUILD=true" >> "$GITHUB_OUTPUT"
else
printf '%s\n' 'Commit message does not match commit message for beta pattern; skipping beta build'
echo "NEEDS_BETA_BUILD=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup environment
if: ${{ steps.needs-beta-build.outputs.NEEDS_BETA_BUILD == 'true' }}
uses: metamask/github-tools/.github/actions/setup-environment@main

- name: Run beta build
if: ${{ steps.needs-beta-build.outputs.NEEDS_BETA_BUILD == 'true' }}
env:
INFURA_PROJECT_ID: 00000000000
INFURA_BETA_PROJECT_ID: 00000000000
SEGMENT_BETA_WRITE_KEY: 00000000000
ENABLE_MV3: true
run: |
yarn build --build-type beta --platform='chrome' dist
yarn build --build-type beta --platform='chrome' prod
- name: Validate source maps
if: ${{ steps.needs-beta-build.outputs.NEEDS_BETA_BUILD == 'true' }}
run: yarn validate-source-maps

- name: Upload 'dist-beta' to S3
if: ${{ steps.needs-beta-build.outputs.NEEDS_BETA_BUILD == 'true' }}
uses: metamask/github-tools/.github/actions/upload-s3@1233659b3850eb84824d7375e2e0c58eb237701d
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.AWS_IAM_ROLE }}
s3-bucket: ${{ vars.AWS_S3_BUCKET }}/${{ github.event.repository.name }}/${{ github.run_id }}/dist-beta
path: dist

- name: Upload 'builds-beta' to S3
if: ${{ steps.needs-beta-build.outputs.NEEDS_BETA_BUILD == 'true' }}
uses: metamask/github-tools/.github/actions/upload-s3@1233659b3850eb84824d7375e2e0c58eb237701d
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.AWS_IAM_ROLE }}
s3-bucket: ${{ vars.AWS_S3_BUCKET }}/${{ github.event.repository.name }}/${{ github.run_id }}/builds-beta
path: builds
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ jobs:
- wait-for-circleci-workflow-status
uses: ./.github/workflows/runway.yml

build-beta:
name: Build beta
uses: ./.github/workflows/build-beta.yml
permissions:
contents: read
id-token: write

publish-prerelease:
name: Publish prerelease
if: ${{ github.event_name == 'pull_request' }}
needs:
- wait-for-circleci-workflow-status
- build-beta
uses: ./.github/workflows/publish-prerelease.yml
secrets:
PR_COMMENT_TOKEN: ${{ secrets.PR_COMMENT_TOKEN }}
Expand All @@ -100,6 +108,7 @@ jobs:
- validate-lavamoat-policy-webapp
- run-tests
- wait-for-circleci-workflow-status
- build-beta
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ jobs:
MERGE_BASE_COMMIT_HASH: ${{ steps.get-merge-base.outputs.MERGE_BASE }}
CIRCLE_BUILD_NUM: ${{ steps.get-circleci-job-details.outputs.CIRCLE_BUILD_NUM }}
CIRCLE_WORKFLOW_JOB_ID: ${{ steps.get-circleci-job-details.outputs.CIRCLE_WORKFLOW_JOB_ID }}
HOST_URL: ${{ vars.AWS_CLOUDFRONT_URL }}/${{ github.event.repository.name }}/${{ github.run_id }}
run: ./development/metamaskbot-build-announce.js
19 changes: 19 additions & 0 deletions development/metamaskbot-build-announce.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node

const { promisify } = require('util');
const { promises: fs } = require('fs');
const execFile = promisify(require('child_process').execFile);
const path = require('path');
// Fetch is part of node js in future versions, thus triggering no-shadow
// eslint-disable-next-line no-shadow
Expand Down Expand Up @@ -58,13 +60,15 @@ async function start() {
MERGE_BASE_COMMIT_HASH,
CIRCLE_BUILD_NUM,
CIRCLE_WORKFLOW_JOB_ID,
HOST_URL,
} = process.env;

console.log('PR_NUMBER', PR_NUMBER);
console.log('HEAD_COMMIT_HASH', HEAD_COMMIT_HASH);
console.log('MERGE_BASE_COMMIT_HASH', MERGE_BASE_COMMIT_HASH);
console.log('CIRCLE_BUILD_NUM', CIRCLE_BUILD_NUM);
console.log('CIRCLE_WORKFLOW_JOB_ID', CIRCLE_WORKFLOW_JOB_ID);
console.log('HOST_URL', HOST_URL);

if (!PR_NUMBER) {
console.warn(`No pull request detected for commit "${HEAD_COMMIT_HASH}"`);
Expand Down Expand Up @@ -98,6 +102,21 @@ async function start() {
},
};

const commitMessage = (
await execFile('git', ['show', '-s', '--format=%s', HEAD_COMMIT_HASH])
).stdout.trim();
const betaVersionRegex = /Version v[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+/u;
const betaMatch = commitMessage.match(betaVersionRegex);

// only include beta build link if a beta version is detected in the commit message
if (betaMatch) {
const betaVersion = betaMatch[0].split('-beta.')[1];
console.log(`Beta version ${betaVersion} detected, adding beta build link`);
buildMap['builds (beta)'] = {
chrome: `${HOST_URL}/builds-beta/metamask-beta-chrome-${VERSION}-beta.${betaVersion}.zip`,
};
}

const buildContentRows = Object.entries(buildMap).map(([label, builds]) => {
const buildLinks = Object.entries(builds).map(([platform, url]) => {
return `<a href="${url}">${platform}</a>`;
Expand Down

0 comments on commit 5024615

Please sign in to comment.