From 0f662c293e08d8c4bed76f266e602d82c237b800 Mon Sep 17 00:00:00 2001 From: Fityan <63894003+fityannugroho@users.noreply.github.com> Date: Sun, 11 Aug 2024 13:50:33 +0700 Subject: [PATCH] ci: add MongoDB support and update database configurations --- .github/workflows/tests.yml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 22306f8..9d50b37 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 }} @@ -47,6 +58,9 @@ 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: >- @@ -54,10 +68,6 @@ jobs: --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 @@ -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