Skip to content

Commit 0012a82

Browse files
authored
ci: publish coverage report to codacy (#439)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent aa86ab7 commit 0012a82

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

.github/workflows/python.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ env:
2121
REPORTS_DIR: CI_reports
2222
PYTHON_VERSION_DEFAULT: "3.11"
2323
POETRY_VERSION: "1.4.1"
24+
TESTS_REPORTS_ARTIFACT: tests-reports
2425

2526
jobs:
2627
coding-standards:
@@ -31,23 +32,19 @@ jobs:
3132
- name: Checkout
3233
# see https://github.com/actions/checkout
3334
uses: actions/checkout@v4
34-
3535
- name: Setup Python Environment
3636
# see https://github.com/actions/setup-python
3737
uses: actions/setup-python@v4
3838
with:
3939
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
4040
architecture: 'x64'
41-
4241
- name: Install poetry
4342
# see https://github.com/marketplace/actions/setup-poetry
4443
uses: Gr1N/setup-poetry@v8
4544
with:
4645
poetry-version: ${{ env.POETRY_VERSION }}
47-
4846
- name: Install dependencies
4947
run: poetry install --no-root
50-
5148
- name: Run tox
5249
run: poetry run tox -e flake8 -s false
5350

@@ -71,32 +68,26 @@ jobs:
7168
- name: Checkout
7269
# see https://github.com/actions/checkout
7370
uses: actions/checkout@v4
74-
7571
- name: Setup Python Environment
7672
# see https://github.com/actions/setup-python
7773
uses: actions/setup-python@v4
7874
with:
7975
python-version: ${{ matrix.python-version }}
8076
architecture: 'x64'
81-
8277
- name: Install poetry
8378
# see https://github.com/marketplace/actions/setup-poetry
8479
uses: Gr1N/setup-poetry@v8
8580
with:
8681
poetry-version: ${{ env.POETRY_VERSION }}
87-
8882
- name: Install dependencies
8983
run: poetry install --no-root
90-
9184
- name: Run tox
9285
run: poetry run tox -e mypy-${{ matrix.toxenv-factor }} -s false
9386

9487
build-and-test:
9588
name: Test (${{ matrix.os }} py${{ matrix.python-version }} ${{ matrix.toxenv-factor }})
9689
runs-on: ${{ matrix.os }}
9790
timeout-minutes: 15
98-
env:
99-
REPORTS_ARTIFACT: tests-reports
10091
strategy:
10192
fail-fast: false
10293
matrix:
@@ -118,57 +109,71 @@ jobs:
118109
run: |
119110
git config --global core.autocrlf false
120111
git config --global core.eol lf
121-
122112
- name: Checkout
123113
# see https://github.com/actions/checkout
124114
uses: actions/checkout@v4
125-
126115
- name: Create reports directory
127116
run: mkdir ${{ env.REPORTS_DIR }}
128-
129117
- name: Setup Python Environment
130118
# see https://github.com/actions/setup-python
131119
uses: actions/setup-python@v4
132120
with:
133121
python-version: ${{ matrix.python-version }}
134122
architecture: 'x64'
135-
136123
- name: Validate Python Environment
137124
shell: python
138125
run: |
139126
import sys
140127
print('Python %s on %s in %s' % (sys.version, sys.platform, sys.getdefaultencoding()))
141-
142128
- name: Install poetry
143129
# see https://github.com/marketplace/actions/setup-poetry
144130
uses: Gr1N/setup-poetry@v8
145131
with:
146132
poetry-version: ${{ env.POETRY_VERSION }}
147-
148133
- name: Install dependencies
149134
run: poetry install --no-root
150-
151135
- name: Ensure build successful
152136
run: poetry build
153-
154137
- name: Run tox
155138
run: poetry run tox -e py-${{ matrix.toxenv-factor }} -s false
156-
157139
- name: Generate coverage reports
158-
run: >
159-
poetry run coverage report &&
160-
poetry run coverage xml -o ${{ env.REPORTS_DIR }}/coverage-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.toxenv-factor }}.xml &&
161-
poetry run coverage html -d ${{ env.REPORTS_DIR }}
162-
140+
shell: bash
141+
run: |
142+
set -eux
143+
poetry run coverage report
144+
poetry run coverage xml -o "$REPORTS_DIR/coverage.${{ matrix.os }}_py${{ matrix.python-version }}_${{ matrix.toxenv-factor }}.cobertura.xml"
145+
# poetry run coverage lcov -o "$REPORTS_DIR/coverage.${{ matrix.os }}_py${{ matrix.python-version }}_${{ matrix.toxenv-factor }}.lcov.xml"
163146
- name: Artifact reports
164147
if: ${{ ! cancelled() }}
165148
# see https://github.com/actions/upload-artifact
166149
uses: actions/upload-artifact@v3
167150
with:
168-
name: ${{ env.REPORTS_ARTIFACT }}
151+
name: ${{ env.TESTS_REPORTS_ARTIFACT }}
169152
path: ${{ env.REPORTS_DIR }}
170153
if-no-files-found: error
171154

