From dacb601da7ae7d0426c659234b0de22854d31f67 Mon Sep 17 00:00:00 2001 From: KRUTAGYA HIRENBHAI KANERIA Date: Sun, 14 Dec 2025 16:04:59 +0530 Subject: [PATCH 1/2] Add Node.js CI/CD pipeline workflow This workflow includes jobs for building, linting, security checks, Docker image creation, and deployment for a Node.js application. --- .github/workflows/node.js(CI & CD).yml | 106 +++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/node.js(CI & CD).yml diff --git a/.github/workflows/node.js(CI & CD).yml b/.github/workflows/node.js(CI & CD).yml new file mode 100644 index 0000000..916cb9a --- /dev/null +++ b/.github/workflows/node.js(CI & CD).yml @@ -0,0 +1,106 @@ +# 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: + + strategy: + matrix: + os: [ubuntu-latest,windows-latest,macos-latest] + node-version: [18.x, 20.x, 22.x] + + runs-on: ${{ matrix.os }} + + 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!" From ae4a38a0681b70cdae39e135a1543c5052d193e0 Mon Sep 17 00:00:00 2001 From: KRUTAGYA HIRENBHAI KANERIA Date: Sun, 14 Dec 2025 16:19:00 +0530 Subject: [PATCH 2/2] Update CI/CD workflow to use a single OS --- .github/workflows/node.js(CI & CD).yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js(CI & CD).yml b/.github/workflows/node.js(CI & CD).yml index 916cb9a..ec1ced7 100644 --- a/.github/workflows/node.js(CI & CD).yml +++ b/.github/workflows/node.js(CI & CD).yml @@ -13,13 +13,14 @@ jobs: build: + + runs-on: ubuntu-latest strategy: matrix: - os: [ubuntu-latest,windows-latest,macos-latest] node-version: [18.x, 20.x, 22.x] - runs-on: ${{ matrix.os }} + steps: - uses: actions/checkout@v4