-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (104 loc) · 4.16 KB
/
python-package.yml
File metadata and controls
109 lines (104 loc) · 4.16 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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python CI/CD
on:
push:
branches: ["master", "dev"]
pull_request:
branches: ["master"]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true # This ensures the entire matrix stops if any job fails
matrix:
python-version: ${{ github.ref == 'refs/heads/master' && fromJSON('["3.9", "3.10", "3.11", "3.12"]') || fromJSON('["3.9"]') }}
steps:
- uses: actions/checkout@v4
- name: Load test batches secrets
env:
ENCODED: ${{ secrets.TEST_BATCHES_ZIP_B64 }}
run: |
echo "$ENCODED" | base64 -d > batches_persistent_test.zip
unzip batches_persistent_test.zip
- name: Set providers jsonl secret
env:
PROVIDER_JSONL : ${{ secrets.PROVIDER_CONFIG_JSONL}}
run: |
echo "$PROVIDER_JSONL" > providers_configs.jsonl
mkdir -p ~/.batchman
mv providers_configs.jsonl ~/.batchman/providers_configs.jsonl
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip uv
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install flake8 pytest
if [ -f requirements.txt ]; then uv pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
source .venv/bin/activate
# stop the build if there are Python syntax errors or undefined names
flake8 ./src/batchman --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
source .venv/bin/activate
pytest
deploy:
needs: test # This ensures deploy only runs if test job succeeds
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip uv
uv venv
source .venv/bin/activate
uv pip install packaging requests tomli
- name: Check version
id: check_version
run: |
source .venv/bin/activate
# Get version from pyproject.toml
TOML_VERSION=$(python -c "import tomli; print(tomli.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "Version in pyproject.toml: $TOML_VERSION"
LOCAL_VERSION=$TOML_VERSION
# Get PyPI version
PYPI_VERSION=$(python -c "import requests, json; print(json.loads(requests.get(f'https://pypi.org/pypi/batchman/json').text)['info']['version'])")
echo "PyPI version: $PYPI_VERSION"
# Compare versions
python -c "from packaging import version; exit(0) if version.parse('$LOCAL_VERSION') > version.parse('$PYPI_VERSION') else exit(1)"
if [ $? -eq 0 ]; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
else
echo "should_deploy=false" >> $GITHUB_OUTPUT
fi
- name: Build package
if: steps.check_version.outputs.should_deploy == 'true'
run: |
source .venv/bin/activate
uv build
echo "Deploying to production"
- name: Upload package to PyPI
if: steps.check_version.outputs.should_deploy == 'true'
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
source .venv/bin/activate
uv publish --index pypi --username __token__ --password "$PYPI_TOKEN"
echo "Uploaded to PyPI"