-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (74 loc) · 2.76 KB
/
release.yml
File metadata and controls
89 lines (74 loc) · 2.76 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
name: Release
on:
push:
branches: [main]
jobs:
test:
name: Test before release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run tests
run: python -m pytest tests/ -v
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install build tools
run: pip install build twine
- name: Check if version is already published
id: version_check
run: |
PKG_VERSION=$(python -c "import tomllib; f=open('pyproject.toml','rb'); d=tomllib.load(f); print(d['project']['version'])")
PYPI_VERSION=$(pip index versions apiforgepy 2>/dev/null | grep -oP '(?<=apiforgepy \()[\d.]+(?=\))' | head -1 || echo "none")
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
echo "pypi_version=$PYPI_VERSION" >> $GITHUB_OUTPUT
if [ "$PKG_VERSION" != "$PYPI_VERSION" ]; then
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "New version detected: $PKG_VERSION (PyPI has $PYPI_VERSION)"
else
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "Version $PKG_VERSION is already on PyPI — skipping publish."
fi
- name: Build package
if: steps.version_check.outputs.should_publish == 'true'
run: python -m build
- name: Publish to PyPI
if: steps.version_check.outputs.should_publish == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
- name: Create GitHub Release
if: steps.version_check.outputs.should_publish == 'true'
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version_check.outputs.pkg_version }}';
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${version}`,
name: `v${version}`,
body: `## apiforgepy v${version}\n\nSee [CHANGELOG.md](https://github.com/APIForge-Organisation/sdk-python/blob/main/CHANGELOG.md) for details.\n\n\`\`\`bash\npip install apiforgepy==${version}\n\`\`\``,
draft: false,
prerelease: version.startsWith('0.'),
});