|
1 | | -# This is a basic workflow to help you get started with Actions |
2 | | - |
3 | 1 | name: CI |
4 | 2 |
|
5 | | -# Controls when the workflow will run |
6 | 3 | on: |
7 | | - # Triggers the workflow on push or pull request events but only for the main branch |
8 | 4 | push: |
9 | | - branches: [ $default-branch ] |
| 5 | + branches: [ main ] |
10 | 6 | pull_request: |
11 | | - branches: [ $default-branch ] |
12 | | - |
13 | | - # Allows you to run this workflow manually from the Actions tab |
| 7 | + branches: [ main ] |
14 | 8 | workflow_dispatch: |
15 | 9 |
|
16 | | -# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
17 | 10 | jobs: |
18 | | - # This workflow contains a single job called "build" |
19 | | - |
20 | 11 | build: |
21 | | - # The type of runner that the job will run on |
22 | 12 | runs-on: ubuntu-latest |
23 | 13 | environment: Testing |
24 | 14 | strategy: |
25 | 15 | matrix: |
26 | | - node-version: [14.x , 16.x] |
27 | | - max-parallel: 1 |
28 | | - |
29 | | - # Steps represent a sequence of tasks that will be executed as part of the job |
| 16 | + node-version: [20.x, 22.x] |
| 17 | + max-parallel: 1 |
| 18 | + services: |
| 19 | + mongodb: |
| 20 | + image: mongo:latest |
| 21 | + options: >- |
| 22 | + --health-cmd mongosh |
| 23 | + --health-interval 10s |
| 24 | + --health-timeout 5s |
| 25 | + --health-retries 5 |
| 26 | + ports: |
| 27 | + - 27017:27017 |
| 28 | + env: |
| 29 | + MONGO_INITDB_ROOT_USERNAME: admin |
| 30 | + MONGO_INITDB_ROOT_PASSWORD: mongodb |
| 31 | + |
30 | 32 | steps: |
31 | | - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
32 | | - - uses: actions/checkout@v2 |
33 | | - with: |
34 | | - ref: 'main-test' |
| 33 | + - uses: actions/checkout@v4 |
35 | 34 |
|
36 | | - - name: Install server npm packages |
37 | | - uses: bahmutov/npm-install@v1 |
| 35 | + - name: Use Node.js ${{ matrix.node-version }} |
| 36 | + uses: actions/setup-node@v4 |
38 | 37 | with: |
39 | | - working-directory: mern/server |
| 38 | + node-version: ${{ matrix.node-version }} |
| 39 | + cache: 'npm' |
| 40 | + cache-dependency-path: | |
| 41 | + mern/server/package-lock.json |
| 42 | + mern/client/package-lock.json |
| 43 | +
|
| 44 | + - name: Install server npm packages |
| 45 | + run: npm ci |
| 46 | + working-directory: mern/server |
40 | 47 |
|
41 | 48 | - name: Install client npm packages |
42 | | - uses: bahmutov/npm-install@v1 |
43 | | - with: |
44 | | - working-directory: mern/client |
| 49 | + run: npm ci |
| 50 | + working-directory: mern/client |
45 | 51 |
|
46 | 52 | - name: Start server in the background |
47 | | - env: |
48 | | - ATLAS_URI: ${{ secrets.ATLAS_URI }} |
49 | | - run: (cd mern/server && echo "ATLAS_URI=$ATLAS_URI" > config.env && npm start &) |
| 53 | + env: |
| 54 | + ATLAS_URI: mongodb://admin:mongodb@localhost:27017/ |
| 55 | + run: | |
| 56 | + echo "ATLAS_URI=$ATLAS_URI" > config.env |
| 57 | + npm start > /tmp/server.log 2>&1 & |
| 58 | + echo "Server PID: $!" |
| 59 | + working-directory: mern/server |
50 | 60 |
|
51 | | - - name: Start React app in the background |
52 | | - run: (cd mern/client && npm start &) |
| 61 | + - name: Wait for server to be ready |
| 62 | + run: | |
| 63 | + npx wait-on http://localhost:5050/record --timeout 30000 || (cat /tmp/server.log && exit 1) |
53 | 64 |
|
54 | 65 | - name: Install Cypress and run tests |
55 | | - uses: cypress-io/github-action@v2 |
| 66 | + uses: cypress-io/github-action@v6 |
56 | 67 | with: |
57 | 68 | working-directory: mern/client |
| 69 | + start: npm run dev |
| 70 | + wait-on: 'http://localhost:5173' |
58 | 71 |
|
0 commit comments