Skip to content

Commit 6c57dea

Browse files
authored
ci: add lint workflow and unify coverage reporting (#1517)
* ci: add lint workflow and unify coverage reporting - Introduced `.github/workflows/lint.yml` for running pre-commit hooks on PRs and pushes to main/develop branches. - Updated `_test.yml` to support coverage reporting and uploading to Codecov, controlled via `with-coverage` input. - Enhanced `pr-tests.yml` to run tests with coverage for Python 3.11. - Added `pr-tests-skip.yml` to skip tests for non-code PRs. - Removed obsolete `test-coverage-report.yml` workflow.
1 parent b3f2839 commit 6c57dea

File tree

5 files changed

+96
-50
lines changed

5 files changed

+96
-50
lines changed

.github/workflows/_test.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ on:
2323
required: false
2424
default: false
2525
type: boolean
26+
with-coverage:
27+
description: "Whether to run tests with coverage reporting"
28+
required: false
29+
default: false
30+
type: boolean
2631

2732
defaults:
2833
run:
@@ -89,8 +94,23 @@ jobs:
8994
poetry install --with dev
9095
fi
9196
92-
- name: Run pre-commit hooks
93-
run: poetry run make pre_commit
97+
- name: Run pytest with coverage
98+
if: inputs.with-coverage
99+
run: poetry run pytest --cov=nemoguardrails tests/ --cov-report=xml:coverage.xml -v
94100

95-
- name: Run pytest
101+
- name: Run pytest without coverage
102+
if: inputs.with-coverage == false
96103
run: poetry run pytest -v
104+
105+
- name: Upload coverage to Codecov
106+
if: inputs.with-coverage
107+
uses: codecov/codecov-action@v5
108+
with:
109+
directory: ./coverage/reports/
110+
env_vars: PYTHON
111+
fail_ci_if_error: true
112+
files: ./coverage.xml
113+
flags: python
114+
name: codecov-umbrella
115+
token: ${{ secrets.CODECOV_TOKEN }}
116+
verbose: true

.github/workflows/lint.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
workflow_dispatch:
10+
11+
env:
12+
POETRY_VERSION: 1.8.2
13+
PYTHON_VERSION: "3.11"
14+
15+
jobs:
16+
lint:
17+
name: Lint Code
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ env.PYTHON_VERSION }}
26+
27+
- name: Get full Python version
28+
id: full-python-version
29+
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT
30+
31+
- name: Bootstrap poetry
32+
run: |
33+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${{ env.POETRY_VERSION }} python -
34+
echo "$HOME/.local/bin" >> $GITHUB_PATH
35+
36+
- name: Configure poetry
37+
run: poetry config virtualenvs.in-project true
38+
39+
- name: Set up cache
40+
uses: actions/cache@v4
41+
id: cache
42+
with:
43+
path: .venv
44+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
45+
46+
- name: Ensure cache is healthy
47+
if: steps.cache.outputs.cache-hit == 'true'
48+
run: timeout 10s poetry run pip --version || rm -rf .venv
49+
50+
- name: Install dependencies
51+
run: poetry install --with dev
52+
53+
- name: Run pre-commit hooks
54+
run: poetry run make pre_commit
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Skip PR Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/*.md"
7+
- ".github/**"
8+
9+
jobs:
10+
pr-tests-summary:
11+
name: PR Tests Summary
12+
runs-on: ubuntu-latest
13+
steps:
14+
- run: echo "Tests skipped (no code changes)"

.github/workflows/pr-tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: PR Tests
22

33
on:
44
pull_request:
5-
# we don't ignore markdkowns to run pre-commits
65
paths-ignore:
6+
- "**/*.md"
77
- ".github/**"
88

99
jobs:
@@ -15,12 +15,16 @@ jobs:
1515
include:
1616
- os: Ubuntu
1717
image: ubuntu-latest
18+
- python-version: "3.11"
19+
with-coverage: true
1820
fail-fast: false
1921
uses: ./.github/workflows/_test.yml
22+
secrets: inherit
2023
with:
2124
os: ${{ matrix.os }}
2225
image: ${{ matrix.image }}
2326
python-version: ${{ matrix.python-version }}
27+
with-coverage: ${{ matrix.with-coverage || false }}
2428
pr-tests-summary:
2529
name: PR Tests Summary
2630
needs: pr-tests-matrix

.github/workflows/test-coverage-report.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)