-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (147 loc) · 5.99 KB
/
build-test.yml
File metadata and controls
155 lines (147 loc) · 5.99 KB
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
146
147
148
149
150
151
152
153
154
155
name: Build and Test
on:
pull_request:
jobs:
unit-test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: 'Install Node'
uses: actions/setup-node@v4
with:
node-version: '22.x'
- uses: pnpm/action-setup@v4
with:
version: latest
run_install: |
- recursive: true
args: [--frozen-lockfile]
- args: [--global, gulp, prettier, vitest]
- name: 'Generate prisma client'
run: pnpm prisma:generate
- name: 'Run Unit Tests'
run: pnpm test:ci
- name: 'Report Coverage'
if: always()
uses: davelosert/vitest-coverage-report-action@v2
- name: 'Lint Code'
run: pnpm lint
test-e2e:
runs-on: ubuntu-latest
needs: unit-test
steps:
- uses: actions/checkout@v4
- name: 'Install Docker'
run: |
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- name: 'Set up Node.js'
uses: actions/setup-node@v4
with:
node-version: '22.x'
- uses: pnpm/action-setup@v4
with:
version: latest
- name: 'Install Dependencies'
run: |
pnpm install --frozen-lockfile
- name: 'Install Playwright Browsers'
run: pnpm exec playwright install
- name: 'Create Docker network'
run: docker network create test-network
- name: 'Set up test database'
run: |
docker run --name test-db -e POSTGRES_PASSWORD=${{ secrets.TEST_DB_PASSWORD }} -e POSTGRES_DB=forvoyez -p 5432:5432 --network test-network -d postgres
docker run --link test-db:postgres --network test-network --rm postgres sh -c 'until pg_isready -h postgres -U postgres; do sleep 1; done;'
- name: 'Run prisma db migrate'
run: |
docker run --rm --network test-network -v $(pwd):/app -w /app -e DATABASE_URL=postgresql://postgres:${{ secrets.TEST_DB_PASSWORD }}@test-db:5432/forvoyez node:22 sh -c "npm install -g pnpm && pnpm run prisma:migrate && pnpm run prisma:seed"
- name: Setup Docker Cache
uses: docker/setup-buildx-action@v3
with:
driver: docker
config-inline: |
[cache.from]
type=gha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Just Build
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true # Charge l'image dans le Docker daemon local
cache-from: type=gha
cache-to: type=gha,mode=max
tags: forvoyez:test
build-args: NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
- name: 'Start Docker Container'
run: |
docker run -d --name forvoyez-container -p 3000:3000 \
-e NEXT_PUBLIC_URL=${{ secrets.NEXT_PUBLIC_URL }} \
-e NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }} \
-e CLERK_SECRET_KEY=${{ secrets.CLERK_SECRET_KEY }} \
-e NEXT_PUBLIC_CLERK_SIGN_IN_URL=${{ secrets.NEXT_PUBLIC_CLERK_SIGN_IN_URL }} \
-e NEXT_PUBLIC_CLERK_SIGN_UP_URL=${{ secrets.NEXT_PUBLIC_CLERK_SIGN_UP_URL }} \
-e NEXT_PUBLIC_CLERK_SIGN_OUT_URL=${{ secrets.NEXT_PUBLIC_CLERK_SIGN_OUT_URL }} \
-e MAILGUN_API_KEY=${{ secrets.MAILGUN_API_KEY }} \
-e MAILGUN_API_URL=${{ secrets.MAILGUN_API_URL }} \
-e MAILGUN_PUBLIC_KEY=${{ secrets.MAILGUN_PUBLIC_KEY }} \
-e MAILGUN_DOMAIN=${{ secrets.MAILGUN_DOMAIN }} \
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \
-e LEMON_SQUEEZY_API_KEY=${{ secrets.LEMON_SQUEEZY_API_KEY }} \
-e LEMON_SQUEEZY_STORE_ID=${{ secrets.LEMON_SQUEEZY_STORE_ID }} \
-e LEMON_SQUEEZY_WEBHOOK_SECRET=${{ secrets.LEMON_SQUEEZY_WEBHOOK_SECRET }} \
-e DATABASE_URL=postgresql://postgres:${{ secrets.TEST_DB_PASSWORD }}@test-db:5432/forvoyez \
--network test-network \
forvoyez:test
- name: 'Wait for the application to be ready'
run: |
echo "Waiting for the application to be ready..."
end=$((SECONDS+30))
while [ $SECONDS -lt $end ]; do
if curl -s http://localhost:3000 > /dev/null; then
echo "Application is up!"
exit 0
fi
echo "Waiting for the application to be up..."
sleep 5
done
echo "Application did not start in time"
docker logs forvoyez-container
exit 1
- name: 'Check Database Connection'
run: |
docker run --rm --network test-network -v $(pwd):/app -w /app -e DATABASE_URL=postgresql://postgres:${{ secrets.TEST_DB_PASSWORD }}@test-db:5432/forvoyez node:22 sh -c "npm install -g pnpm && node check-db-connection.js"
- name: 'Run E2E Tests'
run: pnpm test:e2e:general
env:
NEXT_PUBLIC_URL: http://localhost:3000
TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
TEST_EMAIL_SUB: ${{ secrets.TEST_EMAIL_SUB }}
TEST_PASSWORD_SUB: ${{ secrets.TEST_PASSWORD_SUB }}
ENABLE_TEST_LOGS: ${{ secrets.ENABLE_TEST_LOGS }}
CLERK_FRONTEND_API: ${{ secrets.CLERK_FRONTEND_API }}
- name: 'Capture Docker Logs'
if: always()
run: |
docker logs forvoyez-container > docker-logs.txt 2>&1
- name: 'Upload Test Artifacts'
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-artifacts
path: |
test-results
docker-logs.txt
- name: 'Stop and remove Docker Containers'
run: |
docker stop forvoyez-container
docker rm forvoyez-container
docker stop test-db
docker rm test-db