From a9e64c4be44bb07e89408e8eb99ee3a72200ce2a Mon Sep 17 00:00:00 2001 From: Anas WS Date: Wed, 10 Apr 2024 17:32:57 +0530 Subject: [PATCH] fix: sonar reverted back --- .github/workflows/ci.yml | 13 ++--- .github/workflows/jest-coverage.yml | 2 +- .github/workflows/sonar.yml | 73 ++++------------------------- 3 files changed, 16 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 163a01d..76b936c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,7 @@ name: React Template CI - on: pull_request: branches: [master, qa, develop] - jobs: build-and-test: name: Build & Test @@ -33,9 +31,8 @@ jobs: - name: Build run: yarn build:prod - # Upload coverage artifacts if needed (optional) - # - name: Upload code coverage - # uses: actions/upload-artifact@v2 - # with: - # name: coverage - # path: coverage/ + - name: Upload code coverage + uses: actions/upload-artifact@v2 + with: + name: coverage + path: coverage/ diff --git a/.github/workflows/jest-coverage.yml b/.github/workflows/jest-coverage.yml index ded8719..30b7d55 100644 --- a/.github/workflows/jest-coverage.yml +++ b/.github/workflows/jest-coverage.yml @@ -1,6 +1,6 @@ name: Jest Coverage Report with Annotations (CI) on: - pull_request_target: + pull_request: branches: - master - qa diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index b0693a2..8c92136 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -1,4 +1,4 @@ -name: SonarCloud Analysis +name: SonarQube Analysis on: workflow_run: @@ -7,74 +7,21 @@ on: jobs: sonar-analysis: - name: SonarCloud Analysis + name: SonarQube Analysis runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - - name: Download code coverage - uses: actions/github-script@v4 + - name: Download code coverage artifact + uses: actions/download-artifact@v2 with: - script: | - const { data: artifacts } = await github.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id - }); + name: coverage + path: coverage - const coverageArtifact = artifacts.find(artifact => artifact.name === 'coverage'); - - if (!coverageArtifact) { - console.log('Coverage artifact not found.'); - return; - } - - const downloadUrl = coverageArtifact.archive_download_url; - const downloadPath = `${{ github.workspace }}/coverage.zip`; - - async function downloadFile(url, path) { - const https = require('https'); - const fs = require('fs'); - - const file = fs.createWriteStream(path); - - return new Promise((resolve, reject) => { - https.get(url, response => { - response.pipe(file); - file.on('finish', () => { - file.close(); - resolve(); - }); - }).on('error', error => { - fs.unlinkSync(path); - reject(error.message); - }); - }); - } - await downloadFile(downloadUrl, downloadPath); - - async function execCmd(cmd) { - const { exec } = require('child_process'); - - return new Promise((resolve, reject) => { - exec(cmd, (error, stdout, stderr) => { - if (error) { - console.error(`exec error: ${error}`); - reject(error); - } else { - console.log(stdout); - resolve(); - } - }); - }); - } - const unzipCmd = `unzip ${downloadPath} -d coverage`; - await execCmd(unzipCmd); - - - name: SonarCloud Scan - uses: sonarsource/sonarcloud-github-action@master + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} \ No newline at end of file