Skip to content

added jobs for storing reports #103

added jobs for storing reports

added jobs for storing reports #103

Workflow file for this run

name: NodeJs Application Workflow
env:
MONGO_URI: 'mongodb+srv://supercluster.d83jj.mongodb.net/superData'
MONGO_USERNAME: ${{ vars.MONGO_USERNAME }}
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
on:
push:
branches:
- main
- 'feature/*'
jobs:
unit-testing:
name: Unit Testing
services:
mongo-db:
image: siddharth67/mongo-db:non-prod
ports:
- 27017:27017
env:
MONGO_URI: 'mongodb://localhost:27017/superData'
MONGO_USERNAME: non-prod-user
MONGO_PASSWORD: non-prod-password
strategy:
matrix:
nodejs-versions: [18, 20]
operating-systems: [ubuntu-latest]
exclude:
- nodejs-versions: 18
operating-systems: macos-latest
runs-on: ${{ matrix.operating-systems }}
steps:
- name: Checkout Repositroy
uses: actions/checkout@v4
- name: Setup the NodeJS Versions - ${{ matrix.nodejs-versions }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.nodejs-versions }}
- name: Cache Dependencies # Added new Dependencies
uses: actions/cache@v3 # Updated Version
with:
path: node_modules
key: ${{ runner.os }}--node_modules-${{ hashFiles('package-lock.json') }}
- name: Install Dependencies
run: npm install
- name: Unit Testing
id: nodejs-unit-testing
run: npm test
- name : Storing the Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: mocha-test-report
path: test-results.xml
code-coverage:
name: Code Coverage
container:
image: node:18
services:
mongodb:
image: siddharth67/mongo-db:non-prod
options:
--name mongo
env:
MONGO_URI: 'mongodb://mongo:27017/superData'
MONGO_USERNAME: non-prod-user
MONGO_PASSWORD: non-prod-password
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# - name: Setup the NodeJS Versions - 18
# uses: actions/setup-node@v4
# with:
# node-version: 18
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}--node_modules-${{ hashFiles('package-lock.json') }} # Added Cache
- name: Install Dependencies
run: npm install
- name: Code Coverage
continue-on-error: true
run: npm run coverage
- name : Storing the Test Results
uses: actions/upload-artifact@v3
with:
name: nyc-istanbul-report
path: coverage
retention-days: 5
reports-to-s3-bucket:
needs: [unit-testing, code-coverage]
name: Upload artifacts to AWS S3 Bucket
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Download Mocha Test Reports
uses: actions/download-artifact@v4
with:
name: mocha-test-report
- name: Download Code Coverage Reports
uses: actions/download-artifact@v4
with:
name: nyc-istanbul-report
- name: Merge Test Files
run: |
ls -ltr
mkdir reports-${{ github.sha }}
mv cobertura-coverage.xml reports-${{ github.sha }}/
mv test-results.xml reports-${{ github.sha }}/
ls -ltr reports-${{ github.sha }}/
- name: Uploading to AWS S3 Bucket
run: echo "uploading.........."
docker:
needs: [unit-testing, code-coverage]
name: Containerization
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: GHCR Login
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Build Test
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: ${{ vars.DOCKER_USERNAME }}/solar-system:${{ github.sha }}
- name: Docker Image Test
run: |
docker images
docker run --name solar-system-app -d \
-p 3000:3000 \
-e MONGO_USERNAME=$MONGO_USERNAME \
-e MONGO_PASSWORD=$MONGO_PASSWORD \
${{ vars.DOCKER_USERNAME }}/solar-system:${{ github.sha }}
export IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' solar-system-app)
echo $IP
echo Testing the Image URL using wget
wget -q -O - 127.0.0.1:3000/live | grep live
- name: Container Registry Push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ vars.DOCKER_USERNAME }}/solar-system:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/solar-system:${{ github.sha }}
dev-deploy:
if: contains(github.ref, 'feature/')
name: Deploying Application to the Development Env Production
needs: docker
uses: ./.github/workflows/reuse-deployments.yml
secrets:
k8s-kubeconfig: ${{ secrets.KUBECONFIG }}
mongodb-password: ${{ secrets.MONGO_PASSWORD }}
with:
mongo-uri: ${{ vars.MONGO_URI }}
environment: development
k8s-manifest-direc: kubernetes/development/
dev-integration-testing:
if: contains(github.ref, 'feature/')
name: Dev Integration testing
needs: dev-deploy
runs-on: ubuntu-latest
steps:
- name : Test URL Output Using CURL and JQ
env:
URL: ${{ needs.dev-deploy.outputs.application-url }}
run: |
echo $URL
echo "--------------------------"
curl https://$URL/live -s -k | jq -r .status | grep -i live
continue-on-error: true
prod-deploy:
if: github.ref == 'refs/heads/master'
name: Deploying Application to the Production Env
needs: docker
uses: ./.github/workflows/reuse-deployments.yml
secrets:
k8s-kubeconfig: ${{ secrets.KUBECONFIG }}
mongodb-password: ${{ secrets.MONGO_PASSWORD }}
with:
mongo-uri: ${{ vars.MONGO_URI }}
environment: production
k8s-manifest-direc: kubernetes/production/
production-integration-testing:
if: github.ref == 'refs/heads/master'
name: Production Integration testing
needs: prod-deploy
runs-on: ubuntu-latest
steps:
- name : Test URL Output Using CURL and JQ
env:
URL: ${{ needs.prod-deploy.outputs.application-url }}
run: |
echo $URL
echo "--------------------------"
curl https://$URL/live -s -k | jq -r .status | grep -i live
continue-on-error: true