diff --git a/.github/workflows/api-build.yml b/.github/workflows/api-build.yml deleted file mode 100644 index c410d38..0000000 --- a/.github/workflows/api-build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: API - Build - -on: - push: - branches: - - main - paths: - - 'api/**' - pull_request: - branches: - - main - paths: - - 'api/**' - workflow_dispatch: - -env: - DOCKER_IMAGE: prasadhonrao/devcamper-api - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push Docker image - run: | - docker build -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} -f api/Dockerfile api - docker tag ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest - docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }} - docker push ${{ env.DOCKER_IMAGE }}:latest diff --git a/.github/workflows/api-cd.yml b/.github/workflows/api-cd.yml index 34af841..d485a9a 100644 --- a/.github/workflows/api-cd.yml +++ b/.github/workflows/api-cd.yml @@ -1,31 +1,84 @@ name: API - Continuous Deployment on: - workflow_run: - workflows: ['API - Continuous Integration'] - types: - - completed + push: + branches: + - main + paths: + - 'api/**' + workflow_dispatch: + +env: + DOCKER_IMAGE: prasadhonrao/devcamper-api jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + run: | + docker build -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} -f api/Dockerfile api + docker tag ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest + docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }} + docker push ${{ env.DOCKER_IMAGE }}:latest + deploy: - if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest + needs: build steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: '20' - name: Install dependencies - run: | - cd api - npm install + run: npm install --prefix api - name: Deploy run: | # Add your deployment steps here echo "Deploying the application..." + notify: + runs-on: ubuntu-latest + needs: deploy + if: always() + + steps: + - name: Send email notification + uses: dawidd6/action-send-mail@v3 + with: + server_address: smtp.gmail.com + server_port: 587 + username: ${{ secrets.GMAIL_USERNAME }} + password: ${{ secrets.GMAIL_PASSWORD }} + subject: ${{ job.status }}: Deployment Notification + body: | + The deployment has ${{ job.status }}! + Repository: ${{ github.repository }} + Branch: ${{ github.ref }} + Commit: ${{ github.sha }} + Author: ${{ github.actor }} + Workflow: ${{ github.workflow }} + Job: ${{ github.job }} + Run ID: ${{ github.run_id }} + Run Number: ${{ github.run_number }} + Logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + to: ${{ secrets.NOTIFY_EMAIL }} + from: ${{ secrets.GMAIL_USERNAME }} \ No newline at end of file diff --git a/.github/workflows/api-ci.yml b/.github/workflows/api-ci.yml index 25b1a38..10a0d3d 100644 --- a/.github/workflows/api-ci.yml +++ b/.github/workflows/api-ci.yml @@ -1,30 +1,129 @@ name: API - Continuous Integration on: - workflow_run: - workflows: ['API - Security Checks'] - types: - - completed + push: + branches: + - development + paths: + - 'api/**' + pull_request: + branches: + - development + paths: + - 'api/**' + workflow_dispatch: jobs: - build-and-test: + lint: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: '20' - name: Install dependencies + run: npm install --prefix api + + - name: Run linter run: | - cd api - npm install + export PATH=$(pwd)/api/node_modules/.bin:$PATH + npm run lint --prefix api + + dependency-check: + runs-on: ubuntu-latest + needs: lint + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install --prefix api + + - name: Run dependency check + run: npm audit --audit-level=high --prefix api + + security: + runs-on: ubuntu-latest + needs: dependency-check + permissions: + actions: read + contents: read + security-events: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install --prefix api + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: javascript + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + + test: + runs-on: ubuntu-latest + needs: security + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install --prefix api - name: Run tests - run: | - cd api - npm test + run: npm test --prefix api + + code-coverage: + runs-on: ubuntu-latest + needs: test + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install --prefix api + + - name: Run tests with coverage + run: npm run test --prefix api -- --coverage + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: api/coverage diff --git a/.github/workflows/api-deploy.yml b/.github/workflows/api-deploy.yml deleted file mode 100644 index dd6cc63..0000000 --- a/.github/workflows/api-deploy.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: API - Deploy - -on: - push: - branches: - - main - paths: - - 'api/**' - pull_request: - branches: - - main - paths: - - 'api/**' - workflow_dispatch: - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Deploy - run: | - # Add your deployment steps here - echo "Deploying the application..." diff --git a/.github/workflows/api-lint.yml b/.github/workflows/api-lint.yml deleted file mode 100644 index 8ff9417..0000000 --- a/.github/workflows/api-lint.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: API - Linting - -on: - push: - branches: - - main - paths: - - 'api/**' - pull_request: - branches: - - main - paths: - - 'api/**' - workflow_dispatch: - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '20' - - - name: Install dependencies - run: | - cd api - npm install - - - name: Run linter - run: | - cd api - npm run lint diff --git a/.github/workflows/api-security.yml b/.github/workflows/api-security.yml deleted file mode 100644 index 86c7d46..0000000 --- a/.github/workflows/api-security.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: API - Security Checks - -on: - workflow_run: - workflows: ['API - Linting'] - types: - - completed - -jobs: - codeql-analysis: - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: javascript - - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml deleted file mode 100644 index 1ad264c..0000000 --- a/.github/workflows/api.yml +++ /dev/null @@ -1,177 +0,0 @@ -name: API - End-to-End Workflow - -on: - push: - branches: - - main - paths: - - 'api/**' - pull_request: - branches: - - main - paths: - - 'api/**' - workflow_dispatch: - -env: - DOCKER_IMAGE: prasadhonrao/devcamper-api - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Run linter - run: | - export PATH=$(pwd)/api/node_modules/.bin:$PATH - npm run lint --prefix api - - dependency-check: - runs-on: ubuntu-latest - needs: lint - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Run dependency check - run: npm audit --audit-level=high --prefix api - - security: - runs-on: ubuntu-latest - needs: dependency-check - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: javascript - - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - test: - runs-on: ubuntu-latest - needs: security - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Run tests - run: npm test --prefix api - - code-coverage: - runs-on: ubuntu-latest - needs: test - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Run tests with coverage - run: npm run test --prefix api -- --coverage - - - name: Upload coverage report - uses: actions/upload-artifact@v4 - with: - name: coverage-report - path: api/coverage - - build: - runs-on: ubuntu-latest - needs: code-coverage - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push Docker image - run: | - docker build -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} -f api/Dockerfile api - docker tag ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest - docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }} - docker push ${{ env.DOCKER_IMAGE }}:latest - - deploy: - runs-on: ubuntu-latest - needs: build - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install --prefix api - - - name: Deploy - run: | - # Add your deployment steps here - echo "Deploying the application..."