Repository navigation
113 lines (103 loc) · 3.34 KB
/
Copy pathmain.yaml
File metadata and controls
113 lines (103 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: '5 6 * * 1'
jobs:
build:
runs-on: ubuntu-latest
environment: Testing
strategy:
matrix:
node-version: [20.x, 22.x]
max-parallel: 1
services:
mongodb:
image: mongo:latest
options: >-
--health-cmd "mongosh --username admin --password mongodb --authenticationDatabase admin --eval \"db.adminCommand('ping')\""
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: mongodb
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: |
mern/server/package-lock.json
mern/client/package-lock.json
- name: Install server npm packages
run: npm ci
working-directory: mern/server
- name: Install client npm packages
run: npm ci
working-directory: mern/client
- name: Start server in the background
env:
ATLAS_URI: mongodb://admin:mongodb@localhost:27017/employees?authSource=admin
run: |
echo "ATLAS_URI=$ATLAS_URI" > config.env
npm start > /tmp/server.log 2>&1 &
echo "Server PID: $!"
working-directory: mern/server
- name: Wait for server to be ready
run: |
npx wait-on http://localhost:5050/record --timeout 30000 || (cat /tmp/server.log && exit 1)
- name: Install Cypress and run tests
uses: cypress-io/github-action@v6
with:
working-directory: mern/client
start: npm run dev
wait-on: 'http://localhost:5173'
notify-on-failure:
needs: build
if: failure()
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: File or update CI failure issue for @mongodb-developer/learning-fuel
uses: actions/github-script@v7
with:
script: |
const title = `CI failure on ${context.ref}`;
const body = [
'@mongodb-developer/learning-fuel the CI workflow failed.',
'',
`Workflow: ${context.workflow}`,
`Run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
].join('\n');
const { data: existing } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'ci-failure',
});
if (existing.length > 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existing[0].number,
body,
});
} else {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['ci-failure'],
});
}