diff --git a/.github/workflows/Code-Quality-check.yml b/.github/workflows/Code-Quality-check.yml new file mode 100644 index 000000000..c10f757e4 --- /dev/null +++ b/.github/workflows/Code-Quality-check.yml @@ -0,0 +1,100 @@ +name: Pull Request Checks + +on: + pull_request: + branches: + - '*' +permissions: + pull-requests: write + contents: read + issues: write + checks: write + statuses: write + +jobs: + test-and-quality: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Important for SonarQube to get full history + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: 'maven' + + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build and Run Tests + run: | + mvn clean install -DskipTests=true \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + echo "Running the test cases" + cd content-api/content-service/ + mvn clean test org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent test org.jacoco:jacoco-maven-plugin:0.8.8:report \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: 'content-api/content-service/target/surefire-reports/*.xml' + + - name: Publish Test Results + if: always() + uses: dorny/test-reporter@v1 + with: + name: Test Results + path: content-api/content-service/target/surefire-reports/*.xml + reporter: java-junit + fail-on-error: true + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + + - name: SonarCloud Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + working-directory: content-api/content-service + run: | + mvn sonar:sonar \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} \ + -Dsonar.projectKey=Sunbird-Knowlg_knowledge-platform \ + -Dsonar.organization=sunbird-knowlg-1 \ + -Dsonar.host.url=https://sonarcloud.io \ + -Dsonar.coverage.jacoco.xmlReportPaths=content-api/content-service/target/site/jacoco/jacoco.xml + + + - name: Comment PR with SonarQube Results + uses: actions/github-script@v6 + if: github.event_name == 'pull_request' && always() + with: + script: | + const sonarUrl = `https://sonarcloud.io/dashboard?id=Sunbird-Knowlg_knowledge-platform`; + const message = `### Quality Gate Results + Check the detailed SonarQube analysis at: ${sonarUrl}`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: message + }); \ No newline at end of file