Skip to content

Commit 136428e

Browse files
committed
Github actions
1 parent 4e87ad9 commit 136428e

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

.github/workflows/publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+' # Matches semantic versioning tags
7+
- '[0-9]+.[0-9]+.[0-9]+-test.*' # Test releases
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.12']
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies and run CI
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build pytest pytest-cov setuptools_scm
28+
make ci
29+
30+
publish:
31+
needs: test
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: write
35+
steps:
36+
- uses: actions/checkout@v3
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v4
40+
with:
41+
python-version: '3.12'
42+
43+
- name: Verify tag version matches package version
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install build pytest pytest-cov setuptools_scm twine
47+
PACKAGE_VERSION=$(python -m setuptools_scm)
48+
TAG_VERSION=${GITHUB_REF#refs/tags/} # Remove 'refs/tags/' prefix
49+
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
50+
echo "Package version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)"
51+
exit 1
52+
fi
53+
54+
- name: Publish to TestPyPI
55+
if: contains(github.ref, 'test')
56+
env:
57+
TWINE_USERNAME: __token__
58+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
59+
run: make all && twine upload --repository testpypi dist/*
60+
61+
- name: Publish to PyPI
62+
if: "!contains(github.ref, 'test')"
63+
env:
64+
TWINE_USERNAME: __token__
65+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
66+
run: make dist
67+
68+
- name: Create Release
69+
uses: softprops/action-gh-release@v1
70+
with:
71+
files: dist/*
72+
generate_release_notes: true
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ['3.12']
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Install dependencies and run tests
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install pytest pytest-cov
26+
make ci

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.PHONY: all dist d clean c version v install i test t build b
22

3-
all: clean install test build version
3+
ci: clean install test
4+
all: ci build version
45

56
dist d: all
67
scripts/check-version.sh

0 commit comments

Comments
 (0)