-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (68 loc) · 2.36 KB
/
pypi.yaml
File metadata and controls
79 lines (68 loc) · 2.36 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
name: Publish to PyPI
permissions:
id-token: write # Required for trusted publishing
contents: read # Required to checkout code
actions: write # Required to cancel runs
on:
workflow_run:
workflows: [Python Tests]
types:
- completed
branches:
- main
jobs:
pypi-release:
name: PyPI Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment:
name: pypi
url: https://pypi.org/project/graphomotor/
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Need 2 commits to compare for version changes
- uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- name: Check if version changed
id: version-check
run: |
if git diff HEAD^1 HEAD --name-only | grep -q "pyproject.toml"; then
version_change=$(git diff HEAD^1 HEAD pyproject.toml | grep -E "^(\+|-)version =")
if [[ -n "$version_change" ]]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
echo "Version changed detected:"
echo "$version_change"
else
echo "version_changed=false" >> $GITHUB_OUTPUT
echo "pyproject.toml changed but version did not change"
fi
else
echo "version_changed=false" >> $GITHUB_OUTPUT
echo "pyproject.toml did not change"
fi
- name: Skip release if version unchanged
if: steps.version-check.outputs.version_changed == 'false'
run: |
echo "No version change detected, skipping release"
gh run cancel ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
if: steps.version-check.outputs.version_changed == 'true'
run: uv build
- name: Verify build artifacts
if: steps.version-check.outputs.version_changed == 'true'
run: |
ls -la dist/
python -c "import tarfile; tarfile.open('dist/*.tar.gz').getnames()" || true
- name: Publish to PyPI
if: steps.version-check.outputs.version_changed == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
# Alternative: use uv publish with trusted publishing
# run: uv publish --token ${{ secrets.PYPI_API_TOKEN }}