Skip to content

Commit

Permalink
ci: add sonarcloud workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvieirasilva committed Sep 6, 2023
1 parent 7a69bb5 commit d421046
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 30 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Sonar

on:
workflow_run:
workflows: [Unit Tests]
types: [completed]

jobs:
sonar:
name: Sonar
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: 'Download code coverage'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "code-coverage"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/code-coverage.zip`, Buffer.from(download.data));
- name: 'Unzip code coverage'
run: unzip code-coverage.zip -d coverage
- 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=${{ github.event.workflow_run.pull_requests[0].number }}
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
60 changes: 30 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ name: Unit Tests

on:
push:
branches: [ main ]
branches: [master]
pull_request:
branches: [ main ]
branches: [master]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Set up Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.5.1

- name: Install dependencies
run: |
poetry install -v
- name: Run unit tests
env:
AWS_REGION: us-east-1
run: |
poetry run pytest tests/
- name: Coverage Report
uses: 5monkeys/cobertura-action@master
with:
path: reports/cov/coverage.xml
repo_token: ${{ secrets.GITHUB_TOKEN }}
minimum_coverage: 100
fail_below_threshold: true
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Set up Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.5.1

- name: Install dependencies
run: |
poetry install -v
- name: Run unit tests
env:
AWS_REGION: us-east-1
run: |
poetry run pytest tests/
- name: Upload code coverage
uses: actions/upload-artifact@v3
with:
name: code-coverage
path: coverage/coverage.xml

0 comments on commit d421046

Please sign in to comment.