Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/node.js(CI & CD).yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI/CD Pipeline

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:


build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]



steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Build
run: npm run build --if-present

- name: Run Tests
run: npm test


lint:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Dependencies
run: npm install

- name: Run ESLint
run: npm run lint


security:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Dependencies
run: npm install

- name: NPM Audit Security Check
run: npm audit --audit-level=high



docker:
runs-on: ubuntu-latest
needs: [build, lint, security]

steps:
- uses: actions/checkout@v4

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker Image
run: docker build -t krutagyakaneria/nodejs_cicd_workflow:${{ github.sha }} .

- name: Push Docker Image
run: docker push krutagyakaneria/nodejs_cicd_workflow:${{ github.sha }}


deploy:
runs-on: ubuntu-latest
needs: docker

steps:
- name: Trigger Deployment
run: |
curl -X POST ${{ secrets.DEPLOY_WEBHOOK_URL }}
echo "Deployment triggered successfully!"
Loading