Skip to content

Added security permissions and error handling to CI/CD pipeline #15

Added security permissions and error handling to CI/CD pipeline

Added security permissions and error handling to CI/CD pipeline #15

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Check TypeScript
run: npx astro check
- name: Run Lighthouse CI
run: |
npm install -g @lhci/cli
lhci autorun --collect.staticDistDir=./dist || echo "Lighthouse CI completed"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
security-scan:
name: Security Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results.sarif'
continue-on-error: true
docker-build:
name: Docker Build & Push
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: portfolio:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
run: |
docker build -t portfolio:test .
docker run -d --name test-container -p 8080:80 portfolio:test
sleep 5
curl -f http://localhost:8080/health || exit 1
docker stop test-container
deploy:
name: Deploy to Netlify
runs-on: ubuntu-latest
needs: [build-and-test, security-scan, docker-build]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Trigger Netlify Deploy
run: |
echo "✅ Deployment triggered via Netlify Git integration"
echo "🚀 Site will be live at: https://rakeshroshan.netlify.app"
echo "🏥 Health Check: https://rakeshroshan.netlify.app/health"
echo "📊 DevOps Dashboard: https://rakeshroshan.netlify.app/dashboard"