Skip to content

Commit

Permalink
fix: reverted back sonar.yml to check if auto trigger happens
Browse files Browse the repository at this point in the history
  • Loading branch information
anasnadeemws committed Apr 10, 2024
1 parent e8b83b6 commit d390eea
Showing 1 changed file with 58 additions and 17 deletions.
75 changes: 58 additions & 17 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,67 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Download code coverage artifact
uses: actions/download-artifact@v2
- name: Download code coverage
uses: actions/github-script@v4
with:
name: coverage
path: coverage
script: |
const { data: artifacts } = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id
});
- name: Setup SonarCloud Scan
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
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: >
-Dsonar.organization=wednesday-solutions
-Dsonar.projectKey=wednesday-solutions_react-graphql-ts-template_AY7GxkO6B2n8RRmGoU1i
-Dsonar.language=ts
-Dsonar.sources=.
-Dsonar.tests=app
-Dsonar.exclusions=**/.storybook,**/internals,**/server
-Dsonar.test.inclusions=**/*.test.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
-Dsonar.testExecutionReportPaths=./reports/test-report.xml
-Dsonar.sourceEncoding=UTF-8

0 comments on commit d390eea

Please sign in to comment.