-
Notifications
You must be signed in to change notification settings - Fork 28
109 lines (103 loc) · 3.32 KB
/
build.yml
File metadata and controls
109 lines (103 loc) · 3.32 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
name: build & publish
on: push
permissions:
contents: write # Required for creating releases and tags
jobs:
test:
strategy:
fail-fast: false
matrix:
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
cache-dependency-path: "**/requirements-dev.txt"
- name: Test
run: |-
pip install -r requirements-dev.txt
pytest
build:
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install build dependencies
run: python -m pip install --upgrade build
- name: Build package
run: python -m build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
check_version:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if version tag exists
id: check
run: |
VERSION=$(python -c "import re; print(re.search(r\"version\s*=\s*'([^']+)'\", open('setup.py').read()).group(1))")
echo "version=$VERSION" >> $GITHUB_OUTPUT
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "Tag v${VERSION} already exists, skipping publish"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Tag v${VERSION} does not exist, will publish"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
publish_to_pypi:
if: github.ref == 'refs/heads/master' && needs.check_version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
needs:
- build
- check_version
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*
create_release:
if: github.ref == 'refs/heads/master' && needs.check_version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
needs:
- publish_to_pypi
- check_version
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create tag and release
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag v${{ needs.check_version.outputs.version }}
git push origin v${{ needs.check_version.outputs.version }}
gh release create v${{ needs.check_version.outputs.version }} --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}