ci: test with MongoDB #437
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests the App | |
on: | |
# TODO: Remove pull request trigger later | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-and-test: | |
name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
node-version: [18, 20] | |
db: [postgresql, mysql, mongodb] | |
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 | |
- db: mongodb | |
db-image: mongodb/mongodb-community-server:latest | |
db-port: 27017 | |
db-username: root | |
db-options: >- | |
--replSet rs0 | |
--bind_ip localhost | |
--health-cmd="mongo --eval 'db.runCommand({ping: 1})'" | |
--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: ${{ secrets.DB_PASSWORD }} | |
MYSQL_DATABASE: testdb | |
MONGO_INITDB_ROOT_USERNAME: ${{ matrix.db-username }} | |
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
MONGO_INITDB_DATABASE: testdb | |
ports: | |
- ${{ matrix.db-port }}:${{ matrix.db-port }} | |
options: >- | |
--name db | |
--hostname db | |
${{ matrix.db-options }} | |
env: | |
DB_PROVIDER: ${{ matrix.db }} | |
DB_URL: ${{ matrix.db }}://${{ matrix.db-username }}:${{ secrets.DB_PASSWORD }}@localhost:${{ matrix.db-port }}/testdb${{ matrix.db == 'mongodb' && '?replicaSet=rs0' || '' }} | |
steps: | |
- 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 |