From 5f016fe64a87ae5f974a4af844b168111698602e Mon Sep 17 00:00:00 2001 From: jspark2000 Date: Fri, 1 Mar 2024 09:07:27 +0000 Subject: [PATCH] feat: apply ci pipeline --- .github/workflows/CI-backend.yaml | 129 ++++++++++++++++++ .github/workflows/CI-frontend.yaml | 97 +++++++++++++ .github/workflows/CI-infra.yaml | 63 +++++++++ .prettierignore | 3 +- backend/app/src/app.controller.spec.ts | 2 +- .../auth/src/jwt/jwt-auth.service.spec.ts | 0 .../libs/auth/src/role/roles.service.spec.ts | 0 backend/package.json | 3 +- frontend/package.json | 1 + package.json | 1 + 10 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/CI-backend.yaml create mode 100644 .github/workflows/CI-frontend.yaml create mode 100644 .github/workflows/CI-infra.yaml delete mode 100644 backend/libs/auth/src/jwt/jwt-auth.service.spec.ts delete mode 100644 backend/libs/auth/src/role/roles.service.spec.ts diff --git a/.github/workflows/CI-backend.yaml b/.github/workflows/CI-backend.yaml new file mode 100644 index 0000000..04d8417 --- /dev/null +++ b/.github/workflows/CI-backend.yaml @@ -0,0 +1,129 @@ +name: CI-Backend + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + paths: + - 'backend/**' + + push: + branches: + - main + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Generate Prisma Client + run: pnpm --filter backend exec prisma generate + + - name: Build Backend + run: | + pnpm --filter backend build + + - name: Cache dist + uses: actions/cache@v4 + with: + path: ./*/dist + key: ${{ matrix.os }}-node-v${{ matrix.node }}-${{ github.sha }} + + lint: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Lint pull request title + if: ${{ github.event_name == 'pull_request' }} + run: echo "${{ github.event.pull_request.title }}" | pnpm commitlint --verbose + + - name: Check style + run: pnpm --filter backend format:check + + - name: Lint + run: pnpm --filter backend lint + + test: + runs-on: ${{ matrix.os }} + + env: + DATABASE_URL: postgresql://postgres:1234@localhost:5432/royals?schema=public + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + services: + postgres: + image: postgres:15-alpine + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 1234 + POSTGRES_DB: royals + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Check Prisma Migration + run: | + pnpm --filter backend exec prisma migrate diff \ + --from-migrations ./prisma/migrations \ + --to-schema-datamodel ./prisma/schema.prisma \ + --shadow-database-url ${{ env.DATABASE_URL }} \ + --exit-code || + echo "::error::Prisma migration is not up to date. Please run `pnpm prisma migrate dev` locally and commit the changes." + + - name: Migrate Prisma + run: pnpm --filter backend exec prisma migrate reset --force + + - name: Check types in Typescript (Backend) + run: pnpm --filter backend exec tsc --noEmit + + - name: Test + run: pnpm --filter backend test diff --git a/.github/workflows/CI-frontend.yaml b/.github/workflows/CI-frontend.yaml new file mode 100644 index 0000000..c107582 --- /dev/null +++ b/.github/workflows/CI-frontend.yaml @@ -0,0 +1,97 @@ +name: CI-Frontend + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + paths: + - 'frontend/**' + + push: + branches: + - main + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build Frontend + run: pnpm --filter frontend build + + - name: Cache dist + uses: actions/cache@v4 + with: + path: ./*/dist + key: ${{ matrix.os }}-node-v${{ matrix.node }}-${{ github.sha }} + + lint: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Lint pull request title + if: ${{ github.event_name == 'pull_request' }} + run: echo "${{ github.event.pull_request.title }}" | pnpm commitlint --verbose + + - name: Check style + run: pnpm --filter frontend format:check + + - name: Lint + run: pnpm --filter frontend lint + + test: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Check types in Typescript + run: pnpm --filter frontend exec tsc --noEmit diff --git a/.github/workflows/CI-infra.yaml b/.github/workflows/CI-infra.yaml new file mode 100644 index 0000000..90020cf --- /dev/null +++ b/.github/workflows/CI-infra.yaml @@ -0,0 +1,63 @@ +name: CI-Infra + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + paths: + - 'aws/**' + - 'backend/**' + + push: + branches: + - main + +permissions: + id-token: write + contents: read + +env: + AWS_REGION: ap-northeast-2 + +jobs: + validation: + name: validate terraform + runs-on: ubuntu-latest + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE }} + aws-region: ${{ env.AWS_REGION }} + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.5.2 + + - name: Terraform Init + working-directory: ./aws + run: terraform init + + - name: Terraform Validation + working-directory: ./aws + run: terraform validate + + docker-build: + name: build docker image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build image + uses: docker/build-push-action@v5 + with: + file: ./backend/Dockerfile + push: false + tags: skku-royals/api:latest diff --git a/.prettierignore b/.prettierignore index 39a3a48..8a6f04a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,4 +3,5 @@ node_modules/ *.md pnpm-lock.yaml .pnpm-store/ -thunder-tests \ No newline at end of file +.next/ +components.json diff --git a/backend/app/src/app.controller.spec.ts b/backend/app/src/app.controller.spec.ts index 485f0c2..e5f72cf 100644 --- a/backend/app/src/app.controller.spec.ts +++ b/backend/app/src/app.controller.spec.ts @@ -23,7 +23,7 @@ describe('AppController', () => { describe('root', () => { it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!') + expect(appController.healthCheck()).toBe('Hello World!') }) }) }) diff --git a/backend/libs/auth/src/jwt/jwt-auth.service.spec.ts b/backend/libs/auth/src/jwt/jwt-auth.service.spec.ts deleted file mode 100644 index e69de29..0000000 diff --git a/backend/libs/auth/src/role/roles.service.spec.ts b/backend/libs/auth/src/role/roles.service.spec.ts deleted file mode 100644 index e69de29..0000000 diff --git a/backend/package.json b/backend/package.json index 5ba7cda..2a25f50 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,11 +5,12 @@ "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "format:check": "prettier --check .", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "lint": "eslint \"{src,apps,libs}/**/*.ts\" --fix", "test": "vitest run", "test:cov": "vitest run --coverage" }, diff --git a/frontend/package.json b/frontend/package.json index 03f6dc6..d612c97 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,6 +7,7 @@ "build": "next build", "start": "next start", "lint": "next lint", + "format:check": "prettier --check .", "storybook": "storybook dev -p 6006", "build-storybook": "storybook build" }, diff --git a/package.json b/package.json index ea73a08..93750ef 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "scripts": { "lint": "eslint . --ext .js,.ts,.jsx,.tsx", "format": "prettier --write .", + "format:check": "prettier --check .", "setup-minio": "ts-node scripts/setup-minio.ts" }, "packageManager": "pnpm@8.14.1",