Update ci-cd.dev.yml #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Prod Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
ENVIRONMENT: production | |
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }} | |
NEXTAUTH_SECRET: ${{ secrets.PROD_NEXTAUTH_SECRET }} | |
NEXT_PUBLIC_SITE_URL: https://satsquare.ismail-mouyahada.com | |
NEXT_PUBLIC_SOCKET_URL: wss://websocket.ismail-mouyahada.com | |
jobs: | |
deps-vulnerability: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run dependency vulnerability scan | |
uses: advanced-security/npm-audit-action@v1 | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run Linting | |
run: npm run lint | |
unit-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run Jest Unit Tests | |
run: npm run test:watch | |
codecov: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run tests and generate coverage report | |
run: npm run test -- --coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
security: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Run security analysis | |
uses: github/codeql-action/analyze@v2 | |
lighthouse: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run Lighthouse CI | |
run: npx lhci autorun | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to GitHub Container Registry | |
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Build Docker image | |
run: docker build -t ghcr.io/ismail-mouyahada/sat-square:prod-${{ github.sha }} -f Dockerfile.prod . | |
- name: Scan Docker image for vulnerabilities | |
uses: aquasecurity/[email protected] | |
with: | |
image-ref: ghcr.io/ismail-mouyahada/sat-square:prod-${{ github.sha }} | |
- name: Push Docker image to GitHub Container Registry | |
run: docker push ghcr.io/ismail-mouyahada/sat-square:prod-${{ github.sha }} | |
e2e-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run end-to-end tests | |
run: npm run test:e2e | |
stress-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run stress tests | |
run: npm run test:stress | |
notify: | |
runs-on: ubuntu-latest | |
needs: [deps-vulnerability, lint, unit-tests, codecov, security, lighthouse, docker-build, e2e-tests, stress-test] | |
steps: | |
- name: Send Discord notification on success | |
if: success() | |
run: | | |
curl -X POST -H "Content-Type: application/json" \ | |
-d '{"content": "CI/CD Prod Pipeline succeeded!"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
- name: Send Discord notification on failure | |
if: failure() | |
run: | | |
curl -X POST -H "Content-Type: application/json" \ | |
-d '{"content": "CI/CD Prod Pipeline failed!"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} |