Skip to content

CI

CI #57

Workflow file for this run

name: CI
on:
push:
branches: ["main"]
pull_request:
workflow_dispatch:
schedule:
- cron: '0 6 * * 1'
jobs:
build-and-smoke:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
# Angular 22 requires Node ^22.22.3 || ^24.15.0 || >=26.0.0
node-version: [24.18.0, 26.5.0]
services:
mongodb:
image: mongo:latest
options: >-
--health-cmd "mongosh --eval 'db.adminCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27017:27017
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
env:
DATABASE_URI: mongodb://localhost:27017/
run: npm run build
- name: Server lint tests
env:
DATABASE_URI: mongodb://localhost:27017/
run: npm run test:server
- name: Integration tests
run: npm run test:integration
- name: Seed demo data
env:
DATABASE_URI: mongodb://localhost:27017/meanStackExample?appName=mean-stack-example-ci
run: npm run seed
- name: Start API
env:
DATABASE_URI: mongodb://localhost:27017/meanStackExample?appName=mean-stack-example-ci
PORT: 5300
run: |
npm run start:server > /tmp/server.log 2>&1 &
echo $! > /tmp/server.pid
- name: Wait for API health
run: |
for i in {1..30}; do
if curl -fsS http://localhost:5300/healthcheck >/dev/null; then
echo "API is ready"
exit 0
fi
sleep 1
done
echo "API did not become ready"
cat /tmp/server.log
exit 1
- name: Smoke check employee list endpoint
run: curl -fsS http://localhost:5300/employees
- name: Stop API
if: always()
run: |
if [ -f /tmp/server.pid ]; then
kill "$(cat /tmp/server.pid)" || true
fi
notify-on-failure:
needs: build-and-smoke
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'],
});
}