Merge pull request #1333 from automatisch/backend-tests-ci
feat: Add CI configuration for backend tests
This commit is contained in:
48
.github/workflows/backend.yml
vendored
Normal file
48
.github/workflows/backend.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
name: Automatisch Backend Tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
timeout-minutes: 60
|
||||||
|
runs-on:
|
||||||
|
- ubuntu-latest
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:14.5-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_DB: automatisch_test
|
||||||
|
POSTGRES_USER: automatisch_test_user
|
||||||
|
POSTGRES_PASSWORD: automatisch_test_user_password
|
||||||
|
options: >-
|
||||||
|
--health-cmd "pg_isready -U automatisch_test_user -d automatisch_test"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
redis:
|
||||||
|
image: redis:7.0.4-alpine
|
||||||
|
options: >-
|
||||||
|
--health-cmd "redis-cli ping"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
- name: Install dependencies
|
||||||
|
run: cd packages/backend && yarn
|
||||||
|
- name: Copy .env-example.test file to .env.test
|
||||||
|
run: cd packages/backend && cp .env-example.test .env.test
|
||||||
|
- name: Run tests
|
||||||
|
run: cd packages/backend && yarn test
|
@@ -3,14 +3,12 @@ HOST=localhost
|
|||||||
PROTOCOL=http
|
PROTOCOL=http
|
||||||
PORT=3000
|
PORT=3000
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=debug
|
||||||
WEBHOOK_SECRET_KEY=secret
|
ENCRYPTION_KEY=sample_encryption_key
|
||||||
|
WEBHOOK_SECRET_KEY=sample_webhook_secret_key
|
||||||
|
APP_SECRET_KEY=sample_app_secret_key
|
||||||
|
POSTGRES_HOST=localhost
|
||||||
POSTGRES_DATABASE=automatisch_test
|
POSTGRES_DATABASE=automatisch_test
|
||||||
POSTGRES_PORT=5432
|
POSTGRES_PORT=5432
|
||||||
POSTGRES_HOST=localhost
|
|
||||||
POSTGRES_USERNAME=automatisch_test_user
|
POSTGRES_USERNAME=automatisch_test_user
|
||||||
POSTGRES_PASSWORD=
|
POSTGRES_PASSWORD=automatisch_test_user_password
|
||||||
POSTGRES_ENABLE_SSL=false
|
REDIS_HOST=localhost
|
||||||
ENCRYPTION_KEY=secret
|
|
||||||
APP_SECRET_KEY=secret
|
|
||||||
REDIS_PORT=6379
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
|
@@ -55,6 +55,7 @@ type AppConfig = {
|
|||||||
paddlePublicKey: string;
|
paddlePublicKey: string;
|
||||||
licenseKey: string;
|
licenseKey: string;
|
||||||
sentryDsn: string;
|
sentryDsn: string;
|
||||||
|
CI: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const host = process.env.HOST || 'localhost';
|
const host = process.env.HOST || 'localhost';
|
||||||
@@ -131,6 +132,7 @@ const appConfig: AppConfig = {
|
|||||||
paddlePublicKey: process.env.PADDLE_PUBLIC_KEY,
|
paddlePublicKey: process.env.PADDLE_PUBLIC_KEY,
|
||||||
licenseKey: process.env.LICENSE_KEY,
|
licenseKey: process.env.LICENSE_KEY,
|
||||||
sentryDsn: process.env.SENTRY_DSN,
|
sentryDsn: process.env.SENTRY_DSN,
|
||||||
|
CI: process.env.CI === 'true',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!appConfig.encryptionKey) {
|
if (!appConfig.encryptionKey) {
|
||||||
|
@@ -2,9 +2,13 @@ import './check-env-file';
|
|||||||
import { createDatabaseAndUser } from '../../bin/database/utils';
|
import { createDatabaseAndUser } from '../../bin/database/utils';
|
||||||
import { client as knex } from '../../src/config/database';
|
import { client as knex } from '../../src/config/database';
|
||||||
import logger from '../../src/helpers/logger';
|
import logger from '../../src/helpers/logger';
|
||||||
|
import appConfig from '../../src/config/app';
|
||||||
|
|
||||||
const createAndMigrateDatabase = async () => {
|
const createAndMigrateDatabase = async () => {
|
||||||
|
if (!appConfig.CI) {
|
||||||
await createDatabaseAndUser();
|
await createDatabaseAndUser();
|
||||||
|
}
|
||||||
|
|
||||||
const migrator = knex.migrate;
|
const migrator = knex.migrate;
|
||||||
|
|
||||||
await migrator.latest();
|
await migrator.latest();
|
||||||
|
Reference in New Issue
Block a user