155+
report-coverage:
156+
name: Publish test coverage
157+
needs: [ "build-and-test" ]
158+
runs-on: ubuntu-latest
159+
timeout-minutes: 5
160+
steps:
161+
- name: fetch test artifacts
162+
# see https://github.com/actions/download-artifact
163+
uses: actions/download-artifact@v3
164+
with:
165+
name: ${{ env.TESTS_REPORTS_ARTIFACT }}
166+
path: ${{ env.REPORTS_DIR }}
167+
- name: Run codacy-coverage-reporter
168+
env:
169+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
170+
if: ${{ env.CODACY_PROJECT_TOKEN != '' }} ## see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets
171+
# see https://github.com/codacy/codacy-coverage-reporter-action
172+
uses: codacy/codacy-coverage-reporter-action@v1
173+
with:
174+
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
175+
coverage-reports: ${{ env.REPORTS_DIR }}/coverage.*
176+
172177
examples:
173178
name: Examples
174179
runs-on: ubuntu-latest

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Python Library for generating CycloneDX
22

3-
[![shield_gh-workflow-test]][link_gh-workflow-test]
4-
[![shield_rtfd]][link_rtfd]
53
[![shield_pypi-version]][link_pypi]
64
[![shield_conda-forge-version]][link_conda-forge]
5+
[![shield_rtfd]][link_rtfd]
6+
[![shield_gh-workflow-test]][link_gh-workflow-test]
7+
[![shield_coverage]][link_codacy]
78
[![shield_license]][license_file]
89
[![shield_website]][link_website]
910
[![shield_slack]][link_slack]
@@ -57,6 +58,7 @@ See the [LICENSE][license_file] file for the full license.
5758
[contributing_file]: https://github.com/CycloneDX/cyclonedx-python-lib/blob/master/CONTRIBUTING.md
5859

5960
[shield_gh-workflow-test]: https://img.shields.io/github/actions/workflow/status/CycloneDX/cyclonedx-python-lib/python.yml?branch=main&logo=GitHub&logoColor=white "build"
61+
[shield_coverage]: https://img.shields.io/codacy/coverage/1f9d451e9cdc49ce99c2a1247adab341?logo=Codacy&logoColor=white "test coverage"
6062
[shield_pypi-version]: https://img.shields.io/pypi/v/cyclonedx-python-lib?logo=pypi&logoColor=white&label=PyPI "PyPI"
6163
[shield_conda-forge-version]: https://img.shields.io/conda/vn/conda-forge/cyclonedx-python-lib?logo=anaconda&logoColor=white&label=conda-forge "conda-forge"
6264
[shield_rtfd]: https://img.shields.io/readthedocs/cyclonedx-python-library?logo=readthedocs&logoColor=white "Read the Docs"
@@ -69,6 +71,7 @@ See the [LICENSE][license_file] file for the full license.
6971
[link_pypi]: https://pypi.org/project/cyclonedx-python-lib/
7072
[link_conda-forge]: https://anaconda.org/conda-forge/cyclonedx-python-lib
7173
[link_rtfd]: https://cyclonedx-python-library.readthedocs.io/en/latest/?badge=latest
74+
[link_codacy]: https://app.codacy.com/gh/CycloneDX/cyclonedx-python-lib
7275
[link_website]: https://cyclonedx.org/
7376
[link_slack]: https://cyclonedx.org/slack/invite
7477
[link_discussion]: https://groups.io/g/CycloneDX

0 commit comments

Comments
 (0)