Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #5

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Frontend/Backend pipeline
run-name: Frontend/Backend pipeline
on: [push]
jobs:
fe-pipeline:
name: Frontend Pipeline
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend/core
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Cache node_modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-fe-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Install dependencies
run: npm install
- name: Lint
run: npm run lint
- name: Compile
run: npm run tsc
- name: Test
run: npm run test
- name: Build
run: npm run build
be-pipeline:
name: Backend Pipeline
runs-on: ubuntu-latest
env:
AUTH_SECRET: testsecret
AUTH_SUGAR: testsugar
DATABASE_USERNAME: root
DATABASE_PASSWORD: root
DATABASE_HOST: localhost
NODE_ENV: test
defaults:
run:
working-directory: ./api
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Cache node_modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-be-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: MySQL
run: which mysql
- name: Install dependencies
run: npm install
- name: Lint
run: npm run lint
- name: Compile
run: npm run tsc
- name: Build
run: npm run build
- name: Test
run: npm run test
- name: E2E Test - Start Database Service
run: sudo systemctl start mysql.service
- name: E2E Test - Setup Database & Run
run: |
npm run db:test:create
npm run db:test:setup
npm run test:e2e
9 changes: 7 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:e2e": "NODE_ENV=test jest --config ./test/jest-e2e.json --detectOpenHandles",
"typeorm": "typeorm-ts-node-commonjs",
"migration:create": "typeorm-ts-node-commonjs migration:create",
"migration:run": "typeorm-ts-node-commonjs migration:run -d src/db/config.ts",
"migration:revert": "typeorm-ts-node-commonjs migration:revert -d src/db/config.ts",
"db:migrate": "ts-node src/db/cli/index.ts migrate",
"db:seed": "ts-node src/db/cli/index.ts seed",
"db:reset": "ts-node src/db/cli/index.ts reset",
"db:setup": "npm run db:reset && npm run db:migrate && npm run db:seed"
"db:setup": "npm run db:reset && npm run db:seed",
"db:test:create": "NODE_ENV=test ts-node src/db/cli/index.ts create",
"db:test:migrate": "NODE_ENV=test ts-node src/db/cli/index.ts migrate",
"db:test:seed": "NODE_ENV=test ts-node src/db/cli/index.ts seed",
"db:test:reset": "NODE_ENV=test ts-node src/db/cli/index.ts reset",
"db:test:setup": "npm run db:test:reset && npm run db:test:seed"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down
22 changes: 0 additions & 22 deletions api/src/app.controller.spec.ts

This file was deleted.

1 change: 0 additions & 1 deletion api/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class AppController {
@Get()
index(): { version: string } {
const res = this.appService.index();
console.log(res);
return res;
}
}
4 changes: 3 additions & 1 deletion api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import { LoggerModule } from './lib/modules/logger/logger.module';

const config = appConfig();

const envFilePath = [`.env.${process.env.NODE_ENV || 'development'}`];

@Module({
imports: [
ConfigModule.forRoot({
load: [appConfig],
envFilePath: ['.env.development.local', '.env.development'],
envFilePath,
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.valid('development', 'production', 'test', 'provision')
Expand Down
40 changes: 28 additions & 12 deletions api/src/db/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
import { DataSource } from 'typeorm';
import { NestFactory } from '@nestjs/core';
import { INestApplication } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { AppModule } from '../../app.module';
import { AppDataSource } from '../config';
import { AppDataSource, RootDBDataSource } from '../config';
import { seed } from './seeds';
import { LoggerService } from '../../lib/modules/logger/logger.service';
import { Logger } from '../../lib/modules/logger/logger.service';
import { AppModule } from '../../app.module';

interface Logger {
interface ILogger {
info(...msg: any[]);
debug(...msg: any[]);
error(...msg: any[]);
}

type Context = {
dataSource: DataSource;
logger: Logger;
app: INestApplication<any>;
logger: ILogger;
appFactory: () => Promise<INestApplication>;
};

const commands: { [key: string]: (ctx: Context) => Promise<void> } = {
create: async ({ dataSource, logger }: Context) => {
logger.info('create database: ', dataSource.options.database);
await RootDBDataSource.initialize();
await RootDBDataSource.manager.query(
'create database if not exists ' + dataSource.options.database,
);
await RootDBDataSource.close();
},
reset: async ({ dataSource, logger }: Context) => {
await dataSource.initialize();
logger.info('drop database: ', dataSource.options.database);
await dataSource.dropDatabase();
logger.info('migration run');
await dataSource.runMigrations();
await dataSource.close();
},
migrate: async ({ dataSource, logger }: Context) => {
await dataSource.initialize();
logger.info('migration run');
await dataSource.runMigrations();
await dataSource.close();
},
seed: async (context: Context) => {
const { dataSource } = context;
await dataSource.initialize();
await seed(context);
await dataSource.close();
},
seed,
};

const main = async (command: keyof typeof commands) => {
const app = await NestFactory.create(AppModule);
const logger = app.get(LoggerService).logger;
const appFactory = () => NestFactory.create(AppModule);
const logger = new Logger({ level: 'info' });

try {
logger.info(`start command: ${command}`);
await AppDataSource.initialize();
const cmd = commands[command];
if (!cmd) {
logger.error(`${cmd} is undefined`);
logger.info(`${Object.keys(commands).join(', ')} is available.`);
return;
}

await cmd({ app, dataSource: AppDataSource, logger } as Context);
await cmd({ appFactory, dataSource: AppDataSource, logger } as Context);
logger.info(`end command.`);
process.exit();
} catch (e) {
Expand Down
Loading
Loading