diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c09345d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,195 @@ +name: ๐ŸŒฅ๏ธ CI + +on: + push: + pull_request: + branches: [main] + paths-ignore: + - README.md + - docs/** + +jobs: + changes: + name: ๐Ÿ” Detect changes + runs-on: ubuntu-latest + outputs: + nestjs: ${{ steps.filter.outputs.nestjs }} + remix: ${{ steps.filter.outputs.remix }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Check for file changes + uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + nestjs: + - 'apps/nestjs/**' + - 'libs/types/**' + remix: + - 'apps/remix/**' + - 'apps/types/**' + + lint: + name: โฌฃ ESLint + needs: [changes] + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v2.4.0 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: ๐Ÿ“ฅ Install Dependencies + run: pnpm install + + - name: ๐Ÿ”ฌ Lint + run: pnpm lint + + typecheck: + name: สฆ TypeScript + needs: [changes] + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v2.4.0 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: ๐Ÿ“ฅ Install Dependencies + run: pnpm install + + - name: ๐Ÿ”Ž Type check + run: pnpm typecheck + + test: + name: ๐Ÿงช Tests + needs: [changes] + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v2.4.0 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: ๐Ÿ“ฅ Install Dependencies + run: pnpm install + + - name: ๐Ÿงช Run tests + run: pnpm test + + e2e: + name: ๐Ÿ”ฌ E2E Tests + needs: [changes] + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v2.4.0 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: ๐Ÿ“ฅ Install Dependencies + run: pnpm install + + - name: ๐Ÿงช Run tests + run: pnpm test:e2e + + build: + name: ๐Ÿ—๏ธ Build + needs: [changes] + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v2.4.0 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: ๐Ÿ“ฅ Install Dependencies + run: pnpm install + + - name: ๐Ÿ—๏ธ Build + run: pnpm build + + deploy-nestjs: + name: ๐Ÿš€ Deploy NestJS App + needs: [changes, lint, typecheck, test, e2e, build] + if: needs.changes.outputs.nestjs == 'true' && github.ref == 'refs/heads/main' + + runs-on: ubuntu-latest + + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: ๐ŸŽˆ Setup Fly + uses: superfly/flyctl-actions/setup-flyctl@v1.4 + + - name: ๐Ÿš€ Deploy + run: flyctl deploy --config ./apps/nestjs/fly.toml --dockerfile ./apps/nestjs/Dockerfile --remote-only --build-arg COMMIT_SHA=${{ github.sha }} + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + + deploy-remix: + name: ๐Ÿš€ Deploy Remix App + needs: [changes, lint, typecheck, test, e2e, build] + if: needs.changes.outputs.remix == 'true' && github.ref == 'refs/heads/main' + + runs-on: ubuntu-latest + + steps: + - name: ๐Ÿ›Ž๏ธ Checkout repo + uses: actions/checkout@v4 + + - name: ๐ŸŽˆ Setup Fly + uses: superfly/flyctl-actions/setup-flyctl@v1.4 + + - name: ๐Ÿš€ Deploy + run: flyctl deploy --config ./apps/remix/fly.toml --dockerfile ./apps/remix/Dockerfile --remote-only --build-arg COMMIT_SHA=${{ github.sha }} + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index b32b206..0000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - changes: - name: Detect changes - runs-on: ubuntu-latest - outputs: - nestjs: ${{ steps.filter.outputs.nestjs }} - remix: ${{ steps.filter.outputs.remix }} - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Check for file changes - uses: dorny/paths-filter@v2 - id: filter - with: - filters: | - nestjs: - - 'apps/nestjs/**' - - 'libs/types/**' - remix: - - 'apps/remix/**' - - 'apps/types/**' - - validate: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Setup pnpm - uses: pnpm/action-setup@v2.4.0 - with: - version: 8 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: pnpm - - - name: Install Dependencies - run: pnpm install - - - name: Lint - run: pnpm lint - - - name: Test - run: pnpm test - - - name: Build - run: pnpm build - - deploy-nestjs: - name: Deploy NestJS App - needs: [changes, validate] - if: needs.changes.outputs.nestjs == 'true' && github.ref == 'refs/heads/main' - - runs-on: ubuntu-latest - - steps: - - name: โฌ‡๏ธ Checkout repo - uses: actions/checkout@v4 - - - name: ๐ŸŽˆ Setup Fly - uses: superfly/flyctl-actions/setup-flyctl@v1.4 - - - name: ๐Ÿš€ Deploy - run: flyctl deploy --config ./apps/nestjs/fly.toml --dockerfile ./apps/nestjs/Dockerfile --remote-only --build-arg COMMIT_SHA=${{ github.sha }} - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - - deploy-remix: - name: Deploy Remix App - needs: [changes, validate] - if: needs.changes.outputs.remix == 'true' && github.ref == 'refs/heads/main' - - runs-on: ubuntu-latest - - steps: - - name: โฌ‡๏ธ Checkout repo - uses: actions/checkout@v4 - - - name: ๐ŸŽˆ Setup Fly - uses: superfly/flyctl-actions/setup-flyctl@v1.4 - - - name: ๐Ÿš€ Deploy - run: flyctl deploy --config ./apps/remix/fly.toml --dockerfile ./apps/remix/Dockerfile --remote-only --build-arg COMMIT_SHA=${{ github.sha }} - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/README.md b/README.md index e689b27..35bccd0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - [x] manually deploy to fly.io - [x] create CI deployment workflow to fly.io - [x] improve CI deployment workflow to trigger only for changed apps -- [ ] run typecheck, lint, test and build in parallel +- [x] run typecheck, lint, test and build in parallel - [ ] setup tailwindcss in remix - [ ] create shared ui lib - [ ] setup Storybook in shared ui lib @@ -20,6 +20,7 @@ - [x] set unified path aliases for all apps and shared libs (done for `apps/`, because `libs/` probably don't need them anyway) - [x] add unused imports plugin to eslint - [ ] research if it's worth using `turbo` +- [ ] create diagram ## References diff --git a/apps/nestjs/src/app.controller.spec.ts b/apps/nestjs/src/app.controller.spec.ts index 6e2083c..9dc5096 100644 --- a/apps/nestjs/src/app.controller.spec.ts +++ b/apps/nestjs/src/app.controller.spec.ts @@ -2,14 +2,16 @@ import { Test, TestingModule } from '@nestjs/testing' import { AppController } from './app.controller' import { AppService } from './app.service' +import { DogsController } from './dogs/dogs.controller' +import { DogsService } from './dogs/dogs.service' describe('AppController', () => { let appController: AppController beforeEach(async () => { const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], + controllers: [AppController, DogsController], + providers: [AppService, DogsService], }).compile() appController = app.get(AppController) diff --git a/apps/nestjs/src/dogs/dogs.controller.spec.ts b/apps/nestjs/src/dogs/dogs.controller.spec.ts index ba77b83..e20b0e1 100644 --- a/apps/nestjs/src/dogs/dogs.controller.spec.ts +++ b/apps/nestjs/src/dogs/dogs.controller.spec.ts @@ -1,6 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing' import { DogsController } from './dogs.controller' +import { DogsService } from './dogs.service' describe('DogsController', () => { let controller: DogsController @@ -8,6 +9,7 @@ describe('DogsController', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [DogsController], + providers: [DogsService], }).compile() controller = module.get(DogsController) diff --git a/package.json b/package.json index b069027..70c473a 100644 --- a/package.json +++ b/package.json @@ -2,22 +2,24 @@ "name": "pnpm-monorepo", "private": true, "scripts": { - "build:nestjs": "pnpm --F nestjs build", - "build:remix": "pnpm --F remix build", - "build": "pnpm --F './apps/**' build", + "build:nestjs": "pnpm -F nestjs build", + "build:remix": "pnpm -F remix build", + "build": "pnpm run -r build", "deploy:nestjs": "fly deploy --config ./apps/nestjs/fly.toml --dockerfile ./apps/nestjs/Dockerfile", "deploy:remix": "fly deploy --config ./apps/remix/fly.toml --dockerfile ./apps/remix/Dockerfile", - "develop:nestjs": "pnpm --F nestjs develop", - "develop:remix": "pnpm --F remix develop", - "develop": "pnpm --F './apps/**' develop", + "develop:nestjs": "pnpm -F nestjs develop", + "develop:remix": "pnpm -F remix develop", + "develop": "pnpm -r develop", "format": "prettier --write .", - "lint:fix": "pnpm lint --fix", + "lint:fix": "pnpm lint -fix", "lint": "eslint --ext .ts,.tsx ./apps ./libs", - "start:nestjs": "pnpm --F nestjs start", - "start:remix": "pnpm --F remix start", - "start": "pnpm --F './apps/**' start", - "test": "pnpm --F './apps/**' test", - "test:nestjs": "pnpm --F nestjs test" + "start:nestjs": "pnpm -F nestjs start", + "start:remix": "pnpm -F remix start", + "start": "pnpm -r start", + "test": "pnpm -r test", + "test:e2e": "pnpm -r test:e2e", + "test:nestjs": "pnpm -F nestjs test", + "typecheck": "tsc -b ." }, "devDependencies": { "@flydotio/dockerfile": "^0.4.11",