Skip to content

Commit

Permalink
fix: sonar updated
Browse files Browse the repository at this point in the history
  • Loading branch information
anasnadeemws committed Apr 10, 2024
1 parent e047428 commit e8b83b6
Showing 1 changed file with 5 additions and 63 deletions.
68 changes: 5 additions & 63 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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();
}
});
});
}

0 comments on commit e8b83b6

Please sign in to comment.