From 4b021cdbd3194b50da5ba9a01da5bced4bfde06e Mon Sep 17 00:00:00 2001 From: princegupta1131 <114015020+princegupta1131@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:52:50 +0530 Subject: [PATCH] ED-4000 feat: Github actions instead of Jenkins-test-sonar-fix --- .github/workflows/build-upload-artifact.yml | 56 +++++++++++++++++++++ .github/workflows/cd-run.yml | 31 ++++++++++++ .github/workflows/ci-cd.yml | 34 ++++++------- 3 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/build-upload-artifact.yml create mode 100644 .github/workflows/cd-run.yml diff --git a/.github/workflows/build-upload-artifact.yml b/.github/workflows/build-upload-artifact.yml new file mode 100644 index 00000000000..22f42a373b4 --- /dev/null +++ b/.github/workflows/build-upload-artifact.yml @@ -0,0 +1,56 @@ +name: Build and Upload Artifact + +on: + push: + branches: + - "deploy" # Trigger on push to any branch + pull_request: + branches: + - "deploy" # Trigger on pull request to any branch + +jobs: + build_and_deploy: + name: Build and Upload Artifact Job # Define the name of the job + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 # Checkout the repository code + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "18.20.2" # Set up Node.js version 18 + + - name: Customize dependencies + if: ${{ env.WL_Customization != null }} # Conditional step execution + run: | + git clone --recurse-submodules ${WL_Customization} sunbirded-portal # Clone repository with submodules + cp -r sunbirded-portal/images/ src/app/client/src/assets # Copy images to client assets + cp -r sunbirded-portal/resourceBundles/data/ src/app/resourcebundles/ # Copy resource bundle data + env: + WL_Customization: ${{ github.event.inputs.WL_Customization }} # Set environment variable WL_Customization + + - name: Build and Create Docker Image + run: | + commit_hash=$(git rev-parse --short HEAD) # Get commit hash + build_tag=$(echo "${{ github.ref }}" | rev | cut -d/ -f1 | rev)_${commit_hash}_${GITHUB_RUN_NUMBER} # Generate build tag + echo "build_tag: $build_tag" # Print build tag + bash ./build.sh "${build_tag}" "${{ env.NODE_NAME }}" "test" true false "" # Run build script with parameters + env: + NODE_NAME: "18.20.2" # Set environment variable NODE_NAME + + - name: Archive Artifacts + uses: actions/upload-artifact@v2 + with: + name: metadata + path: metadata.json + + - name: Archive CDN assets if required + if: ${{ github.event.inputs.buildCdnAssests == 'true' }} # Conditional step execution + run: | + rm -rf cdn_assets # Remove existing CDN assets directory + mkdir cdn_assets # Create CDN assets directory + cp -r src/app/dist-cdn/* cdn_assets/ # Copy CDN assets + zip -Jr cdn_assets.zip cdn_assets # Create zip file of CDN assets + echo "##vso[task.uploadfile]cdn_assets.zip" # Upload CDN assets zip file diff --git a/.github/workflows/cd-run.yml b/.github/workflows/cd-run.yml new file mode 100644 index 00000000000..d9f0782b1fc --- /dev/null +++ b/.github/workflows/cd-run.yml @@ -0,0 +1,31 @@ +name: Use the data + +on: + workflow_run: + workflows: [Upload data] + types: + - completed + +jobs: + download: + runs-on: ubuntu-latest + steps: + - 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 - + + # 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 diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9672b698e77..aaa2108d6de 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -80,25 +80,25 @@ jobs: # 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" + # - 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: