diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1cbd7d..0973f23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,10 @@ -name: CI +name: SQLite CI on: [push, pull_request] jobs: - build: - name: Run Tests + name: Run Tests with SQLite runs-on: ubuntu-latest steps: diff --git a/.github/workflows/postgres-ci.yml b/.github/workflows/postgres-ci.yml new file mode 100644 index 0000000..66804f1 --- /dev/null +++ b/.github/workflows/postgres-ci.yml @@ -0,0 +1,28 @@ +name: PostgreSQL CI + +on: [push, pull_request] + +jobs: + build: + name: Run Tests with PostgreSQL + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Build the docker-compose stack + env: + PG_USER: ci_db_user + PG_PASS: ci_db_pass + run: docker-compose -f docker/docker-compose-ci.yml up -d + - name: Sleep + uses: jakejarvis/wait-action@master + with: + time: '10s' + - name: Check running containers + run: docker ps + - uses: actions/setup-node@v1 + - run: npm install + - name: Run test suite + env: + TEST_POSTGRES: true + run: npm test \ No newline at end of file diff --git a/ci.json b/ci.json new file mode 100644 index 0000000..f6e1c7b --- /dev/null +++ b/ci.json @@ -0,0 +1,65 @@ +{ + "port": 8080, + "mockPort": 8081, + "globalSalt": "testSalt", + "adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b", + "newLeafURLs": ["placeholder"], + "discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook", + "discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook", + "discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook", + "discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/NeuralBlockRejectWebhook", + "neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock", + "behindProxy": true, + "postgres": { + "user": "ci_db_user", + "password": "ci_db_pass", + "host": "localhost", + "port": 5432 + }, + "createDatabaseIfNotExist": true, + "schemaFolder": "./databases", + "dbSchema": "./databases/_sponsorTimes.db.sql", + "privateDBSchema": "./databases/_private.db.sql", + "mode": "test", + "readOnly": false, + "webhooks": [ + { + "url": "http://127.0.0.1:8081/CustomWebhook", + "key": "superSecretKey", + "scopes": [ + "vote.up", + "vote.down" + ] + }, { + "url": "http://127.0.0.1:8081/FailedWebhook", + "key": "superSecretKey", + "scopes": [ + "vote.up", + "vote.down" + ] + }, { + "url": "http://127.0.0.1:8099/WrongPort", + "key": "superSecretKey", + "scopes": [ + "vote.up", + "vote.down" + ] + } + ], + "categoryList": ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "highlight"], + "maxNumberOfActiveWarnings": 3, + "hoursAfterWarningExpires": 24, + "rateLimit": { + "vote": { + "windowMs": 900000, + "max": 20, + "message": "Too many votes, please try again later", + "statusCode": 429 + }, + "view": { + "windowMs": 900000, + "max": 20, + "statusCode": 200 + } + } +} diff --git a/docker/docker-compose-ci.yml b/docker/docker-compose-ci.yml new file mode 100644 index 0000000..acfd112 --- /dev/null +++ b/docker/docker-compose-ci.yml @@ -0,0 +1,9 @@ +version: '3' +services: + postgres: + image: postgres:alpine + environment: + - POSTGRES_USER=${PG_USER} + - POSTGRES_PASSWORD=${PG_PASS} + ports: + - 5432:5432 \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 72099f9..afebd4f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,9 @@ import fs from 'fs'; import {SBSConfig} from "./types/config.model"; const isTestMode = process.env.npm_lifecycle_script === 'ts-node test/test.ts'; -const configFile = isTestMode ? 'test.json' : 'config.json'; +const configFile = process.env.TEST_POSTGRES ? 'ci.json' + : isTestMode ? 'test.json' + : 'config.json'; export const config: SBSConfig = JSON.parse(fs.readFileSync(configFile).toString('utf8')); addDefaults(config, { diff --git a/test/test.ts b/test/test.ts index 8697652..59fd5f0 100644 --- a/test/test.ts +++ b/test/test.ts @@ -23,6 +23,11 @@ async function init() { await initDb(); + const dbMode = config.mysql ? 'mysql' + : config.postgres ? 'postgres' + : 'sqlite' + Logger.info('Database Mode: ' + dbMode) + // Instantiate a Mocha instance. const mocha = new Mocha();