-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (72 loc) · 2.53 KB
/
Copy pathpython-package.yml
File metadata and controls
88 lines (72 loc) · 2.53 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
name: Python package
on:
push:
branches: ["release"]
tags: ["v*"]
pull_request:
branches: ["release"]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# Stop the build on syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Treat all other errors as warnings
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
publish:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install wheel & twine
run: |
python -m pip install wheel twine
- name: Extract and validate version from tag
id: get_version
run: |
# Extract version from tag (remove 'v' prefix)
VERSION=${GITHUB_REF#refs/tags/v}
# Validate version format (allows for alpha/beta versions)
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(a|b|rc)?[0-9]*$ ]]; then
echo "Error: Invalid version format. Expected format: X.Y.Z[a|b|rc]N (e.g., 0.1.0a1)"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Using version: $VERSION"
- name: Update version in setup.py
run: |
# Update the version in setup.py dynamically
sed -i "s/version='[^']*'/version='$VERSION'/" setup.py
echo "Updated setup.py with version: $VERSION"
grep "version=" setup.py
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Publish to PyPI
run: |
twine upload --skip-existing dist/*
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}