Skip to content

Commit f70b244

Browse files
committed
Add GitHub Workflow Example
Disabled testing on FireFox and Safari to get a low-key GitHub CI setup.
1 parent 59f4f43 commit f70b244

File tree

7 files changed

+110
-27
lines changed

7 files changed

+110
-27
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
NEXT_PUBLIC_TESTNET_WALLET_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
2+
FORK_BLOCK_NUMBER=16391695
3+
FORK_URL=https://eth-archival-rpc.gateway.pokt.network

.github/workflows/ci.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Continuous Integration
2+
3+
env:
4+
FOUNDRY_CACHE_PATH: ${{ github.workspace }}/.foundry/cache
5+
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/ms-playwright
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
branches: [main]
12+
13+
jobs:
14+
pipeline:
15+
runs-on: ubuntu-latest
16+
steps:
17+
# Install deps
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-node@v3
20+
with:
21+
cache: npm
22+
node-version: 18
23+
- uses: foundry-rs/foundry-toolchain@v1
24+
with:
25+
version: nightly
26+
- run: npm ci
27+
28+
# Playwright caching
29+
# For Playwright it's wise to cache the browsers on the
30+
# OS used + the installed Playwright version.
31+
# We need to find the version ourselves though...
32+
# https://playwright.dev/docs/ci#caching-browsers
33+
- run: |
34+
echo "PLAYWRIGHT_VERSION=$(node -e "process.stdout.write(require('@playwright/test/package.json').version)")" >> $GITHUB_OUTPUT
35+
id: playwright-version
36+
- uses: actions/cache@v3
37+
id: playwright-cache
38+
with:
39+
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.PLAYWRIGHT_VERSION }}
40+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
41+
- run: npm run e2e install
42+
if: steps.playwright-cache.outputs.cache-hit != 'true'
43+
44+
# Foundry's `anvil` caches things as well. Notably: testnet forks!
45+
- uses: actions/cache@v3
46+
with:
47+
key: ${{ runner.os }}-foundry
48+
path: ${{ env.FOUNDRY_CACHE_PATH }}
49+
50+
# Run CI
51+
- run: npm run lint
52+
- run: npm run e2e test
53+
- run: npm run build

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ Requirements: recent-ish [`node`](https://nodejs.org/), `anvil` from [Foundry](h
1212

1313
- Run `npm install`
1414
- Run `npm run e2e test` or see it live (it's _fast_)
15-
`npm run e2e test --headed`
15+
`npm run e2e test -- --headed`
1616

1717
Note: you might need to install the Playwright browsers with
1818
`npx playwright install`
19+
20+
## GitHub Workflow
21+
22+
An example GitHub workflow has been implemented in [`.github/workflows/ci.yaml`](https://github.com/re-nft/dapp-e2e-example/blob/main/.github/workflows/ci.yaml)

package-lock.json

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"wagmi": "^0.9.0"
1919
},
2020
"devDependencies": {
21+
"@next/env": "^13.1.1",
2122
"@playwright/test": "^1.29.2",
2223
"@types/node": "^17.0.35",
2324
"@types/react": "^18.0.9",

pages/_app.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { providers, Wallet } from 'ethers';
1414

1515
const TESTNET_URL =
1616
process.env.NEXT_PUBLIC_TESTNET_URL || 'http://localhost:8545';
17-
const TESTNET_WALLET_KEY =
18-
process.env.NEXT_PUBLIC_TESTNET_WALLET_KEY || undefined;
17+
const TESTNET_WALLET_KEY = process.env.NEXT_PUBLIC_TESTNET_WALLET_KEY;
1918

2019
const signer = TESTNET_WALLET_KEY
2120
? new Wallet(TESTNET_WALLET_KEY, new providers.JsonRpcProvider(TESTNET_URL))

playwright.config.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { devices } from '@playwright/test';
3+
import { loadEnvConfig } from '@next/env';
34

4-
/**
5-
* Read environment variables from file.
6-
* https://github.com/motdotla/dotenv
7-
*/
8-
// require('dotenv').config();
5+
// The Playwright config doesn't like @next/env's Env type.
6+
const env: Record<string, string> = Object.entries(
7+
loadEnvConfig(process.cwd()).combinedEnv
8+
).reduce(
9+
(env, [key, value]) => ({ ...env, ...(value && { [key]: value }) }),
10+
{}
11+
);
912

1013
/**
1114
* See https://playwright.dev/docs/test-configuration.
@@ -51,19 +54,19 @@ const config: PlaywrightTestConfig = {
5154
},
5255
},
5356

54-
{
55-
name: 'firefox',
56-
use: {
57-
...devices['Desktop Firefox'],
58-
},
59-
},
57+
// {
58+
// name: 'firefox',
59+
// use: {
60+
// ...devices['Desktop Firefox'],
61+
// },
62+
// },
6063

61-
{
62-
name: 'webkit',
63-
use: {
64-
...devices['Desktop Safari'],
65-
},
66-
},
64+
// {
65+
// name: 'webkit',
66+
// use: {
67+
// ...devices['Desktop Safari'],
68+
// },
69+
// },
6770

6871
/* Test against mobile viewports. */
6972
// {
@@ -100,11 +103,17 @@ const config: PlaywrightTestConfig = {
100103
/* Run your local dev server before starting the tests */
101104
webServer: [
102105
{
103-
command: 'anvil',
106+
command: [
107+
`anvil`,
108+
`--fork-block-number=${env.FORK_BLOCK_NUMBER}`,
109+
`--fork-url=${env.FORK_URL}`,
110+
].join(' '),
111+
env,
104112
port: 8545,
105113
},
106114
{
107115
command: 'npm run dev',
116+
env,
108117
port: 3000,
109118
},
110119
],

0 commit comments

Comments
 (0)