Skip to content

Commit 20220bc

Browse files
ci: test with different databases and Node.js versions (#392)
1 parent e61a3df commit 20220bc

File tree

2 files changed

+115
-42
lines changed

2 files changed

+115
-42
lines changed

.github/workflows/pr-tests.yml

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
name: "Test the PR"
1+
name: Test the PR
22
on:
33
pull_request:
44
branches:
55
- main
6+
workflow_dispatch:
7+
68
jobs:
7-
run_test:
8-
name: "Run tests"
9+
build-and-test:
10+
name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }}
911
runs-on: ubuntu-latest
1012

1113
strategy:
1214
matrix:
13-
node-version: [18.x, 20.x]
14-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
15+
node-version: [18, 20] # See supported Node.js release schedule at https://nodejs.org/en/about/releases
16+
db: [postgresql, mysql, mongodb, sqlite]
17+
18+
env:
19+
DB_PROVIDER: ${{ matrix.db }}
1520

1621
steps:
17-
- uses: actions/checkout@v3
18-
- name: Install modules
19-
run: npm ci
20-
- name: Check code formatting
21-
run: npm run lint
22-
- name: Generate Prisma Client
23-
run: npm run prisma:gen
24-
env:
25-
DB_PROVIDER: ${{ vars.DB_PROVIDER || 'mongodb' }}
26-
- name: Build
27-
run: npm run build
28-
- name: Run unit tests
29-
run: npm run test
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: ${{ matrix.node-version }}
29+
30+
- name: Install modules
31+
run: npm ci
32+
33+
- name: Check code formatting
34+
run: npm run lint
35+
36+
- name: Generate Prisma Client
37+
run: npm run prisma:gen
38+
39+
- name: Build
40+
run: npm run build
41+
42+
- name: Run unit tests
43+
run: npm run test

.github/workflows/tests.yml

Lines changed: 83 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,94 @@
1-
name: "Tests the App"
2-
env:
3-
DB_PROVIDER: ${{ vars.DB_PROVIDER }}
4-
DB_URL: ${{ secrets.DB_URL }}
1+
name: Tests the App
2+
53
on:
64
push:
75
branches:
86
- main
7+
workflow_dispatch:
8+
99
jobs:
10-
run_test:
11-
name: "Run tests"
10+
build-and-test:
11+
name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }}
1212
runs-on: ubuntu-latest
1313

1414
strategy:
15-
max-parallel: 1
1615
matrix:
17-
node-version: [18.x, 20.x]
18-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
16+
node-version: [18, 20]
17+
db: [postgresql, mysql]
18+
include:
19+
- db: postgresql
20+
db-image: postgres:14
21+
db-port: 5432
22+
db-username: postgres
23+
db-options: >-
24+
--health-cmd="pg_isready -U postgres"
25+
--health-interval=10s
26+
--health-timeout=5s
27+
--health-retries=5
28+
29+
- db: mysql
30+
db-image: mysql:8
31+
db-port: 3306
32+
db-username: root
33+
db-options: >-
34+
--health-cmd="mysqladmin ping --silent"
35+
--health-interval=10s
36+
--health-timeout=5s
37+
--health-retries=5
38+
39+
services:
40+
db:
41+
image: ${{ matrix.db-image }}
42+
env:
43+
POSTGRES_USER: ${{ matrix.db-username }}
44+
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
45+
POSTGRES_DB: testdb
46+
MYSQL_ROOT_PASSWORD: rO0t_${{ secrets.DB_PASSWORD }}
47+
MYSQL_DATABASE: testdb
48+
MYSQL_USER: ${{ matrix.db-username }}
49+
MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }}
50+
ports:
51+
- ${{ matrix.db-port }}:${{ matrix.db-port }}
52+
options: ${{ matrix.db-options }}
53+
54+
env:
55+
DB_PROVIDER: ${{ matrix.db }}
56+
DB_URL: ${{ format('{0}://{1}:{2}/{3}', matrix.db, matrix.db-username, secrets.DB_PASSWORD, matrix.db-port, 'testdb') }}
1957

2058
steps:
21-
- uses: actions/checkout@v3
22-
- name: Install modules
23-
run: npm ci
24-
- name: Check code formatting
25-
run: npm run lint
26-
- name: Migrate the database
27-
run: npm run db:migrate
28-
- name: Seed the data
29-
run: npm run db:seed
30-
- name: Build
31-
run: npm run build
32-
- name: Run unit tests
33-
run: npm run test
34-
- name: Run e2e tests
35-
run: npm run test:e2e
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Node.js
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: ${{ matrix.node-version }}
66+
67+
- name: Cache Node.js modules
68+
uses: actions/cache@v4
69+
with:
70+
path: node_modules
71+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}-${{ matrix.node-version }}
72+
restore-keys: |
73+
${{ runner.os }}-node-${{ matrix.node-version }}
74+
75+
- name: Install dependencies
76+
run: npm ci
77+
78+
- name: Run linting
79+
run: npm run lint
80+
81+
- name: Run database migrations
82+
run: npm run db:migrate
83+
84+
- name: Run database seed
85+
run: npm run db:seed
86+
87+
- name: Build the app
88+
run: npm run build
89+
90+
- name: Run unit tests
91+
run: npm run test
92+
93+
- name: Run e2e tests
94+
run: npm run test:e2e

0 commit comments

Comments
 (0)