From 421533bfa1d762f87ee0edf785031e75ded58454 Mon Sep 17 00:00:00 2001 From: princegupta1131 <114015020+princegupta1131@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:06:45 +0530 Subject: [PATCH] ED-4000 feat: Github actions instead of Jenkins-test --- .circleci/config.yml | 57 +++++++++++++ .github/workflows/build-deploy.yml | 4 +- .github/workflows/ci-cd.yml | 124 ++++++++++++++--------------- 3 files changed, 119 insertions(+), 66 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e69de29bb2d..681cfa58b5b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 + \ No newline at end of file diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index 55bbe5a0f11..ede1f295fa6 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -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: diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index b34fbd2c41a..b9ad172c8fd 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 }} @@ -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