-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (69 loc) · 2.46 KB
/
publish.yml
File metadata and controls
80 lines (69 loc) · 2.46 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
name: Release
on:
workflow_run:
workflows: ["Python Tests", "Transports"]
branches: [main]
types:
- completed
# Required for PyPI trusted publishing
permissions:
id-token: write
contents: write # Required for creating tags and releases
jobs:
check-version-and-publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel tomli
- name: Check for version bump
id: check-version
run: |
# Extract current version directly from pyproject.toml
# This is more reliable than using importlib.metadata
CURRENT_VERSION=$(python -c "
import tomli
with open('pyproject.toml', 'rb') as f:
data = tomli.load(f)
print(data['project']['version'])
")
echo "Current version: $CURRENT_VERSION"
# Check if this version already has a tag
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Version $CURRENT_VERSION already has a tag. Skipping release."
echo "is_new_version=false" >> $GITHUB_OUTPUT
else
echo "New version detected: $CURRENT_VERSION"
echo "is_new_version=true" >> $GITHUB_OUTPUT
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi
- name: Build package
if: steps.check-version.outputs.is_new_version == 'true'
run: |
python -m build
- name: Create Release
if: steps.check-version.outputs.is_new_version == 'true'
id: create_release
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.check-version.outputs.new_version }}
name: Release v${{ steps.check-version.outputs.new_version }}
draft: false
prerelease: false
generateReleaseNotes: false
omitBodyDuringUpdate: true
- name: Publish to PyPI
if: steps.check-version.outputs.is_new_version == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}