From b8edf9ed672a3653872458f500b958a49152f067 Mon Sep 17 00:00:00 2001 From: princegupta1131 <114015020+princegupta1131@users.noreply.github.com> Date: Thu, 13 Jun 2024 01:10:58 +0530 Subject: [PATCH] ED-4000 feat: Github actions instead of Jenkins-test-sonar-fix --- .github/workflows/build-test.yml | 285 +++++++++++++++---------------- .github/workflows/sonar.yml | 61 +++---- 2 files changed, 157 insertions(+), 189 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index dc9130cb6f8..013ae28516f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,164 +1,151 @@ ---- -name: Preflight +name: Build on: - - pull_request - - push + push: + branches: + - "*" # Trigger on push to any branch + pull_request: + branches: + - "*" # Trigger on pull request to any branch + workflow_dispatch: # Manual trigger + pull_request_target: # This is to access secrets from forked PRs jobs: - preflight-job: - name: Preflight Step + build-and-test: runs-on: ubuntu-latest - steps: - - run: env -# name: Build - -# on: -# push: -# branches: -# - "*" # Trigger on push to any branch -# pull_request: -# branches: -# - "*" # Trigger on pull request to any branch -# workflow_dispatch: # Manual trigger -# pull_request_target: # This is to access secrets from forked PRs -# jobs: -# build-and-test: -# runs-on: ubuntu-latest - -# steps: -# # Checkout the repository to the runner -# - name: Checkout repository -# uses: actions/checkout@v3 + steps: + # Checkout the repository to the runner + - name: Checkout repository + uses: actions/checkout@v3 -# # Set up Node.js environment -# - name: Set up Node.js -# uses: actions/setup-node@v3 -# with: -# node-version: 18 + # Set up Node.js environment + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 -# # Install client dependencies -# - 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 -# run: | -# if [ -d dist ]; then -# echo "dist directory exists. Listing contents:" -# ls -l dist -# 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 -# run: | -# if [ -f dist/index.html ]; then -# mv dist/index.html dist/index.ejs -# 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 -# run: node helpers/resourceBundles/build.js -task="phraseAppPull" -# Execute test cases using JEST -# - name: Execute test cases using JEST -# working-directory: src/app/client -# run: | -# 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 client dependencies + # - 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 + # run: | + # if [ -d dist ]; then + # echo "dist directory exists. Listing contents:" + # ls -l dist + # 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 + # run: | + # if [ -f dist/index.html ]; then + # mv dist/index.html dist/index.ejs + # 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 + # run: node helpers/resourceBundles/build.js -task="phraseAppPull" + # Execute test cases using JEST + # - name: Execute test cases using JEST + # working-directory: src/app/client + # run: | + # 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.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.login=$SONAR_TOKEN -# - name: Run Sonar Scanner -# 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.organization=sunbird-ed \ -# -Dsonar.host.url=https://sonarcloud.io \ -# -Dsonar.login=$SONAR_TOKEN + # - name: Run Sonar Scanner + # 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.organization=sunbird-ed \ + # -Dsonar.host.url=https://sonarcloud.io \ + # -Dsonar.login=$SONAR_TOKEN -# Install SonarScanner globally using npm -# - name: Install SonarScanner -# run: -# npm install -g sonarqube-scanner + # Install SonarScanner globally using npm + # - 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." + # # 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 + # 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 + # 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 diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index aa720cb2fbc..3c03b5316a9 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -1,52 +1,33 @@ -name: Test +name: Use the data on: workflow_run: - workflows: - - Preflight + workflows: ["Build"] types: - completed jobs: - test-job: - name: Test Step + download: runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.workflow_run.head_branch }} - - run: git branch - - run: env -# name: Use the data + - name: Checkout repository + uses: actions/checkout@v3 -# on: -# workflow_run: -# workflows: ["Build"] -# types: -# - completed + - name: Print SONAR_TOKEN + run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123" -# jobs: -# download: -# runs-on: ubuntu-latest -# if: github.event.workflow_run.conclusion == 'success' -# steps: -# - name: Checkout repository -# uses: actions/checkout@v3 + # Install Sonar Scanner + - name: Install Sonar Scanner + run: | + sudo apt-get update && sudo apt-get install -y unzip + wget -O /tmp/sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip + unzip /tmp/sonar-scanner-cli.zip -d /tmp -# - name: Print SONAR_TOKEN -# run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123" - -# # Install Sonar Scanner -# - name: Install Sonar Scanner -# run: | -# sudo apt-get update && sudo apt-get install -y unzip -# wget -O /tmp/sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -# unzip /tmp/sonar-scanner-cli.zip -d /tmp - -# # 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.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.login=$SONAR_TOKEN