|
| 1 | +name: ThoughtSwap CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint-and-format: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout Code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + ref: ${{ github.head_ref }} # Checkout the branch for PR auto-commits |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '20' |
| 22 | + cache: 'npm' |
| 23 | + |
| 24 | + - name: Install Dependencies |
| 25 | + run: npm install |
| 26 | + |
| 27 | + # Check styling (Prettier) as required by syllabus |
| 28 | + - name: Check Formatting |
| 29 | + run: npx prettier --check "**/*.{ts,tsx,js,jsx,json,md}" |
| 30 | + |
| 31 | + # Attempt to auto-format on PR if check fails [cite: 150] |
| 32 | + - name: Auto-format on Pull Request |
| 33 | + if: failure() && github.event_name == 'pull_request' |
| 34 | + run: | |
| 35 | + npm run lint-staged |
| 36 | +
|
| 37 | + - name: Commit formatting changes |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 40 | + with: |
| 41 | + commit_message: 'style: auto-format code with Prettier' |
| 42 | + |
| 43 | + # Run ESLint for client code quality |
| 44 | + - name: Lint Client |
| 45 | + run: npm run lint --workspace=packages/client |
| 46 | + |
| 47 | + build-and-test: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + services: |
| 50 | + # Provision a database for Prisma server tests |
| 51 | + postgres: |
| 52 | + image: postgres:15 |
| 53 | + env: |
| 54 | + POSTGRES_USER: user |
| 55 | + POSTGRES_PASSWORD: password |
| 56 | + POSTGRES_DB: thoughtswap |
| 57 | + ports: |
| 58 | + - 5432:5432 |
| 59 | + options: >- |
| 60 | + --health-cmd pg_isready |
| 61 | + --health-interval 10s |
| 62 | + --health-timeout 5s |
| 63 | + --health-retries 5 |
| 64 | +
|
| 65 | + steps: |
| 66 | + - name: Checkout Code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Setup Node.js |
| 70 | + uses: actions/setup-node@v4 |
| 71 | + with: |
| 72 | + node-version: '20' |
| 73 | + cache: 'npm' |
| 74 | + |
| 75 | + - name: Install Dependencies |
| 76 | + run: npm install |
| 77 | + |
| 78 | + # Generate Prisma Client and run builds [cite: 129] |
| 79 | + - name: Server - Build |
| 80 | + env: |
| 81 | + DATABASE_URL: postgresql://user:password@localhost:5432/thoughtswap |
| 82 | + run: | |
| 83 | + cd packages/server |
| 84 | + npx prisma generate |
| 85 | + npm run build |
| 86 | +
|
| 87 | + - name: Client - Build |
| 88 | + run: | |
| 89 | + cd packages/client |
| 90 | + npm run build |
| 91 | +
|
| 92 | + # Run basic Reachability Smoke Test [cite: 145, 146] |
| 93 | + - name: Run Smoke Test |
| 94 | + run: npm run smoke-test --workspace=packages/server |
0 commit comments