Skip to content

Merge pull request #55 from mongodb-developer/ci-weekly-schedule-code… #42

Merge pull request #55 from mongodb-developer/ci-weekly-schedule-code…

Merge pull request #55 from mongodb-developer/ci-weekly-schedule-code… #42

Workflow file for this run

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'],
});
}