Comment on the pull request, grab coverage report and upload to SonarCloud #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment on the pull request, grab coverage report and upload to SonarCloud | |
# read-write repo token | |
# access to secrets | |
on: | |
workflow_run: | |
workflows: ["Test API Generate Coverage, and Upload Newman and Coverage Artifacts"] | |
types: | |
- completed | |
jobs: | |
upload: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: 'Download artifact' | |
uses: actions/[email protected] | |
with: | |
script: | | |
var artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr" | |
})[0]; | |
var download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | |
- run: unzip pr.zip | |
- name: 'Comment on PR' | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var fs = require('fs'); | |
var issue_number = Number(fs.readFileSync('./NR')); | |
await github.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: 'Everything is OK. Thank you for the PR! - another test' | |
}); | |
SonarCloudAnalysis-API: | |
name: SonarCloud Analysis API | |
# needs: test_api | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Important to fetch all history for accurate blame information | |
- name: 'Download artifact' | |
uses: actions/[email protected] | |
with: | |
script: | | |
var artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "coverage-report" | |
})[0]; | |
var download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/coverage-report.zip', Buffer.from(download.data)); | |
- run: unzip coverage-report.zip | |
# - name: Download lcov artifact | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: coverage-report | |
- name: Move lcov.info to api/source | |
run: mv lcov.info ./api/source/ | |
- name: Analyze API with SonarCloud | |
uses: SonarSource/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_API }} # Needed to push to SonarCloud | |
with: | |
# Additional arguments for the sonarcloud scanner | |
projectBaseDir: ./api/source | |
args: -Dsonar.projectKey=cd-rite_stig-manager | |
-Dsonar.projectName=cd-rite_stig-manager | |
-Dsonar.organization=cd-rite | |
-Dsonar.inclusions=**/*.js | |
-Dsonar.exclusions=**/node_modules/**,**/coverage-report/** | |
-Dsonar.javascript.lcov.reportPaths=./lcov.info |