Skip to content

Commit

Permalink
ci: test with different databases and Node.js versions (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
fityannugroho authored Aug 10, 2024
1 parent e61a3df commit 20220bc
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 42 deletions.
50 changes: 32 additions & 18 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
name: "Test the PR"
name: Test the PR
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
run_test:
name: "Run tests"
build-and-test:
name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }}
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
node-version: [18, 20] # See supported Node.js release schedule at https://nodejs.org/en/about/releases
db: [postgresql, mysql, mongodb, sqlite]

env:
DB_PROVIDER: ${{ matrix.db }}

steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm ci
- name: Check code formatting
run: npm run lint
- name: Generate Prisma Client
run: npm run prisma:gen
env:
DB_PROVIDER: ${{ vars.DB_PROVIDER || 'mongodb' }}
- name: Build
run: npm run build
- name: Run unit tests
run: npm run test
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install modules
run: npm ci

- name: Check code formatting
run: npm run lint

- name: Generate Prisma Client
run: npm run prisma:gen

- name: Build
run: npm run build

- name: Run unit tests
run: npm run test
107 changes: 83 additions & 24 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,94 @@
name: "Tests the App"
env:
DB_PROVIDER: ${{ vars.DB_PROVIDER }}
DB_URL: ${{ secrets.DB_URL }}
name: Tests the App

on:
push:
branches:
- main
workflow_dispatch:

jobs:
run_test:
name: "Run tests"
build-and-test:
name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }}
runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
node-version: [18, 20]
db: [postgresql, mysql]
include:
- db: postgresql
db-image: postgres:14
db-port: 5432
db-username: postgres
db-options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
- db: mysql
db-image: mysql:8
db-port: 3306
db-username: root
db-options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
services:
db:
image: ${{ matrix.db-image }}
env:
POSTGRES_USER: ${{ matrix.db-username }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DB: testdb
MYSQL_ROOT_PASSWORD: rO0t_${{ secrets.DB_PASSWORD }}
MYSQL_DATABASE: testdb
MYSQL_USER: ${{ matrix.db-username }}
MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }}
ports:
- ${{ matrix.db-port }}:${{ matrix.db-port }}
options: ${{ matrix.db-options }}

env:
DB_PROVIDER: ${{ matrix.db }}
DB_URL: ${{ format('{0}://{1}:{2}/{3}', matrix.db, matrix.db-username, secrets.DB_PASSWORD, matrix.db-port, 'testdb') }}

steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm ci
- name: Check code formatting
run: npm run lint
- name: Migrate the database
run: npm run db:migrate
- name: Seed the data
run: npm run db:seed
- name: Build
run: npm run build
- name: Run unit tests
run: npm run test
- name: Run e2e tests
run: npm run test:e2e
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}-${{ matrix.node-version }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}
- name: Install dependencies
run: npm ci

- name: Run linting
run: npm run lint

- name: Run database migrations
run: npm run db:migrate

- name: Run database seed
run: npm run db:seed

- name: Build the app
run: npm run build

- name: Run unit tests
run: npm run test

- name: Run e2e tests
run: npm run test:e2e

0 comments on commit 20220bc

Please sign in to comment.