eletrotupi / tcc/ commit / 8b7a438

ci: add API test workflow and fix tsconfig.build.json rootDir

Pedro Lucas Porcellis porcellis@eletrotupi.com 29 days ago 8b7a4383c6c39de79612d786a2c836f1b01221b8
Parents: 52edfe2
2 file(s) changed
  • .github/workflows/deploy.yml +58 -4
  • api/tsconfig.build.json +2 -1
.github/workflows/deploy.yml
1 -
name: Deploy
1 +
name: Test & Deploy
2 2

3 3
on:
4 4
  push:
5 5
    branches:
6 -
      - master # goes for production now, will become staging later on
6 +
      - master
7 7
      - production
8 +
    paths:
9 +
      - 'api/**'
10 +
      - '.github/workflows/deploy.yml'
11 +
  pull_request:
8 12
    paths:
9 13
      - 'api/**'
10 14
      - '.github/workflows/deploy.yml'
11 15

12 16
env:
13 17
  REGISTRY: ghcr.io
14 18
  IMAGE_NAME: ${{ github.repository }}
15 19

16 20
jobs:
21 +
  test:
22 +
    name: Run test suite
23 +
    runs-on: ubuntu-latest
24 +

25 +
    services:
26 +
      postgres:
27 +
        image: postgres:17-alpine
28 +
        env:
29 +
          POSTGRES_USER: user
30 +
          POSTGRES_PASSWORD: password
31 +
          POSTGRES_DB: postgres
32 +
        options: >-
33 +
          --health-cmd "pg_isready -U user"
34 +
          --health-interval 10s
35 +
          --health-timeout 5s
36 +
          --health-retries 5
37 +
        ports:
38 +
          - 5432:5432
39 +

40 +
    defaults:
41 +
      run:
42 +
        working-directory: api
43 +

44 +
    env:
45 +
      DATABASE_URL: postgres://user:password@localhost:5432/orbit_test
46 +
      NODE_ENV: test
47 +
      JWT_SECRET: test-secret-key
48 +
      FRONTEND_URL: http://localhost:8081
49 +

50 +
    steps:
51 +
      - uses: actions/checkout@v4
52 +

53 +
      - uses: actions/setup-node@v4
54 +
        with:
55 +
          node-version: '24'
56 +
          cache: 'npm'
57 +
          cache-dependency-path: api/package-lock.json
58 +

59 +
      - name: Install dependencies
60 +
        run: npm ci
61 +

62 +
      - name: Set up test database
63 +
        run: |
64 +
          node scripts/create-test-db.mjs
65 +
          npx prisma generate
66 +
          npx prisma db push
67 +

68 +
      - name: Run tests
69 +
        run: npx vitest run
70 +

17 71
  build-and-push:
18 72
    name: Build & push image
73 +
    needs: test
74 +
    if: github.event_name == 'push'
19 75
    runs-on: ubuntu-latest
20 76
    permissions:
21 77
      contents: read
22 78
      packages: write
23 79

▸ 31 unchanged lines
55 111
          file: ./api/Dockerfile.production
56 112
          push: true
57 113
          tags: ${{ steps.meta.outputs.tags }}
58 114
          labels: ${{ steps.meta.outputs.labels }}
59 115

60 -

61 116
  deploy-production:
62 117
    name: Deploy to production
63 118
    needs: build-and-push
64 119
    runs-on: ubuntu-latest
65 120
    if: github.ref == 'refs/heads/master'
▸ 15 unchanged lines
81 136
            sed -i "s/^IMAGE_TAG=.*/IMAGE_TAG=latest/" .env
82 137

83 138
            docker compose up -d --no-deps --force-recreate api
84 139

85 140
            sleep 5
86 -
            # Dump the logs for a while
87 141
            docker compose logs --tail=50 api
api/tsconfig.build.json
1 1
{
2 2
  "extends": "./tsconfig.json",
3 3
  "compilerOptions": {
4 4
    "ignoreDeprecations": "6.0",
5 5
    "noImplicitAny": false,
6 -
    "lib": ["ES2022", "DOM"]
6 +
    "lib": ["ES2022", "DOM"],
7 +
    "rootDir": "src"
7 8
  },
8 9
  "include": ["src/**/*"],
9 10
  "exclude": ["node_modules", "dist", "tests"]
10 11
}