Skip to content

Commit

Permalink
ci: add MongoDB support and update database configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
fityannugroho committed Aug 11, 2024
1 parent afcc657 commit 0f662c2
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ jobs:
runs-on: ubuntu-latest

strategy:
# Don't cancel all the jobs if one of them fails
fail-fast: false
matrix:
node-version: [18, 20]
db: [postgresql, mysql]
db: [postgresql, mysql, mongodb]
include:
- db: postgresql
db-image: postgres:14
Expand All @@ -38,6 +37,18 @@ jobs:
--health-timeout=5s
--health-retries=5
- db: mongodb
db-image: mongo:7.0
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 }}
Expand All @@ -47,17 +58,16 @@ jobs:
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

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -78,9 +88,24 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Set DB_URL environment variable
run: |
DB_URL="${{ matrix.db }}://${{ matrix.db-username }}:${{ secrets.DB_PASSWORD }}@localhost:${{ matrix.db-port }}/testdb"
if [ '${{ matrix.db }}' = 'mongodb' ]; then
DB_URL="$DB_URL?replicaSet=rs0"
fi
echo "DB_URL=$DB_URL" >> $GITHUB_ENV
- name: Run linting
run: npm run lint

- name: Initialize MongoDB Replica Set
if: matrix.db == 'mongodb'
run: mongo --eval "rs.initiate()"
env:
MONGO_INITDB_ROOT_USERNAME: ${{ matrix.db-username }}
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }}

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

Expand Down

0 comments on commit 0f662c2

Please sign in to comment.