From da92f2082d1ee8cbf6d0545743ec399baa138ba2 Mon Sep 17 00:00:00 2001 From: Michael C Date: Wed, 23 Jun 2021 14:48:47 -0400 Subject: [PATCH 1/3] set up postgres CI route uses env flag TEST_POSTGRES since the sqlite test also runs with env flag CI true --- .github/workflows/postgres-ci.yml | 27 +++++++++++++ ci.json | 65 +++++++++++++++++++++++++++++++ docker-compose.yml | 9 +++++ src/config.ts | 4 +- test/test.ts | 6 +++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/postgres-ci.yml create mode 100644 ci.json create mode 100644 docker-compose.yml diff --git a/.github/workflows/postgres-ci.yml b/.github/workflows/postgres-ci.yml new file mode 100644 index 0000000..1a7c8d7 --- /dev/null +++ b/.github/workflows/postgres-ci.yml @@ -0,0 +1,27 @@ +name: Docker Image CI + +on: [push, pull_request] + +jobs: + build: + 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 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-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..acfd112 --- /dev/null +++ b/docker-compose.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..028b85a 100644 --- a/test/test.ts +++ b/test/test.ts @@ -23,6 +23,12 @@ async function init() { await initDb(); + const dbMode = config.mysql ? 'mysql' + : config.postgres ? 'postgres' + : 'sqlite' + // print database mode + console.log('Database Mode: ' + dbMode) + // Instantiate a Mocha instance. const mocha = new Mocha(); From b62db5675ddd296d50de13ea9c12bfc15b4a592e Mon Sep 17 00:00:00 2001 From: Michael C Date: Wed, 23 Jun 2021 15:39:39 -0400 Subject: [PATCH 2/3] update CI names and path move docker-compose to new folder rename action names --- .github/workflows/ci.yml | 5 ++--- .github/workflows/postgres-ci.yml | 5 +++-- docker-compose.yml => docker/docker-compose-ci.yml | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename docker-compose.yml => docker/docker-compose-ci.yml (100%) 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 index 1a7c8d7..66804f1 100644 --- a/.github/workflows/postgres-ci.yml +++ b/.github/workflows/postgres-ci.yml @@ -1,9 +1,10 @@ -name: Docker Image CI +name: PostgreSQL CI on: [push, pull_request] jobs: build: + name: Run Tests with PostgreSQL runs-on: ubuntu-latest steps: @@ -12,7 +13,7 @@ jobs: env: PG_USER: ci_db_user PG_PASS: ci_db_pass - run: docker-compose up -d + run: docker-compose -f docker/docker-compose-ci.yml up -d - name: Sleep uses: jakejarvis/wait-action@master with: diff --git a/docker-compose.yml b/docker/docker-compose-ci.yml similarity index 100% rename from docker-compose.yml rename to docker/docker-compose-ci.yml From 0fbfee8dc89a293e5628f2d384d2ebc45b69a3de Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 24 Jun 2021 00:08:19 -0400 Subject: [PATCH 3/3] Use logger instead of console.log --- test/test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test.ts b/test/test.ts index 028b85a..59fd5f0 100644 --- a/test/test.ts +++ b/test/test.ts @@ -26,8 +26,7 @@ async function init() { const dbMode = config.mysql ? 'mysql' : config.postgres ? 'postgres' : 'sqlite' - // print database mode - console.log('Database Mode: ' + dbMode) + Logger.info('Database Mode: ' + dbMode) // Instantiate a Mocha instance. const mocha = new Mocha();