96 lines
2.8 KiB
YAML
96 lines
2.8 KiB
YAML
name: FreightDesk CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
pull_request:
|
|
branches: [master]
|
|
|
|
env:
|
|
NODE_VERSION: '20'
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
# ── Lint & Test ──────────────────────────────────────────
|
|
test:
|
|
name: Lint & Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
cache: 'npm'
|
|
cache-dependency-path: webapp/package-lock.json
|
|
|
|
- name: Install dependencies
|
|
working-directory: ./webapp
|
|
run: npm ci
|
|
|
|
- name: Run linter
|
|
working-directory: ./webapp
|
|
run: npm run lint --if-present
|
|
|
|
- name: Run tests
|
|
working-directory: ./webapp
|
|
run: npm test --if-present
|
|
env:
|
|
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
|
|
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
|
|
|
|
- name: Smoke test
|
|
working-directory: ./webapp
|
|
run: |
|
|
timeout 15 npm start &
|
|
sleep 5
|
|
curl -sf http://localhost:3000/health || exit 1
|
|
echo "✅ Smoke test passed"
|
|
env:
|
|
NODE_ENV: test
|
|
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
|
|
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
|
|
SESSION_SECRET: test-secret
|
|
|
|
# ── Build & Push Docker Image ────────────────────────────
|
|
build:
|
|
name: Build Docker Image
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
if: github.ref == 'refs/heads/master'
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Build Docker image
|
|
working-directory: ./webapp
|
|
run: |
|
|
docker build -t freightdesk:${{ github.sha }} .
|
|
echo "✅ Docker image built"
|
|
|
|
- name: Tag image
|
|
run: |
|
|
docker tag freightdesk:${{ github.sha }} freightdesk:latest
|
|
echo "✅ Image tagged"
|
|
|
|
# ── Deploy to Coolify ────────────────────────────────────
|
|
deploy:
|
|
name: Deploy to Coolify
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
if: github.ref == 'refs/heads/master'
|
|
steps:
|
|
- name: Trigger Coolify deployment
|
|
run: |
|
|
if [ -n "${{ secrets.COOLIFY_WEBHOOK_URL }}" ]; then
|
|
curl -sf -X POST "${{ secrets.COOLIFY_WEBHOOK_URL }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"sha": "${{ github.sha }}", "branch": "master"}'
|
|
echo "✅ Coolify deployment triggered"
|
|
else
|
|
echo "⚠️ COOLIFY_WEBHOOK_URL not set — skipping deployment"
|
|
fi
|