Skip to content

Commit 7d49c4d

Browse files
authored
Merge pull request #5 from BarnabasG/initial
1.1.4 - Add github auto publish, flask-openapi3
2 parents 6e7ffd8 + abb9b18 commit 7d49c4d

File tree

10 files changed

+402
-19
lines changed

10 files changed

+402
-19
lines changed

.github/workflows/ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- main
8+
push:
9+
branches:
10+
- master
11+
- main
12+
13+
jobs:
14+
test:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, windows-latest, macos-latest]
19+
python-version: ['3.10', '3.11', '3.12']
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v4
32+
with:
33+
enable-cache: true
34+
35+
- name: Install dependencies
36+
run: |
37+
uv sync --dev
38+
39+
# - name: Run code formatting check
40+
# run: |
41+
# uv run ruff format --check .
42+
43+
# - name: Run linting
44+
# run: |
45+
# uv run ruff check .
46+
47+
- name: Run type checking
48+
run: |
49+
uv run mypy
50+
51+
- name: Run tests
52+
run: |
53+
make test
54+
55+
- name: Run integration tests
56+
run: |
57+
uv run python -m pytest tests/integration/
58+
59+
- name: Run typeguard
60+
if: matrix.os == 'ubuntu-latest'
61+
run: |
62+
make typeguard
63+
64+
publish-check:
65+
runs-on: ubuntu-latest
66+
needs: test
67+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
68+
69+
steps:
70+
- name: Checkout repository
71+
uses: actions/checkout@v4
72+
73+
- name: Set up Python
74+
uses: actions/setup-python@v5
75+
with:
76+
python-version: '3.11'
77+
78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v4
80+
81+
- name: Check if version exists on PyPI
82+
id: version_check
83+
run: |
84+
VERSION=$(uv version | awk '{print $2}')
85+
echo "version=$VERSION" >> $GITHUB_OUTPUT
86+
87+
# Check if version already exists on PyPI
88+
if curl -s "https://pypi.org/pypi/pytest-api-cov/$VERSION/json" > /dev/null 2>&1; then
89+
echo "exists=true" >> $GITHUB_OUTPUT
90+
echo "Version $VERSION already published to PyPI"
91+
else
92+
echo "exists=false" >> $GITHUB_OUTPUT
93+
echo "Version $VERSION not found on PyPI"
94+
fi
95+
96+
- name: Comment on publish workflow
97+
if: steps.version_check.outputs.exists == 'true'
98+
run: |
99+
echo "::warning::Version ${{ steps.version_check.outputs.version }} already exists on PyPI. Update version in pyproject.toml before publishing."
100+

.github/workflows/publish.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
workflow_dispatch: # Allow manual triggering
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: write # Required to create and push tags
16+
id-token: write # Required for OIDC authentication (if using PyPI trusted publishing)
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0 # Fetch all history for tags
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.11'
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v4
32+
with:
33+
enable-cache: true
34+
35+
- name: Read version from pyproject.toml
36+
id: version
37+
run: |
38+
VERSION=$(uv version | awk '{print $2}')
39+
echo "version=$VERSION" >> $GITHUB_OUTPUT
40+
echo "Package version: $VERSION"
41+
42+
- name: Check if version already published
43+
id: check_published
44+
run: |
45+
VERSION="${{ steps.version.outputs.version }}"
46+
47+
# Check if Git tag exists
48+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
49+
echo "tag_exists=true" >> $GITHUB_OUTPUT
50+
echo "Git tag v$VERSION already exists"
51+
else
52+
echo "tag_exists=false" >> $GITHUB_OUTPUT
53+
echo "Git tag v$VERSION does not exist"
54+
fi
55+
56+
# Check if version exists on PyPI
57+
if curl -s "https://pypi.org/pypi/pytest-api-cov/$VERSION/json" > /dev/null 2>&1; then
58+
echo "pypi_exists=true" >> $GITHUB_OUTPUT
59+
echo "Version $VERSION already published to PyPI"
60+
else
61+
echo "pypi_exists=false" >> $GITHUB_OUTPUT
62+
echo "Version $VERSION not found on PyPI"
63+
fi
64+
65+
- name: Create version tag
66+
if: steps.check_published.outputs.tag_exists == 'false'
67+
run: |
68+
git config user.name "github-actions[bot]"
69+
git config user.email "github-actions[bot]@users.noreply.github.com"
70+
git tag -a "v${{ steps.version.outputs.version }}" -m "Release version ${{ steps.version.outputs.version }}"
71+
git push origin "v${{ steps.version.outputs.version }}"
72+
73+
- name: Set up build environment
74+
if: steps.check_published.outputs.pypi_exists == 'false'
75+
run: |
76+
uv sync --dev
77+
78+
- name: Run pipeline (tests, linting, etc.)
79+
if: steps.check_published.outputs.pypi_exists == 'false'
80+
run: make pipeline
81+
82+
- name: Build package
83+
if: steps.check_published.outputs.pypi_exists == 'false'
84+
run: make build
85+
86+
- name: Publish to PyPI
87+
if: steps.check_published.outputs.pypi_exists == 'false'
88+
env:
89+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
90+
run: |
91+
if [ -z "$PYPI_TOKEN" ]; then
92+
echo "❌ PYPI_TOKEN secret is not set. Please configure it in repository settings."
93+
echo " Settings → Secrets and variables → Actions → New repository secret"
94+
exit 1
95+
fi
96+
echo $PYPI_TOKEN > /tmp/pypi_token.txt
97+
uv publish --token $(cat /tmp/pypi_token.txt)
98+
rm /tmp/pypi_token.txt
99+
100+
- name: Verify publication
101+
if: steps.check_published.outputs.pypi_exists == 'false'
102+
run: |
103+
sleep 10 # Wait for PyPI to index the package
104+
uv run --with pytest-api-cov --no-project -- python -c \
105+
"import pytest_api_cov; print(f'✅ Published version: {pytest_api_cov.__version__}')"
106+
107+
- name: Skip publish - already published
108+
if: steps.check_published.outputs.pypi_exists == 'true'
109+
run: |
110+
echo "✅ Version ${{ steps.version.outputs.version }} already published to PyPI. Skipping publish."
111+

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Makefile
22

3-
.PHONY: ruff mypy test clean clean-all
3+
.PHONY: ruff mypy test clean clean-all version
44

55
PYPI_TOKEN := $(shell type .pypi_token 2>nul || echo "")
66
TEST_PYPI_TOKEN := $(shell type .test_pypi_token 2>nul || echo "")
77

8+
version:
9+
@uv version
10+
811
ruff:
912
@echo "Running ruff..."
1013
@uv run ruff format .

0 commit comments

Comments
 (0)