Skip to content

Change badge to reflect buildkite builds (#2859) #1

Change badge to reflect buildkite builds (#2859)

Change badge to reflect buildkite builds (#2859) #1

Workflow file for this run

name: SonarCloud
on:
workflow_dispatch:
push:
branches:
- main
workflow_run:
workflows: ["CodeCoverage Build"]
types:
- completed
jobs:
coverage:
name: SonarCloud
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
repository: '${{ github.event.workflow_run.head_repository.full_name }}'
ref: '${{ github.event.workflow_run.head_branch }}'
- name: 'Download artifact'
uses: actions/github-script@v3.1.0
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 == "test-coverage"
})[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}}/test-coverage.zip', Buffer.from(download.data));
- run: unzip -o test-coverage.zip -d build
- name: Retrieve the pr number
id: pr-number
uses: actions/github-script@v6
with:
result-encoding: string
script: |
var fs = require('fs');
var pr_number = Number(fs.readFileSync('./build/pull_request_number'));
return pr_number;
- name: Retrieve the pr base
id: pr-base
uses: actions/github-script@v6
with:
result-encoding: string
script: |
var fs = require('fs');
var pr_base = fs.readFileSync('./build/pull_request_base');
return pr_base;
- name: Retrieve the pr branch
id: pr-branch
uses: actions/github-script@v6
with:
result-encoding: string
script: |
var fs = require('fs');
var pr_base = fs.readFileSync('./build/pull_request_branch');
return pr_base;
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.pullrequest.key=${{ steps.pr-number.outputs.result }}
-Dsonar.pullrequest.branch=${{ steps.pr-branch.outputs.result }}
-Dsonar.pullrequest.base=${{ steps.pr-base.outputs.result }}
branch-coverage:
name: Branch SonarCloud
runs-on: ubuntu-latest
if: >
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Run Unit tests
env:
TEST_COVERAGE: 'true'
run: |
make test-unit junit-report
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}