-
Notifications
You must be signed in to change notification settings - Fork 7
146 lines (126 loc) · 4.95 KB
/
e2e-tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: E2E Tests
on:
push:
branches:
- develop
pull_request:
jobs:
playwright:
timeout-minutes: 30
runs-on: ubuntu-latest
environment: dev
steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout@v3
# Set up the required Node.js version
- name: Set up node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
# Create an environment file with sensitive information
- name: Create env file
working-directory: ./docker
run: echo NEXT_PUBLIC_ALCHEMY_TESTING_API_KEY=${{ secrets.NEXT_PUBLIC_ALCHEMY_TESTING_API_KEY }} >> .env.tests.local
# Set up Docker Buildx for building Docker images with cache support
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Cache Docker layers for the blockchain service
- name: Cache Docker layers for blockchain
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-blockchain
key: ${{ runner.os }}-buildx-blockchain-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-blockchain-
# Build the Docker image for the blockchain service using Buildx and cache
- name: Build Docker image for blockchain
uses: docker/build-push-action@v4
with:
context: docker/blockchain
file: docker/blockchain/Dockerfile
load: true
tags: blockchain:latest
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache-blockchain
cache-to: type=local,dest=/tmp/.buildx-cache-blockchain,mode=max
# Cache Docker layers for the webapp service
- name: Cache Docker layers for webapp
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-webapp
key: ${{ runner.os }}-buildx-webapp-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-webapp-
# Build the Docker image for the webapp service using Buildx and cache
- name: Build Docker image for webapp
uses: docker/build-push-action@v4
with:
context: .
file: docker/webapp/Dockerfile
load: true
tags: webapp:latest
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache-webapp
cache-to: type=local,dest=/tmp/.buildx-cache-webapp,mode=max
# Run the blockchain Docker container
- name: Run blockchain container
run: docker run -d --name blockchain -p 8545:8545 --env-file ./docker/.env.tests.local blockchain:latest
# Run the webapp Docker container
- name: Run webapp container
run: docker run -d --name webapp -p 3000:3000 -e NEXT_PUBLIC_TESTING_ENVIRONMENT=true -e NEXT_PUBLIC_LOCAL_CHAIN_ID=31337 -e NEXT_PUBLIC_LOCAL_PROVIDER_URL=http://0.0.0.0:8545 webapp:latest
# Remove existing package.json and package-lock.json, then create a new package.json
- name: remove package.json
run: |
rm package.json
rm package-lock.json
npm init -y
# Install Node.js dependencies for Playwright
- name: Install Node.js dependencies
run: npm i -D @playwright/test playwright
# Cache Playwright browsers for faster future runs
- name: Cache Playwright Browsers
id: cache-playwright
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/playwright.config.js') }}
restore-keys: |
${{ runner.os }}-playwright-
# Install Playwright dependencies if the cache is hit
- name: Install Playwright Dependencies
if: steps.cache-playwright.outputs.cache-hit == 'true'
run: |
npx playwright install-deps
# Install Playwright browsers and dependencies if the cache is not hit
- name: Install Playwright Browsers and Dependencies
if: steps.cache-playwright.outputs.cache-hit != 'true'
run: |
npx playwright install --with-deps
# Wait for the development server to start before running tests
- name: Wait for Development Server
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:3000'
responseCode: 200
timeout: 300000
# Run Playwright tests
- name: Run Playwright tests
run: npx playwright test
# Upload Playwright report as an artifact
- name: Upload Playwright report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
# Stop and remove Docker containers after tests are completed
- name: Stop containers
if: always()
run: |
docker stop webapp
docker rm webapp
docker stop blockchain
docker rm blockchain