Skip to content

Commit

Permalink
ci: setup prep-deps on GitHub Actions, and try self-hosted runners fo…
Browse files Browse the repository at this point in the history
…r benchmarks
  • Loading branch information
HowardBraham committed Dec 15, 2024
1 parent bb1c77e commit 6f1d3b5
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 22 deletions.
50 changes: 50 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This script will probably eventually live at
# https://github.com/MetaMask/github-tools/blob/main/.github/actions/setup-environment/action.yml
name: Setup environment
description: Setup environment
inputs:
should-cache-restore:
required: true
should-cache-save:
required: false
default: 'false'
runs:
using: composite
steps:
- name: Checkout repository
uses: actions/checkout@v4

# actions/cache/restore will not work in a container unless zstd is installed
- name: Install zstd
if: ${{ job.container }}
run: sudo apt-get update && sudo apt-get install zstd
shell: bash

- name: Download workspace
if: ${{ inputs.should-cache-restore == 'true' }}
uses: actions/cache/restore@v4
with:
path: ./node_modules
key: workspace-${{ github.sha }}

- run: corepack enable
shell: bash

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

- name: Install dependencies
if: ${{ inputs.should-cache-restore == 'false' }}
run: yarn --immutable
shell: bash

- name: Cache workspace
if: ${{ inputs.should-cache-save == 'true' }}
uses: actions/cache/save@v4
with:
path: ./node_modules
key: workspace-${{ github.sha }}
67 changes: 67 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Run Benchmarks'

on: workflow_call

jobs:
benchmark:
name: Benchmark
# runs-on: ubuntu-latest
# runs-on: [self-hosted, Linux, X64]
runs-on: gha-mm-scale-set-ubuntu-22.04-amd64-med
container:
image: cimg/node:20.18-browsers
# options: --user root
steps:
- name: Setup environment
uses: MetaMask/metamask-extension/.github/actions/setup-environment@self-hosted-temp
with:
should-cache-restore: true

# - name: Debugging with tmate
# uses: ./.github/actions/actions-tmate

# - run: |
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# source ~/.nvm/nvm.sh
# nvm install 20
# node -v # should print `v20.18.1`.
# apt-get update
# apt-get install gh

# - run: corepack enable
# shell: bash

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

# - name: Install dependencies
# run: yarn
# shell: bash

# - run: yarn build:test
- run: yarn webpack --test

- name: Install prereqs
run: |
# apt-get update
# apt-get install -y xvfb
# apt-get -y install xorg xvfb gtk2-engines-pixbuf
# apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable
Xvfb -ac :99 -screen 0 1280x1024x16 &
# export DISPLAY=:99
- name: Run the benchmark
run: yarn benchmark:chrome --out test-artifacts/chrome/benchmark/pageload.json --retries 2

- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
with:
name: pageload
path: test-artifacts/chrome/benchmark/pageload.json
retention-days: 5
# user-actions-benchmark:
# name: User Actions Benchmark
30 changes: 24 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches:
- main
- master
- stable
- gh-readonly-queue.*
- Version-v[0-9]+.[0-9]+.[0-9]+
- trigger-ci.*
- prep-deps-and-self-hosted
pull_request:
types:
- opened
- reopened
- synchronize
types: [opened, reopened, synchronize]
merge_group:

jobs:
Expand All @@ -25,23 +27,39 @@ jobs:
shell: bash

- name: Check workflow files
run: ${{ steps.download-actionlint.outputs.executable }} -color
run: ${{ steps.download-actionlint.outputs.executable }} -color -ignore 'label ".+" is unknown'
shell: bash

prep-deps:
runs-on: ubuntu-latest
steps:
- name: Setup environment
uses: MetaMask/metamask-extension/.github/actions/setup-environment@prep-deps-and-self-hosted
with:
should-cache-restore: false
should-cache-save: true

run-tests:
name: Run tests
needs: prep-deps
uses: ./.github/workflows/run-tests.yml

run-benchmarks:
needs: prep-deps
uses: ./.github/workflows/benchmarks.yml

wait-for-circleci-workflow-status:
name: Wait for CircleCI workflow status
uses: ./.github/workflows/wait-for-circleci-workflow-status.yml

# Explanation for all-jobs-completed and all-jobs-pass being separate:
# https://github.com/MetaMask/metamask-module-template/pull/151
all-jobs-completed:
name: All jobs completed
runs-on: ubuntu-latest
needs:
- check-workflows
- run-tests
- run-benchmarks
- wait-for-circleci-workflow-status
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
Expand Down
29 changes: 13 additions & 16 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
matrix:
shard: [1, 2, 3, 4, 5, 6]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main
uses: MetaMask/metamask-extension/.github/actions/setup-environment@prep-deps-and-self-hosted
with:
should-cache-restore: true

- name: test:unit:coverage
run: yarn test:unit:coverage --shard=${{ matrix.shard }}/${{ strategy.job-total }}
Expand All @@ -39,11 +38,10 @@ jobs:
name: Webpack tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main
uses: MetaMask/metamask-extension/.github/actions/setup-environment@prep-deps-and-self-hosted
with:
should-cache-restore: true

- name: test:unit:webpack:coverage
run: yarn test:unit:webpack:coverage
Expand All @@ -60,11 +58,10 @@ jobs:
name: Integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main
uses: MetaMask/metamask-extension/.github/actions/setup-environment@prep-deps-and-self-hosted
with:
should-cache-restore: true

- name: test:integration:coverage
run: yarn test:integration:coverage
Expand All @@ -88,16 +85,16 @@ jobs:
current-coverage: ${{ steps.get-current-coverage.outputs.CURRENT_COVERAGE }}
stored-coverage: ${{ steps.get-stored-coverage.outputs.STORED_COVERAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main
uses: MetaMask/metamask-extension/.github/actions/setup-environment@prep-deps-and-self-hosted
with:
should-cache-restore: true

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: coverage
pattern: coverage-*
merge-multiple: true

- name: Merge coverage reports
Expand Down

0 comments on commit 6f1d3b5

Please sign in to comment.