Skip to content

Commit

Permalink
ED-4000 feat: Github actions instead of Jenkins-test
Browse files Browse the repository at this point in the history
  • Loading branch information
princegupta1131 committed Jun 11, 2024
1 parent d9c882b commit 421533b
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 66 deletions.
57 changes: 57 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: 2.1
jobs:
build:
docker:
- image: cimg/node:18.16.0
steps:
- checkout
- run:
name: run build file
command: /bin/bash -x build.sh ${CIRCLE_SHA1} test
test-cases:
working_directory: ~/portal/src/app/client
docker:
# Ref: https://circleci.com/docs/2.0/configuration-reference/#available-machine-images
- image: cimg/node:18.16.0
resource_class: large
steps:
- checkout:
path: ~/portal
- run:
# Using NodeJS version 16
name: Installing prerequisites
command: |-
node --version
- run:
name: ignore-engines
command: 'yarn config set ignore-engines true'
- run:
name: Installing npm deps
command: 'yarn install'
- save_cache: # special step to save the dependency cache
key: dependency-cache-portal-{{ checksum "package.json" }}
paths:
- ./node_modules
# - run:
# name: ng lint and building
# command: 'mkdir -p /tmp/logs && node --max_old_space_size=6000 ./node_modules/@angular/cli/bin/ng build --prod --optimization=false --buildOptimizer=false | tee /tmp/logs/build.log'
- run:
name: Executing test cases using JEST
command: 'npm run test:ci'
- run:
name: Install Sonar Scanner
command: |
cd /tmp
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip || sudo apt install unzip -y
unzip sonar-scanner-cli-5.0.1.3006-linux.zip
cd -
- run:
name: run sonar scanner
command: 'cd ~/portal && /tmp/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner'
workflows:
version: 2
build_and_test:
jobs:
- test-cases

4 changes: 2 additions & 2 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Build and Deploy
on:
push:
branches:
- "*" # Trigger on push to any branch
- "deploy" # Trigger on push to any branch
pull_request:
branches:
- "*" # Trigger on pull request to any branch
- "deploy" # Trigger on pull request to any branch

jobs:
build_and_deploy:
Expand Down
124 changes: 60 additions & 64 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: CI/CD
on:
push:
branches:
- "test" # Trigger on push to any branch
- "*" # Trigger on push to any branch
pull_request:
branches:
- "trst" # Trigger on pull request to any branch
- "*" # Trigger on pull request to any branch

jobs:
build-and-test:
Expand All @@ -27,17 +27,14 @@ jobs:
# - name: Install client dependencies
# working-directory: src/app/client
# run: yarn install --no-progress --production=true

# # Build the client
# - name: Build client
# working-directory: src/app/client
# run: npm run build

# # List all files after the build
# - name: List all files after build
# working-directory: src/app/client
# run: find . -type f

# # Check if the dist directory exists and list its contents
# - name: Check if dist directory exists and list contents
# working-directory: src/app/client
Expand All @@ -48,7 +45,6 @@ jobs:
# else
# echo "dist directory does not exist"
# fi

# # Move index.html to index.ejs if it exists
# - name: Move index.html to index.ejs if it exists
# working-directory: src/app/client
Expand All @@ -58,22 +54,18 @@ jobs:
# else
# echo "File dist/index.html does not exist"
# fi

# # Set up server directories
# - name: Set up server directories
# run: mkdir -p $GITHUB_WORKSPACE/app_dist

# # Copy server files to the destination directory
# - name: Copy server files
# run: |
# cp -r src/app/libs src/app/helpers src/app/proxy src/app/resourcebundles src/app/package.json src/app/framework.config.js src/app/sunbird-plugins src/app/routes src/app/constants src/app/controllers src/app/server.js $GITHUB_WORKSPACE/app_dist/
# shell: /usr/bin/bash -e {0}

# # Install server dependencies
# - name: Install server dependencies
# working-directory: ${{ github.workspace }}/app_dist
# run: yarn install --ignore-engines --no-progress --production=true

# # Run server build script
# - name: Run server build script
# working-directory: ${{ github.workspace }}/app_dist
Expand All @@ -85,27 +77,31 @@ jobs:
# yarn config set ignore-engines true
# yarn install
# npm run test:ci
# Debug: Print the masked SONAR_TOKEN
- name: Print SONAR_TOKEN
run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123"

# Install Sonar Scanner
# - name: Install Sonar Scanner
# run: |
# cd /tmp
# wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
# sudo apt-get install -y unzip
# unzip sonar-scanner-cli-5.0.1.3006-linux.zip
# cd -
#Install Sonar Scanner
- name: Install Sonar Scanner
run: |
cd /tmp
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
sudo apt-get install -y unzip
unzip sonar-scanner-cli-5.0.1.3006-linux.zip
cd -
# Run SonarScanner for frontend (Angular)
- name: Run SonarScanner for frontend
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
/tmp/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
-Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
-Dsonar.sources=src/app/client/src \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=sunbird-ed \
-Dsonar.login=$SONAR_TOKEN
# # Run SonarScanner for frontend (Angular)
# - name: Run SonarScanner for frontend
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: |
# /tmp/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
# -Dsonar.projectKey=your_frontend_project_key \
# -Dsonar.sources=src \
# -Dsonar.host.url=https://sonarcloud.io \
# -Dsonar.organization=your_organization \
# -Dsonar.login=$SONAR_TO
# - name: Run Sonar Scanner
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand All @@ -118,40 +114,40 @@ jobs:
# -Dsonar.login=$SONAR_TOKEN

# Install SonarScanner globally using npm
- name: Install SonarScanner
run:
npm install -g sonarqube-scanner
# - name: Install SonarScanner
# run:
# npm install -g sonarqube-scanner

# Check if SONAR_TOKEN is set
- name: Check SONAR_TOKEN
run: |
if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then
echo "Error: SONAR_TOKEN is not set."
else
echo "SONAR_TOKEN is set."
fi
# # Check if SONAR_TOKEN is set
# - name: Check SONAR_TOKEN
# run: |
# if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then
# echo "Error: SONAR_TOKEN is not set."

# Debug: Print the masked SONAR_TOKEN
- name: Print SONAR_TOKEN
run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123"
# Ensure sonar-project.properties exists and print its content for debugging
- name: Check sonar-project.properties
run: |
if [ -f sonar-project.properties ]; then
echo "Found sonar-project.properties"
cat sonar-project.properties
else
echo "sonar-project.properties not found"
fi
# Run SonarScanner in the specified directory
- name: Run SonarScanner
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
-Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
-Dsonar.organization=sunbird-ed \
-Dsonar.sources=src/app/client/src \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=$SONAR_TOKEN
# else
# echo "SONAR_TOKEN is set."
# fi

# Debug: Print the masked SONAR_TOKEN
# - name: Print SONAR_TOKEN
# run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123"
# # Ensure sonar-project.properties exists and print its content for debugging
# - name: Check sonar-project.properties
# run: |
# if [ -f sonar-project.properties ]; then
# echo "Found sonar-project.properties"
# cat sonar-project.properties
# else
# echo "sonar-project.properties not found"
# fi
# # Run SonarScanner in the specified directory
# - name: Run SonarScanner
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: |
# sonar-scanner \
# -Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
# -Dsonar.organization=sunbird-ed \
# -Dsonar.sources=src/app/client/src \
# -Dsonar.host.url=https://sonarcloud.io \
# -Dsonar.login=$SONAR_TOKEN

0 comments on commit 421533b

Please sign in to comment.