diff --git a/.env b/.env index 8e1c7311..23d45e62 100644 --- a/.env +++ b/.env @@ -1,31 +1,31 @@ DB=pg DB_NAME=lucid -MYSQL_HOST=mysql +MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=virk MYSQL_PASSWORD=password -MYSQL_LEGACY_HOST=mysql_legacy +MYSQL_LEGACY_HOST=localhost MYSQL_LEGACY_PORT=3306 MYSQL_LEGACY_USER=virk MYSQL_LEGACY_PASSWORD=password -MYSQL_REPLICA_1_HOST=mysql_replica_1 +MYSQL_REPLICA_1_HOST=localhost MYSQL_REPLICA_1_PORT=3306 MYSQL_REPLICA_1_USER=virk MYSQL_REPLICA_1_PASSWORD=password -MYSQL_REPLICA_2_HOST=mysql_replica_2 +MYSQL_REPLICA_2_HOST=localhost MYSQL_REPLICA_2_PORT=3306 MYSQL_REPLICA_2_USER=virk MYSQL_REPLICA_2_PASSWORD=password -PG_HOST=pg +PG_HOST=localhost PG_PORT=5432 PG_USER=virk PG_PASSWORD=password -MSSQL_SERVER=microsoftsql +MSSQL_SERVER=localhost MSSQL_USER=sa MSSQL_PASSWORD=arandom&233password diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d2f8049..a728bfb9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,12 +2,124 @@ name: test on: - push - pull_request + jobs: - build: + lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'npm' + - run: npm install + - run: npm run lint + + typecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'npm' + - run: npm install + - run: npx tsc + + test-postgres: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [14, 16, 18] + postgres-version: [11, 14] + services: + postgres: + image: postgres:${{ matrix.postgres-version }} + env: + POSTGRES_DB: lucid + POSTGRES_USER: virk + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install + run: npm install + - name: Run Postgres Tests + run: npm run test:pg + + test-mysql: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + mysql: [{ version: '5.7', command: 'mysql_legacy' }, { version: '8.0', command: 'mysql' }] + node-version: [14, 16, 18] + services: + mysql: + image: mysql:${{ matrix.mysql.version }} + env: + MYSQL_DATABASE: lucid + MYSQL_USER: virk + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: password + ports: + - '3306:3306' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install + run: npm install + - name: Run Mysql Tests + run: npm run test:${{ matrix.mysql.command }} + + test-sqlite: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + lib: ['sqlite', 'better_sqlite'] + node-version: [14, 16, 18] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install + run: npm install + - name: Run Sqlite Tests + run: npm run test:${{ matrix.lib }} + + test-mssql: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [14, 16, 18] + services: + mssql: + image: mcr.microsoft.com/mssql/server:2019-latest + env: + SA_PASSWORD: 'arandom&233password' + ACCEPT_EULA: 'Y' + ports: + - '1433:1433' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' - name: Install run: npm install - - name: Run tests - run: npm run test + - name: Run Mssql Tests + run: npm run test:mssql diff --git a/docker-compose-test.yml b/docker-compose-test.yml deleted file mode 100644 index c949d84a..00000000 --- a/docker-compose-test.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.4' -services: - test: - build: - context: . - target: build-deps - links: - - mysql_legacy - - mysql_replica_1 - - mysql_replica_2 - - mysql - - pg - - microsoftsql - command: ['/start.sh'] diff --git a/package.json b/package.json index a08f66a3..4ff60ec6 100644 --- a/package.json +++ b/package.json @@ -16,14 +16,13 @@ "scripts": { "mrm": "mrm --preset=@adonisjs/mrm-preset", "pretest": "npm run lint", - "test:better_sqlite": "cross-env DB=better_sqlite FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", - "test:sqlite": "cross-env DB=sqlite FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", - "test:mysql": "cross-env DB=mysql FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", - "test:mysql_legacy": "cross-env DB=mysql_legacy FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", - "test:mssql": "cross-env DB=mssql FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", - "test:pg": "cross-env DB=pg FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts", + "test:better_sqlite": "sh ./scripts/run-tests.sh better_sqlite", + "test:sqlite": "sh ./scripts/run-tests.sh sqlite", + "test:mysql": "sh ./scripts/run-tests.sh mysql", + "test:mysql_legacy": "sh ./scripts/run-tests.sh mysql_legacy", + "test:mssql": "sh ./scripts/run-tests.sh mssql", + "test:pg": "sh ./scripts/run-tests.sh pg", "test:docker": "npm run test:mysql && npm run test:mysql_legacy && npm run test:pg && npm run test:mssql", - "test": "docker-compose -f docker-compose.yml -f docker-compose-test.yml build && docker-compose -f docker-compose.yml -f docker-compose-test.yml run --rm test && npm run test:sqlite && npm run test:better_sqlite", "lint": "eslint . --ext=.ts", "clean": "del-cli build", "compile": "npm run lint && npm run clean && tsc && npm run copyfiles", diff --git a/Dockerfile b/scripts/Dockerfile similarity index 71% rename from Dockerfile rename to scripts/Dockerfile index 6e0b64fc..957652fe 100644 --- a/Dockerfile +++ b/scripts/Dockerfile @@ -1,10 +1,10 @@ FROM node:16.14.0-alpine as build-deps RUN apk update && apk upgrade && \ - apk add --update git && \ - apk add --update openssh && \ - apk add --update bash && \ - apk add --update wget && \ + apk add --update git && \ + apk add --update openssh && \ + apk add --update bash && \ + apk add --update wget && \ apk add --update g++ make python3 WORKDIR /usr/src/app @@ -17,7 +17,4 @@ RUN chmod +x /wait-for-it.sh COPY . . -COPY ./start.sh /start.sh -RUN chmod +x /start.sh - RUN npm run build diff --git a/docker-compose.yml b/scripts/docker-compose.yml similarity index 99% rename from docker-compose.yml rename to scripts/docker-compose.yml index 68caedab..ce039f38 100644 --- a/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -12,6 +12,7 @@ services: - '3306:3306' expose: - '3306' + mysql_replica_1: platform: linux/x86_64 image: mysql:5.7 @@ -24,6 +25,7 @@ services: - '3304:3306' expose: - '3306' + mysql_replica_2: platform: linux/x86_64 image: mysql:5.7 @@ -36,6 +38,7 @@ services: - '3303:3306' expose: - '3306' + mysql: platform: linux/x86_64 image: mysql:8.0 @@ -49,6 +52,7 @@ services: - '3305:3306' expose: - '3306' + pg: image: postgres:11 environment: @@ -59,7 +63,8 @@ services: - 5432:5432 expose: - '5432' - microsoftsql: + + mssql: image: mcr.microsoft.com/mssql/server:2019-latest ports: - 21433:1433 diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100644 index 00000000..9c1fb49c --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +docker-compose -f ./scripts/docker-compose.yml down + +if [ $1 != "better_sqlite" ] && [ $1 != "sqlite" ]; then + docker-compose -f ./scripts/docker-compose.yml up -d $1 +fi + +DB=$1 FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts diff --git a/start.sh b/start.sh deleted file mode 100644 index 25dbecff..00000000 --- a/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -/wait-for-it.sh -t 30 mysql_legacy:3306 && /wait-for-it.sh -t 30 mysql_replica_1:3306 && /wait-for-it.sh -t 30 mysql_replica_2:3306 && /wait-for-it.sh -t 30 mysql:3306 && /wait-for-it.sh -t 30 pg:5432 && /wait-for-it.sh -t 30 microsoftsql:1433 && npm run test:docker