ci: optimize workflow with reusable setup and parallel jobs #4593
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: Test | |
on: [push] | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/workflows/setup.yaml | |
- name: Get contract addresses | |
run: 'parallel --lb --halt now,success=1,fail=1 ::: \ | |
"pnpm tenv start --no-graph --no-scripts --no-build --exit-after-deploy" \ | |
"pnpm wait-on ./.env.local"' | |
- run: pnpm test:coverage | |
build: | |
runs-on: ubuntu-latest-16-cores | |
strategy: | |
matrix: | |
type: [stateless, stateful] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/workflows/setup.yaml | |
- name: Get contract addresses | |
if: matrix.type == 'stateless' | |
run: 'parallel --lb --halt now,success=1,fail=1 ::: \ | |
"pnpm tenv start --no-graph --no-scripts --no-build --exit-after-deploy" \ | |
"pnpm wait-on ./.env.local"' | |
- name: Build and export | |
run: | | |
if [ "${{ matrix.type }}" = "stateless" ]; then | |
pnpm build:glocal && pnpm export | |
else | |
pnpm build && pnpm export | |
fi | |
- name: Compress build | |
run: tar -czf ${{ matrix.type }}-build.tar.gz out | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.type }}-build | |
path: ${{ matrix.type }}-build.tar.gz | |
compression-level: 0 # Already compressed with gzip | |
stateless: | |
name: stateless (${{matrix.shard}}) | |
needs: build | |
timeout-minutes: 20 | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/workflows/setup.yaml | |
- name: Cache Playwright browsers | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ms-playwright | |
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-playwright- | |
- name: Download build | |
uses: actions/download-artifact@v4 | |
with: | |
name: stateless-build | |
merge-multiple: true | |
- name: Extract build | |
run: tar -xzf stateless-build.tar.gz | |
- name: Install playwright | |
run: pnpm dlx playwright install chromium --with-deps | |
- name: Run tests | |
run: | | |
PLAYWRIGHT_SHARD=${{matrix.shard}} PLAYWRIGHT_TOTAL=${{strategy.job-total}} pnpm e2e:ci --no-build | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: stateless-report-${{matrix.shard}} | |
path: playwright-report/ | |
retention-days: 30 | |
overwrite: true | |
stateful: | |
name: stateful (${{matrix.shard}}) | |
needs: build | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
shard: [1, 2, 3] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/workflows/setup.yaml | |
- run: ./scripts/check-chrome.sh | |
- name: Cache Playwright browsers | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ms-playwright | |
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-playwright- | |
- name: Download build | |
uses: actions/download-artifact@v4 | |
with: | |
name: stateful-build | |
- name: Extract build | |
run: tar -xzf stateful-build.tar.gz | |
- name: Install playwright | |
run: pnpm dlx playwright install chromium --with-deps | |
- name: Run tests | |
run: | | |
parallel --lb --halt now,success=1,fail=1 ::: \ | |
"pnpm wrangle" \ | |
"pnpm wait-on http://127.0.0.1:8788 && npx playwright test --shard=${{matrix.shard}}/${{strategy.job-total}} --project=stateful" | |
env: | |
SECRET_WORDS: ${{ secrets.SECRET_WORDS }} | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: stateful-report-${{matrix.shard}} | |
path: playwright-report/ | |
retention-days: 30 |