-
Notifications
You must be signed in to change notification settings - Fork 3
108 lines (91 loc) · 3.42 KB
/
Copy pathsdk-python-release.yml
File metadata and controls
108 lines (91 loc) · 3.42 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
name: Release Python SDK
on:
push:
paths:
- 'sdk/python/**'
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
working-directory: ./sdk/python
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Lint
working-directory: ./sdk/python
run: ruff check src tests
- name: Type check
working-directory: ./sdk/python
run: mypy src
- name: Run tests
working-directory: ./sdk/python
run: pytest
release:
runs-on: ubuntu-latest
needs: test
permissions:
id-token: write # Required for PyPI trusted publishing
contents: write # Required for creating GitHub releases
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version changed
id: version-check
working-directory: ./sdk/python
run: |
# Get current version from pyproject.toml
CURRENT_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Get previous version (if exists)
git show HEAD~1:sdk/python/pyproject.toml > /tmp/prev-pyproject.toml 2>/dev/null || echo '[project]\nversion = "0.0.0"' > /tmp/prev-pyproject.toml
PREV_VERSION=$(python -c "import tomllib; print(tomllib.load(open('/tmp/prev-pyproject.toml', 'rb')).get('project', {}).get('version', '0.0.0'))" 2>/dev/null || echo "0.0.0")
echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT
# Check if versions differ
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged ($CURRENT_VERSION)"
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Set up Python
if: steps.version-check.outputs.changed == 'true'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tools
if: steps.version-check.outputs.changed == 'true'
run: pip install build
- name: Build package
if: steps.version-check.outputs.changed == 'true'
working-directory: ./sdk/python
run: python -m build
- name: Publish to PyPI
if: steps.version-check.outputs.changed == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sdk/python/dist/
- name: Create GitHub Release
if: steps.version-check.outputs.changed == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: python-sdk-v${{ steps.version-check.outputs.current_version }}
name: Python SDK v${{ steps.version-check.outputs.current_version }}
body: |
## nfc-agent (Python) v${{ steps.version-check.outputs.current_version }}
Install via pip:
```bash
pip install nfc-agent==${{ steps.version-check.outputs.current_version }}
```
generate_release_notes: true