Replace e2e fork node with anvil #9066
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
name: Build | |
on: | |
pull_request: {} | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
env: | |
NODE_OPTIONS: --openssl-legacy-provider | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Read .nvmrc | |
run: echo "NVMRC=$(cat ./.nvmrc)" >> $GITHUB_OUTPUT | |
id: nvm | |
- name: Use Node + Yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ steps.nvm.outputs.NVMRC }}" | |
cache: "yarn" | |
- run: yarn install --frozen-lockfile | |
- name: Detect env block | |
id: env-block | |
if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const detectEnvBlock = require("./.github/workflows/builds/detect-env-block.js") | |
return await detectEnvBlock({ github, context }) | |
- name: Dev build | |
if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo -e ${{ steps.env-block.outputs.result }} > .env | |
echo 'USE_ANALYTICS_SOURCE="BETA"' >> .env | |
yarn build | |
env: | |
ALCHEMY_KEY: ${{ secrets.DEV_ALCHEMY_API_KEY || 'oV1Rtjh61hGa97X2MTqMY9kEUcpxP-6K' }} | |
ZEROX_API_KEY: ${{ secrets.DEV_ZEROX_API_KEY }} | |
BLOCKNATIVE_API_KEY: ${{ secrets.DEV_BLOCKNATIVE_API_KEY || 'f60816ff-da02-463f-87a6-67a09c6d53fa' }} | |
DAYLIGHT_API_KEY: ${{ secrets.DAYLIGHT_API_KEY }} | |
COMMIT_SHA: ${{ github.sha }} | |
- name: Production build | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo 'USE_ANALYTICS_SOURCE="PROD"' >> .env | |
yarn build | |
env: | |
ALCHEMY_KEY: ${{ secrets.ALCHEMY_API_KEY }} | |
BLOCKNATIVE_API_KEY: ${{ secrets.BLOCKNATIVE_API_KEY }} | |
UNS_API_KEY: ${{ secrets.UNS_API_KEY }} | |
SIMPLE_HASH_API_KEY: ${{ secrets.SIMPLE_HASH_API_KEY }} | |
ZEROX_API_KEY: ${{ secrets.ZEROX_API_KEY }} | |
COMMIT_SHA: ${{ github.sha }} | |
POAP_API_KEY: ${{ secrets.POAP_API_KEY }} | |
DAYLIGHT_API_KEY: ${{ secrets.DAYLIGHT_API_KEY }} | |
- name: Create Release and Upload Artifacts | |
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: dist/*.zip | |
draft: true | |
generate_release_notes: true | |
prerelease: ${{ contains(github.ref, '-pre') || contains(github.ref, 'v0.') }} | |
- name: Upload build asset | |
if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: extension-builds-${{ github.event.number || github.event.head_commit.id }} | |
path: dist/*.zip | |
- name: Dev build on Mainnet fork | |
if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo -e ${{ steps.env-block.outputs.result }} > .env | |
echo 'USE_ANALYTICS_SOURCE="BETA"' >> .env | |
yarn build | |
find dist -name "*.zip" -exec sh -c 'mv "$1" "${1%.zip}-fork.zip"' _ {} \; | |
env: | |
ALCHEMY_KEY: ${{ secrets.DEV_ALCHEMY_API_KEY || 'oV1Rtjh61hGa97X2MTqMY9kEUcpxP-6K' }} | |
BLOCKNATIVE_API_KEY: ${{ secrets.DEV_BLOCKNATIVE_API_KEY || 'f60816ff-da02-463f-87a6-67a09c6d53fa' }} | |
DAYLIGHT_API_KEY: ${{ secrets.DAYLIGHT_API_KEY }} | |
COMMIT_SHA: ${{ github.sha }} | |
USE_MAINNET_FORK: true | |
- name: Production build on Mainnet fork | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo 'USE_ANALYTICS_SOURCE="BETA"' >> .env | |
yarn build | |
find dist -name "*.zip" -exec sh -c 'mv "$1" "${1%.zip}-fork.zip"' _ {} \; | |
env: | |
ALCHEMY_KEY: ${{ secrets.ALCHEMY_API_KEY }} | |
BLOCKNATIVE_API_KEY: ${{ secrets.BLOCKNATIVE_API_KEY }} | |
UNS_API_KEY: ${{ secrets.UNS_API_KEY }} | |
SIMPLE_HASH_API_KEY: ${{ secrets.SIMPLE_HASH_API_KEY }} | |
ZEROX_API_KEY: ${{ secrets.ZEROX_API_KEY }} | |
COMMIT_SHA: ${{ github.sha }} | |
POAP_API_KEY: ${{ secrets.POAP_API_KEY }} | |
DAYLIGHT_API_KEY: ${{ secrets.DAYLIGHT_API_KEY }} | |
USE_MAINNET_FORK: true | |
- name: Upload build asset | |
if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: extension-builds-fork-${{ github.event.number || github.event.head_commit.id }} | |
path: dist/*.zip | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Read .nvmrc | |
run: echo "NVMRC=$(cat ./.nvmrc)" >> $GITHUB_OUTPUT | |
id: nvm | |
- name: Use Node + Yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ steps.nvm.outputs.NVMRC }}" | |
cache: "yarn" | |
- run: yarn install --frozen-lockfile | |
- run: yarn test | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Read .nvmrc | |
run: echo "NVMRC=$(cat ./.nvmrc)" >> $GITHUB_OUTPUT | |
id: nvm | |
- name: Use Node + Yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ steps.nvm.outputs.NVMRC }}" | |
cache: "yarn" | |
- run: yarn install --frozen-lockfile | |
- run: yarn install --frozen-lockfile | |
working-directory: .github/workflows/pledge-signer-sync | |
- run: yarn install --frozen-lockfile | |
working-directory: scripts/key-generation | |
- run: yarn install --frozen-lockfile | |
working-directory: ci | |
- run: yarn lint | |
detect-if-flag-changed: | |
runs-on: ubuntu-latest | |
outputs: | |
path-filter: ${{ steps.filter.outputs.path-filter }} | |
steps: | |
- uses: actions/checkout@v3 | |
if: github.event_name == 'pull_request' | |
- uses: dorny/paths-filter@v2 | |
if: github.event_name == 'pull_request' | |
id: filter | |
with: | |
filters: | | |
path-filter: | |
- '.env.defaults' | |
e2e-tests: | |
needs: [build, detect-if-flag-changed] | |
if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
env: | |
# https://playwright.dev/docs/service-workers-experimental | |
PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS: 1 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Read .nvmrc | |
run: echo "NVMRC=$(cat ./.nvmrc)" >> $GITHUB_OUTPUT | |
id: nvm | |
- name: Use Node + Yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ steps.nvm.outputs.NVMRC }}" | |
cache: "yarn" | |
- run: yarn install --frozen-lockfile | |
- name: Install Playwright Browsers | |
run: npx playwright install --with-deps chromium | |
- uses: actions/download-artifact@v4 | |
with: | |
name: extension-builds-${{ github.event.number || github.event.head_commit.id }} | |
- name: Extract extension | |
run: unzip -o chrome.zip -d dist/chrome | |
# Some tests that we have configured in the `e2e-tests` folder may require | |
# spending funds. Although they're desined to not spend much, with | |
# frequent execution that can accumulate. We don't want to execute such | |
# tests on every PR update. We'll tag those tests with the `@expensive` | |
# tag. | |
- name: Run free Playwright tests | |
env: | |
E2E_TEST_ONLY_WALLET_JSON_BODY: ${{ secrets.E2E_TEST_ONLY_WALLET_JSON_BODY }} | |
E2E_TEST_ONLY_WALLET_JSON_PASSWORD: ${{ secrets.E2E_TEST_ONLY_WALLET_JSON_PASSWORD }} | |
run: xvfb-run yarn e2e:regular | |
#env: | |
# DEBUG: pw:api* | |
- name: Run costing Playwright tests | |
if: | | |
github.ref == 'refs/heads/main' | |
|| contains(github.head_ref, 'e2e') | |
|| needs.detect-if-flag-changed.outputs.path-filter == 'true' | |
env: | |
TESTNET_TEST_WALLET_JSON_BODY: ${{ secrets.TEST_WALLET_JSON_BODY }} | |
TESTNET_TEST_WALLET_JSON_PASSWORD: ${{ secrets.TEST_WALLET_JSON_PASSWORD }} | |
run: xvfb-run yarn e2e:testnet | |
- uses: actions/upload-artifact@v4 | |
if: ${{ failure() || cancelled() }} | |
with: | |
name: debug-output | |
path: | | |
test-results/ | |
#videos/ | |
retention-days: 30 | |
e2e-tests-fork: | |
if: | | |
github.ref == 'refs/heads/main' | |
|| contains(github.head_ref, 'e2e') | |
|| needs.detect-if-flag-changed.outputs.path-filter == 'true' | |
needs: [build, detect-if-flag-changed] | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
env: | |
# https://playwright.dev/docs/service-workers-experimental | |
PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS: 1 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Read .nvmrc | |
run: echo "NVMRC=$(cat ./.nvmrc)" >> $GITHUB_OUTPUT | |
id: nvm | |
- name: Use Node + Yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ steps.nvm.outputs.NVMRC }}" | |
cache: "yarn" | |
- run: yarn install --frozen-lockfile | |
- name: Install Playwright Browsers | |
run: npx playwright install --with-deps chromium | |
- uses: actions/download-artifact@v4 | |
with: | |
name: extension-builds-fork-${{ github.event.number || github.event.head_commit.id }} | |
- name: Extract extension | |
run: unzip -o chrome-fork.zip -d dist/chrome | |
- name: Install Foundry | |
uses: foundry-rs/foundry-toolchain@v1 | |
with: | |
cache: false | |
- name: Restore Anvil cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: /home/runner/.foundry/cache | |
key: anvil-21802314-${{ github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
anvil-21802314-${{ github.ref_name }}-${{ github.sha }} | |
anvil-21802314-${{ github.ref_name }}- | |
anvil-21802314- | |
- name: Run Anvil | |
env: | |
CHAIN_API_URL: https://eth-mainnet.g.alchemy.com/v2/${{ secrets.DEV_ALCHEMY_API_KEY }} | |
MAINNET_FORK_CHAIN_ID: 1337 | |
# We're using a fixed block number as a start of the fork to get | |
# consistent behavior in tests. The `21802314` block is a block at | |
# which the state of the chain allows the tests to pass | |
FORKING_BLOCK: 21802314 | |
run: | | |
anvil -q --chain-id $MAINNET_FORK_CHAIN_ID --port 8545 \ | |
--fork-block-number $FORKING_BLOCK --fork-url $CHAIN_API_URL \ | |
--preserve-historical-states --fork-chain-id 1 \ | |
--gas-limit 65000000 & | |
sleep 10 | |
- name: Run Playwright tests designed for fork | |
env: | |
FORK_TEST_WALLET_JSON_BODY: ${{ secrets.TEST_WALLET_JSON_BODY }} | |
FORK_TEST_WALLET_JSON_PASSWORD: ${{ secrets.TEST_WALLET_JSON_PASSWORD }} | |
USE_MAINNET_FORK: true | |
run: xvfb-run yarn e2e:fork | |
- uses: actions/upload-artifact@v4 | |
if: ${{ failure() || cancelled() }} | |
with: | |
name: fork-debug-output | |
path: | | |
test-results/ | |
#videos/ | |
retention-days: 30 | |
# Wait for anvil to finish and save its cache to disk | |
- name: Stop Anvil | |
if: ${{ !cancelled() }} | |
run: sh ./ci/stop-node.sh | |
- name: Save Anvil Cache | |
uses: actions/cache/save@v3 | |
# We want to save the cache even if the tests failed. Without the cache | |
# the tests almost always fail, so without `if: always()` we would have | |
# problem with creating the first cache. | |
if: always() | |
with: | |
path: /home/runner/.foundry/cache | |
key: anvil-21802314-${{ github.ref_name }}-${{ github.sha }} |