Skip to content

Commit

Permalink
run validation jobs in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
sitek94 committed Nov 25, 2023
1 parent ebc2bfb commit d8ccb1d
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 113 deletions.
195 changes: 195 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]

- 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/[email protected]

- 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 }}
98 changes: 0 additions & 98 deletions .github/workflows/validate.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
- [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
- [ ] (?) build and deploy Storybook to fly.io
- [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

Expand Down
6 changes: 4 additions & 2 deletions apps/nestjs/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(AppController)
Expand Down
2 changes: 2 additions & 0 deletions apps/nestjs/src/dogs/dogs.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing'

import { DogsController } from './dogs.controller'
import { DogsService } from './dogs.service'

describe('DogsController', () => {
let controller: DogsController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [DogsController],
providers: [DogsService],
}).compile()

controller = module.get<DogsController>(DogsController)
Expand Down
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d8ccb1d

Please sign in to comment.