Skip to content

Commit 2fdab0e

Browse files
committed
ci: split workflows into push and PR variants
1 parent efee306 commit 2fdab0e

File tree

4 files changed

+110
-47
lines changed

4 files changed

+110
-47
lines changed

.github/workflows/lint-pr.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Lint & Type Checks
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
lint:
11+
name: Lint & types (ruff + mypy)
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [3.11]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install linters
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install httpx colorama types-colorama
29+
pip install ruff mypy
30+
31+
- name: Run ruff
32+
run: ruff check .
33+
34+
- name: Run mypy
35+
run: mypy user_scanner
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ name: Lint & Type Checks
22

33
on:
44
push:
5-
pull_request:
65
branches: [ main ]
76

87
permissions:
98
contents: read
109

1110
jobs:
1211
lint:
13-
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
1412
name: Lint & types (ruff + mypy)
1513
runs-on: ubuntu-latest
1614
strategy:
@@ -31,18 +29,8 @@ jobs:
3129
pip install httpx colorama types-colorama
3230
pip install ruff mypy
3331
34-
- name: Show installed linters
35-
run: |
36-
ruff --version || true
37-
mypy --version || true
38-
pip freeze | sed -n '1,200p'
39-
40-
- name: Run ruff (style/lint)
41-
run: |
42-
echo "==== Running ruff ===="
43-
ruff check . || { echo "Ruff failed"; exit 1; }
32+
- name: Run ruff
33+
run: ruff check .
4434

45-
- name: Run mypy (type checks)
46-
run: |
47-
echo "==== Running mypy ===="
48-
mypy user_scanner || { echo "Mypy found issues"; exit 1; }
35+
- name: Run mypy
36+
run: mypy user_scanner

.github/workflows/tests-pr.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Tests (pytest + coverage)
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
test:
11+
name: Test (pytest + coverage) — ${{ matrix.python-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.10"]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Show Python info
27+
run: |
28+
python --version
29+
which python
30+
python -m pip --version
31+
32+
- name: Cache pip
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.cache/pip
36+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }}
37+
restore-keys: |
38+
${{ runner.os }}-pip-
39+
40+
- name: Install package & test deps
41+
run: |
42+
python -m pip install --upgrade pip
43+
pip install .
44+
pip install pytest pytest-cov
45+
46+
- name: Show installed packages
47+
run: pip freeze | sed -n '1,200p'
48+
49+
- name: Run pytest with coverage
50+
run: |
51+
mkdir -p test-output
52+
pytest -vv --maxfail=1 --disable-warnings \
53+
--junitxml=test-output/report.xml \
54+
--cov=user_scanner \
55+
--cov-report=xml:test-output/coverage.xml \
56+
--cov-report=term
57+
58+
- name: Upload test artifacts
59+
if: always()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: test-reports-${{ matrix.python-version }}
63+
path: test-output
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ name: Tests (pytest + coverage)
22

33
on:
44
push:
5-
pull_request:
65
branches: [ main ]
76

87
permissions:
98
contents: read
109

1110
jobs:
1211
test:
13-
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
1412
name: Test (pytest + coverage) — ${{ matrix.python-version }}
1513
runs-on: ubuntu-latest
1614
strategy:
1715
matrix:
1816
python-version: ["3.10"]
17+
1918
steps:
2019
- name: Checkout
2120
uses: actions/checkout@v4
@@ -45,43 +44,21 @@ jobs:
4544
pip install .
4645
pip install pytest pytest-cov
4746
48-
- name: Show installed packages (top)
49-
run: |
50-
pip freeze | sed -n '1,200p'
47+
- name: Show installed packages
48+
run: pip freeze | sed -n '1,200p'
5149

52-
- name: Run pytest (verbose) with coverage and generate JUnit XML
50+
- name: Run pytest with coverage
5351
run: |
5452
mkdir -p test-output
5553
pytest -vv --maxfail=1 --disable-warnings \
5654
--junitxml=test-output/report.xml \
57-
--cov=user_scanner --cov-report=xml:test-output/coverage.xml --cov-report=term
58-
59-
- name: Show pytest junit xml (head)
60-
if: always()
61-
run: |
62-
echo "==== JUnit report (head) ===="
63-
sed -n '1,200p' test-output/report.xml || true
64-
echo "==== JUnit report (tail) ===="
65-
sed -n '200,400p' test-output/report.xml || true
55+
--cov=user_scanner \
56+
--cov-report=xml:test-output/coverage.xml \
57+
--cov-report=term
6658
67-
- name: Show coverage xml (head)
68-
if: always()
69-
run: |
70-
echo "==== Coverage XML (head) ===="
71-
sed -n '1,200p' test-output/coverage.xml || true
72-
73-
- name: Upload test & coverage artifacts
59+
- name: Upload test artifacts
7460
if: always()
7561
uses: actions/upload-artifact@v4
7662
with:
7763
name: test-reports-${{ matrix.python-version }}
7864
path: test-output
79-
80-
- name: (Optional) Upload coverage to Codecov
81-
if: success() && env.CODECOV_TOKEN != ''
82-
uses: codecov/codecov-action@v4
83-
with:
84-
files: test-output/coverage.xml
85-
token: ${{ secrets.CODECOV_TOKEN }}
86-
env:
87-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)