From 3834ed4d425651cddaa5cc8960335de1503350a8 Mon Sep 17 00:00:00 2001 From: saimanaswini-k Date: Mon, 19 Aug 2024 11:15:30 +0530 Subject: [PATCH] Feat : Workflow for github actions --- .github/workflows/build.yml | 99 ++++++++++++++++++++++++++++++ .github/workflows/pull-request.yml | 75 ++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..f5c62a8a4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,99 @@ +name: Build and Test + +on: + push: + tags: + - '*' + branches: + - master + - release-* + + +jobs: + Docker-build: + runs-on: ubuntu-latest + + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Restore Maven cache + uses: actions/cache@v3 + with: + path: ~/.m2 + key: lern-jobs-dependency-cache-${{ hashFiles('pom.xml') }} + restore-keys: | + lern-jobs-dependency-cache- + + - name: Install ImageMagick + run: | + sudo apt-get update || sudo apt-get update + sudo apt-get install -y imagemagick + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '11' + + - name: Build the code + run: mvn clean install -DskipTests + + - name: Execute coverage report + run: mvn clean scoverage:report + + - name: Save test results + if: always() + run: | + mkdir -p ~/test-results/junit/ + find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/test-results/junit/ \; + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2 + key: lern-jobs-dependency-cache-${{ hashFiles('pom.xml') }} + + - name: Store test results + uses: actions/upload-artifact@v3 + with: + name: test-results + path: ~/test-results + + - name: Setup Maven Action + uses: s4u/setup-maven-action@v1.2.1 + with: + maven-version: '3.6.3' + java-version: '11' + + - name: Verify Maven version + run: mvn -v + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build Docker Image + run: | + cd jobs-distribution + mvn package -Pbuild-docker-image -Drelease-version=${{ github.ref_name }} + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Run SonarQube analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + mvn verify -DskipTests=true sonar:sonar -Dlog4j.configuration=./logs sonar:sonar -Dsonar.projectKey=Sunbird-Lern_data-pipeline -Dsonar.organization=sunbird-lern -Dsonar.host.url=https://sonarcloud.io -Dsonar.java.binaries=$(find . -path '*/build/classes/java' | xargs | tr ' ' ',') -Dsonar.coverage.exclusions=**/notification-sdk/**,**/notification/domain/** -Dsonar.test.exclusions=**/notification-sdk/** -Dsonar.exclusions=**/**.java -Dsonar.scala.coverage.reportPaths=/home/circleci/lern/target/scoverage.xml \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 000000000..c53df5e53 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,75 @@ +name: Build and Test + +on: + pull_request: + types: [opened, synchronize] + + +jobs: + Run-test-cases: + runs-on: ubuntu-latest + + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Restore Maven cache + uses: actions/cache@v3 + with: + path: ~/.m2 + key: lern-jobs-dependency-cache-${{ hashFiles('pom.xml') }} + restore-keys: | + lern-jobs-dependency-cache- + + - name: Install ImageMagick + run: | + sudo apt-get update || sudo apt-get update + sudo apt-get install -y imagemagick + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '11' + + - name: Build the code + run: mvn clean install -DskipTests + + - name: Execute coverage report + run: mvn clean scoverage:report + + - name: Save test results + if: always() + run: | + mkdir -p ~/test-results/junit/ + find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/test-results/junit/ \; + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2 + key: lern-jobs-dependency-cache-${{ hashFiles('pom.xml') }} + + - name: Store test results + uses: actions/upload-artifact@v3 + with: + name: test-results + path: ~/test-results + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Run SonarQube analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + mvn verify -DskipTests=true sonar:sonar -Dlog4j.configuration=./logs sonar:sonar -Dsonar.projectKey=Sunbird-Lern_data-pipeline -Dsonar.organization=sunbird-lern -Dsonar.host.url=https://sonarcloud.io -Dsonar.java.binaries=$(find . -path '*/build/classes/java' | xargs | tr ' ' ',') -Dsonar.coverage.exclusions=**/notification-sdk/**,**/notification/domain/** -Dsonar.test.exclusions=**/notification-sdk/** -Dsonar.exclusions=**/**.java -Dsonar.scala.coverage.reportPaths=/home/circleci/lern/target/scoverage.xml \ No newline at end of file