|
1 | | -name: "Tests the App" |
2 | | -env: |
3 | | - DB_PROVIDER: ${{ vars.DB_PROVIDER }} |
4 | | - DB_URL: ${{ secrets.DB_URL }} |
| 1 | +name: Tests the App |
| 2 | + |
5 | 3 | on: |
6 | 4 | push: |
7 | 5 | branches: |
8 | 6 | - main |
| 7 | + workflow_dispatch: |
| 8 | + |
9 | 9 | jobs: |
10 | | - run_test: |
11 | | - name: "Run tests" |
| 10 | + build-and-test: |
| 11 | + name: Build and test with Node.js ${{ matrix.node-version }} and ${{ matrix.db }} |
12 | 12 | runs-on: ubuntu-latest |
13 | 13 |
|
14 | 14 | strategy: |
15 | | - max-parallel: 1 |
16 | 15 | matrix: |
17 | | - node-version: [18.x, 20.x] |
18 | | - # See supported Node.js release schedule at https://nodejs.org/en/about/releases |
| 16 | + node-version: [18, 20] |
| 17 | + db: [postgresql, mysql] |
| 18 | + include: |
| 19 | + - db: postgresql |
| 20 | + db-image: postgres:14 |
| 21 | + db-port: 5432 |
| 22 | + db-username: postgres |
| 23 | + db-options: >- |
| 24 | + --health-cmd="pg_isready -U postgres" |
| 25 | + --health-interval=10s |
| 26 | + --health-timeout=5s |
| 27 | + --health-retries=5 |
| 28 | +
|
| 29 | + - db: mysql |
| 30 | + db-image: mysql:8 |
| 31 | + db-port: 3306 |
| 32 | + db-username: root |
| 33 | + db-options: >- |
| 34 | + --health-cmd="mysqladmin ping --silent" |
| 35 | + --health-interval=10s |
| 36 | + --health-timeout=5s |
| 37 | + --health-retries=5 |
| 38 | +
|
| 39 | + services: |
| 40 | + db: |
| 41 | + image: ${{ matrix.db-image }} |
| 42 | + env: |
| 43 | + POSTGRES_USER: ${{ matrix.db-username }} |
| 44 | + POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }} |
| 45 | + POSTGRES_DB: testdb |
| 46 | + MYSQL_ROOT_PASSWORD: rO0t_${{ secrets.DB_PASSWORD }} |
| 47 | + MYSQL_DATABASE: testdb |
| 48 | + MYSQL_USER: ${{ matrix.db-username }} |
| 49 | + MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }} |
| 50 | + ports: |
| 51 | + - ${{ matrix.db-port }}:${{ matrix.db-port }} |
| 52 | + options: ${{ matrix.db-options }} |
| 53 | + |
| 54 | + env: |
| 55 | + DB_PROVIDER: ${{ matrix.db }} |
| 56 | + DB_URL: ${{ format('{0}://{1}:{2}/{3}', matrix.db, matrix.db-username, secrets.DB_PASSWORD, matrix.db-port, 'testdb') }} |
19 | 57 |
|
20 | 58 | steps: |
21 | | - - uses: actions/checkout@v3 |
22 | | - - name: Install modules |
23 | | - run: npm ci |
24 | | - - name: Check code formatting |
25 | | - run: npm run lint |
26 | | - - name: Migrate the database |
27 | | - run: npm run db:migrate |
28 | | - - name: Seed the data |
29 | | - run: npm run db:seed |
30 | | - - name: Build |
31 | | - run: npm run build |
32 | | - - name: Run unit tests |
33 | | - run: npm run test |
34 | | - - name: Run e2e tests |
35 | | - run: npm run test:e2e |
| 59 | + - name: Checkout code |
| 60 | + uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Set up Node.js |
| 63 | + uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + node-version: ${{ matrix.node-version }} |
| 66 | + |
| 67 | + - name: Cache Node.js modules |
| 68 | + uses: actions/cache@v4 |
| 69 | + with: |
| 70 | + path: node_modules |
| 71 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}-${{ matrix.node-version }} |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-node-${{ matrix.node-version }} |
| 74 | +
|
| 75 | + - name: Install dependencies |
| 76 | + run: npm ci |
| 77 | + |
| 78 | + - name: Run linting |
| 79 | + run: npm run lint |
| 80 | + |
| 81 | + - name: Run database migrations |
| 82 | + run: npm run db:migrate |
| 83 | + |
| 84 | + - name: Run database seed |
| 85 | + run: npm run db:seed |
| 86 | + |
| 87 | + - name: Build the app |
| 88 | + run: npm run build |
| 89 | + |
| 90 | + - name: Run unit tests |
| 91 | + run: npm run test |
| 92 | + |
| 93 | + - name: Run e2e tests |
| 94 | + run: npm run test:e2e |
0 commit comments