-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (128 loc) · 3.62 KB
/
Copy pathpython-ci.yml
File metadata and controls
135 lines (128 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# DevForge — Reusable Python CI Workflow
#
# Standardizes test running, linting, and packaging for Python repos.
# Call from any Coding-Dev-Tools Python repo:
#
# name: Python CI
# on:
# push:
# branches: [main]
# pull_request:
# branches: [main]
# jobs:
# test:
# uses: Coding-Dev-Tools/.github/.github/workflows/python-ci.yml@main
# with:
# python-versions: '["3.11", "3.12", "3.13"]'
# runner-os: '["ubuntu-latest"]'
# run-lint: true
# lint-path: src
# run-build: true
name: Python CI (Reusable)
on:
workflow_call:
inputs:
python-versions:
description: JSON array of Python versions to test
type: string
required: false
default: '["3.10", "3.11", "3.12", "3.13"]'
runner-os:
description: JSON array of runner OS targets
type: string
required: false
default: '["ubuntu-latest"]'
run-lint:
description: Run ruff linting
type: boolean
required: false
default: true
lint-path:
description: Path(s) to lint (space-separated)
type: string
required: false
default: src
run-build:
description: Run hatch build check
type: boolean
required: false
default: true
test-command:
description: Custom test command override
type: string
required: false
default: ''
extra-deps:
description: Extra pip install deps (space-separated)
type: string
required: false
default: ''
secrets:
CODECOV_TOKEN:
description: Token for uploading coverage to Codecov
required: false
defaults:
run:
shell: bash
jobs:
lint:
if: inputs.run-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install ruff
run: pip install ruff
- name: Run ruff check
run: ruff check ${{ inputs.lint-path }}
- name: Run ruff format check
run: ruff format --check ${{ inputs.lint-path }}
test:
needs: lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ${{ fromJSON(inputs.runner-os) }}
python-version: ${{ fromJSON(inputs.python-versions) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- id: hatch
name: Install the project
run: |
pip install hatch
hatch env create
continue-on-error: true
- name: Install legacy
if: steps.hatch.outcome == 'failure'
run: |
pip install -e ".[dev,test]" 2>/dev/null || pip install -e ".[dev]" 2>/dev/null || pip install -e .
- name: Install extra deps
if: inputs.extra-deps != ''
run: pip install ${{ inputs.extra-deps }}
- name: Run tests
run: ${{ inputs.test-command || 'hatch run test' }}
- name: Upload coverage
if: inputs.test-command == '' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
build:
if: inputs.run-build
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install hatch
run: pip install hatch
- name: Build package
run: hatch build