Skip to content

Commit

Permalink
fix: sonar reverted back
Browse files Browse the repository at this point in the history
  • Loading branch information
anasnadeemws committed Apr 10, 2024
1 parent cf9edb1 commit a9e64c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 72 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: React Template CI

on:
pull_request:
branches: [master, qa, develop]

jobs:
build-and-test:
name: Build & Test
Expand Down Expand Up @@ -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/
2 changes: 1 addition & 1 deletion .github/workflows/jest-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Jest Coverage Report with Annotations (CI)
on:
pull_request_target:
pull_request:
branches:
- master
- qa
Expand Down
73 changes: 10 additions & 63 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SonarCloud Analysis
name: SonarQube Analysis

on:
workflow_run:
Expand All @@ -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 }}

0 comments on commit a9e64c4

Please sign in to comment.