1+ name : Build and Publish to PyPI
2+
3+ on :
4+ push :
5+ branches : [ main, master ]
6+ tags : [ 'v*' ]
7+ pull_request :
8+ branches : [ main, master ]
9+
10+ jobs :
11+ test :
12+ runs-on : ubuntu-latest
13+ strategy :
14+ matrix :
15+ python-version : [3.8, 3.9, 3.10, 3.11, 3.12, 3.13]
16+
17+ steps :
18+ - uses : actions/checkout@v4
19+
20+ - name : Set up Python ${{ matrix.python-version }}
21+ uses : actions/setup-python@v4
22+ with :
23+ python-version : ${{ matrix.python-version }}
24+
25+ - name : Install dependencies
26+ run : |
27+ python -m pip install --upgrade pip
28+ pip install -r requirements.txt
29+ pip install -r requirements-dev.txt
30+ pip install -e .
31+
32+ - name : Lint with flake8
33+ run : |
34+ # stop the build if there are Python syntax errors or undefined names
35+ flake8 cost_katana/ --count --select=E9,F63,F7,F82 --show-source --statistics
36+ # exit-zero treats all errors as warnings
37+ flake8 cost_katana/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
39+ - name : Format check with black
40+ run : |
41+ black --check cost_katana/
42+ black --check examples/
43+
44+ - name : Type check with mypy
45+ run : |
46+ mypy cost_katana/ --ignore-missing-imports
47+
48+ - name : Test with pytest
49+ run : |
50+ pytest tests/ -v --cov=cost_katana --cov-report=xml
51+
52+ - name : Test examples
53+ run : |
54+ python -m py_compile examples/*.py
55+
56+ - name : Upload coverage to Codecov
57+ uses : codecov/codecov-action@v3
58+ with :
59+ file : ./coverage.xml
60+ fail_ci_if_error : false
61+
62+ build-and-publish :
63+ needs : test
64+ runs-on : ubuntu-latest
65+ if : github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
66+
67+ steps :
68+ - uses : actions/checkout@v4
69+
70+ - name : Set up Python
71+ uses : actions/setup-python@v4
72+ with :
73+ python-version : " 3.13"
74+
75+ - name : Install dependencies
76+ run : |
77+ python -m pip install --upgrade pip
78+ pip install build twine
79+
80+ - name : Extract version from setup.py
81+ id : version
82+ run : |
83+ VERSION=$(python -c "import re; setup_content = open('setup.py').read(); version_match = re.search(r\"version=['\"]([^'\"]*)['\"]\", setup_content); print(version_match.group(1))")
84+ echo "version=$VERSION" >> $GITHUB_OUTPUT
85+ echo "Extracted version: $VERSION"
86+
87+ - name : Build package
88+ run : |
89+ python -m build
90+
91+ - name : Check package
92+ run : |
93+ twine check dist/*
94+
95+ - name : Publish to PyPI
96+ env :
97+ TWINE_USERNAME : __token__
98+ TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
99+ run : |
100+ twine upload dist/*
101+
102+ - name : Create GitHub Release
103+ if : startsWith(github.ref, 'refs/tags/v')
104+ uses : actions/create-release@v1
105+ env :
106+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107+ with :
108+ tag_name : ${{ github.ref_name }}
109+ release_name : Release ${{ github.ref_name }}
110+ body : |
111+ ## What's Changed
112+
113+ This release includes updates to the Cost Katana Python SDK.
114+
115+ ### Installation
116+ ```bash
117+ pip install cost-katana==${{ steps.version.outputs.version }}
118+ ```
119+
120+ ### Features
121+ - Updated dependencies
122+ - Improved error handling
123+ - Enhanced CLI interface
124+
125+ ### Breaking Changes
126+ None
127+
128+ ### Bug Fixes
129+ - Fixed Makefile syntax issues
130+ - Updated Python command references
131+
132+ ### Documentation
133+ - Updated installation instructions
134+ - Improved examples
135+ draft : false
136+ prerelease : false
0 commit comments