From e8b83b6a82146c2ba99cd94708a176a8ba0bc854 Mon Sep 17 00:00:00 2001 From: Anas WS Date: Wed, 10 Apr 2024 16:18:54 +0530 Subject: [PATCH] fix: sonar updated --- .github/workflows/sonar.yml | 68 +++---------------------------------- 1 file changed, 5 insertions(+), 63 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index f8afa34..72f240c 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -14,33 +14,13 @@ jobs: - 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: - github-token: ${{ secrets.GITHUB_TOKEN }} - 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`; - - await downloadFile(downloadUrl, downloadPath); - - const unzipCmd = `unzip ${downloadPath} -d coverage`; - await execCmd(unzipCmd); - - - name: SonarCloud Scan + - name: Setup SonarCloud Scan uses: sonarsource/sonarcloud-github-action@master env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -57,41 +37,3 @@ jobs: -Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info -Dsonar.testExecutionReportPaths=./reports/test-report.xml -Dsonar.sourceEncoding=UTF-8 - -# Helper function to download and extract artifacts -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); - }); - }); -} - -# Helper function to execute shell commands -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(); - } - }); - }); -}