mirror of
https://github.com/nimbusdotstorage/Nimbus
synced 2026-04-22 17:45:03 +02:00
125 lines
4.1 KiB
YAML
125 lines
4.1 KiB
YAML
name: CI
|
|
run-name: "Branch: ${{ github.ref_name }}. Event: ${{ github.event_name }}. By: ${{ github.actor }}."
|
|
|
|
on:
|
|
push:
|
|
branches: [main, staging]
|
|
pull_request:
|
|
branches: [main, staging]
|
|
|
|
jobs:
|
|
ci:
|
|
runs-on: ubuntu-latest
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
ports:
|
|
- 5432:5432
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: nimbus-test
|
|
options: >-
|
|
--health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
|
|
minio:
|
|
image: minio/minio:edge-cicd
|
|
ports:
|
|
- 9000:9000
|
|
env:
|
|
MINIO_ROOT_USER: minioadmin
|
|
MINIO_ROOT_PASSWORD: minioadmin
|
|
MINIO_REGION: us-east-1
|
|
options: >-
|
|
--health-cmd "curl -f http://localhost:9000/minio/health/ready" --health-interval 30s --health-timeout 10s --health-retries 3
|
|
|
|
steps:
|
|
- uses: actions/checkout@master
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: latest
|
|
- uses: oven-sh/setup-bun@v2
|
|
with:
|
|
bun-version: latest
|
|
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
|
|
- name: Run formatter
|
|
run: bun format
|
|
|
|
- name: Run linter
|
|
run: bun lint
|
|
|
|
- name: Run tests with coverage
|
|
run: bun run test:coverage
|
|
|
|
- name: Build application
|
|
env:
|
|
NODE_ENV: production
|
|
DATABASE_URL: postgres://postgres:postgres@localhost:5432/nimbus-test
|
|
NEXT_PUBLIC_BACKEND_URL: http://localhost:1284
|
|
NEXT_PUBLIC_FRONTEND_URL: http://localhost:3000
|
|
run: bun run build
|
|
|
|
- name: Create coverage badge
|
|
if: github.ref == 'refs/heads/staging'
|
|
run: |
|
|
# Extract coverage percentage from JSON summary
|
|
if [ -f "coverage/coverage-summary.json" ]; then
|
|
coverage=$(node -e "const fs=require('fs'); const data=JSON.parse(fs.readFileSync('coverage/coverage-summary.json')); const total=data.total; if(total && total.lines && total.lines.pct !== undefined) { console.log(total.lines.pct); } else { console.log('0'); }")
|
|
else
|
|
coverage=0
|
|
fi
|
|
|
|
# If coverage extraction fails, default to 0
|
|
if [ -z "$coverage" ] || [ "$coverage" = "null" ]; then coverage=0; fi
|
|
|
|
# Round coverage to integer
|
|
coverage=$(printf "%.0f" "$coverage")
|
|
|
|
# Determine color based on coverage
|
|
if [ "$coverage" -ge 80 ]; then
|
|
color=green
|
|
elif [ "$coverage" -ge 50 ]; then
|
|
color=yellow
|
|
else
|
|
color=red
|
|
fi
|
|
|
|
# Create a simpler badge using shields.io style URL
|
|
echo "Coverage: $coverage%"
|
|
continue-on-error: true
|
|
|
|
- name: Commit coverage report
|
|
if: github.ref == 'refs/heads/staging'
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
git config user.name "github-actions"
|
|
git config user.email "github-actions@github.com"
|
|
|
|
# Update README with actual coverage percentage using shields.io badge
|
|
if [ -f "coverage/coverage-summary.json" ]; then
|
|
coverage=$(node -e "const fs=require('fs'); const data=JSON.parse(fs.readFileSync('coverage/coverage-summary.json')); const total=data.total; if(total && total.lines && total.lines.pct !== undefined) { console.log(total.lines.pct); } else { console.log('0'); }")
|
|
else
|
|
coverage=0
|
|
fi
|
|
|
|
if [ -z "$coverage" ] || [ "$coverage" = "null" ]; then coverage=0; fi
|
|
coverage=$(printf "%.0f" "$coverage")
|
|
|
|
if [ "$coverage" -ge 80 ]; then
|
|
color=green
|
|
elif [ "$coverage" -ge 50 ]; then
|
|
color=yellow
|
|
else
|
|
color=red
|
|
fi
|
|
|
|
sed -i "s/coverage-[0-9]*%25-[a-z]*/coverage-$coverage%25-$color/" README.md
|
|
git add README.md
|
|
git commit -m "Update coverage badge [skip ci]" || echo "No changes to commit"
|
|
git push
|
|
continue-on-error: true
|