From 6f1d3b5f02b153a2eccae9f04cbd583816ffca00 Mon Sep 17 00:00:00 2001 From: Howard Braham Date: Mon, 16 Dec 2024 02:56:58 +0530 Subject: [PATCH] ci: setup prep-deps on GitHub Actions, and try self-hosted runners for benchmarks --- .github/actions/setup-environment/action.yml | 50 +++++++++++++++ .github/workflows/benchmarks.yml | 67 ++++++++++++++++++++ .github/workflows/main.yml | 30 +++++++-- .github/workflows/run-tests.yml | 29 ++++----- 4 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 .github/actions/setup-environment/action.yml create mode 100644 .github/workflows/benchmarks.yml diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml new file mode 100644 index 000000000000..5849904f7624 --- /dev/null +++ b/.github/actions/setup-environment/action.yml @@ -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 }} diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 000000000000..152306f2b38c --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7907455701d..b30310385497 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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 }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3cb7c50e573a..45aa74dae310 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 }} @@ -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 @@ -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 @@ -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