diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc4e84784b..e257ce9515 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,25 +7,67 @@ on: types: [opened, edited, synchronize, reopened] jobs: - build: - name: Build + build-backend: + name: Build Backend runs-on: ubuntu-latest strategy: matrix: - target: [frontend, backend, backend-admin] + target: [client, admin] steps: - uses: actions/checkout@v4 + + - name: Check if source code has changed + uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + shared: &shared + - 'apps/backend/libs/**' + - 'apps/backend/prisma/**' + - 'apps/backend/*.json' + - 'pnpm-lock.yaml' + client: + - *shared + - 'apps/backend/apps/client/**' + admin: + - *shared + - 'apps/backend/apps/admin/**' + - uses: ./.github/actions/setup-pnpm + if: ${{ steps.filter.outputs[matrix.target] == 'true' }} - name: Generate Prisma Client - if: ${{ matrix.target == 'backend' || matrix.target == 'backend-admin' }} + if: ${{ steps.filter.outputs[matrix.target] == 'true' }} run: pnpm --filter="@codedang/backend" exec prisma generate + - name: Build + if: ${{ steps.filter.outputs[matrix.target] == 'true' }} + run: pnpm --filter="@codedang/backend" build ${{ matrix.target }} + + build-frontend: + name: Build Frontend + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Check if source code has changed + uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + frontend: + - 'apps/frontend/**' + - 'pnpm-lock.yaml' + + - uses: ./.github/actions/setup-pnpm + if: steps.filter.outputs.frontend == 'true' + - name: Setup Next.js build cache - if: ${{ matrix.target == 'frontend' }} uses: actions/cache@v4 + if: steps.filter.outputs.frontend == 'true' with: path: apps/frontend/.next/cache key: ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} @@ -33,18 +75,15 @@ jobs: ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}- - name: Load Next.js environment - if: ${{ matrix.target == 'frontend' }} + if: steps.filter.outputs.frontend == 'true' run: | echo "NEXT_PUBLIC_BASEURL=https://stage.codedang.com/api" >> apps/frontend/.env echo "NEXT_PUBLIC_GQL_BASEURL=https://stage.codedang.com/graphql" >> apps/frontend/.env echo "NEXT_URL=https://stage.codedang.com" >> apps/frontend/.env - - name: Build (backend admin) - if: ${{ matrix.target == 'backend-admin' }} - run: pnpm --filter="@codedang/backend" build admin - name: Build - if: ${{ matrix.target != 'backend-admin' }} - run: pnpm --filter="apps/${{ matrix.target }}" build + if: steps.filter.outputs.frontend == 'true' + run: pnpm --filter="@codedang/frontend" build typecheck: name: Typecheck @@ -52,12 +91,24 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Check if source code has changed + uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - 'apps/backend/**' + - uses: ./.github/actions/setup-pnpm + if: steps.filter.outputs.backend == 'true' - name: Generate Prisma Client + if: steps.filter.outputs.backend == 'true' run: pnpm --filter="@codedang/backend" exec prisma generate - name: Check types (backend) # For spec files + if: steps.filter.outputs.backend == 'true' run: pnpm --filter="@codedang/backend" exec tsc --noEmit # Typecheck is not performed for frontend intentionally. @@ -98,8 +149,8 @@ jobs: - name: Lint (Node.js) run: pnpm lint - test: - name: Test + test-backend: + name: Test Backend runs-on: ubuntu-latest env: @@ -118,9 +169,21 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Check if source code has changed + uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - 'apps/backend/**' + - 'pnpm-lock.yaml' + - uses: ./.github/actions/setup-pnpm + if: steps.filter.outputs.backend == 'true' - name: Check Prisma Migration + if: steps.filter.outputs.backend == 'true' run: | pnpm --filter="@codedang/backend" exec prisma migrate diff \ --from-migrations ./prisma/migrations \ @@ -131,7 +194,9 @@ jobs: "Please run 'pnpm prisma migrate dev' locally and commit the changes." && exit 1) - name: Migrate Prisma + if: steps.filter.outputs.backend == 'true' run: pnpm --filter="@codedang/backend" exec prisma migrate reset --force - name: Test - run: pnpm -r test + if: steps.filter.outputs.backend == 'true' + run: pnpm --filter="@codedang/backend" test