-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (82 loc) · 2.62 KB
/
publish.yml
File metadata and controls
100 lines (82 loc) · 2.62 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
name: Publish to PyPI / GitHub
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: read
env:
PYTHON_VERSION: "3.14"
jobs:
build:
name: "Build the project"
runs-on: ubuntu-latest
outputs:
prerelease: ${{ steps.check-version.outputs.prerelease }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
python-version: ${{ env.PYTHON_VERSION }}
enable-cache: true
cache-suffix: "publish-py${{ env.python-version }}"
- name: Install dependencies
run: |
# We only need the project dependencies, no development deps
uv sync --no-default-groups
- name: Make sure pyproject.toml version matches git version
run: |
git_version=$(git describe --tags)
pyproject_version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
if [ "$git_version" != "v$pyproject_version" ]; then
echo "The version specified in pyproject.toml (v$pyproject_version) doesn't match the git version ($git_version)"
echo "You most likely forgot to update pyproject.toml when publishing the release tag"
echo "You can fix this by updating the pyproject version and overwriting the git tag"
exit 1
fi
- name: Build the project
run: uv build
- name: Upload build files
uses: actions/upload-artifact@v4
with:
name: "dist"
path: "dist/"
if-no-files-found: error
retention-days: 5
publish-github:
name: "Publish a GitHub release"
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download the distribution files from PR artifact
uses: actions/download-artifact@v4
with:
name: "dist"
path: "dist/"
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*"
draft: false
publish-pypi:
name: "Publish to PyPI"
needs: build
runs-on: ubuntu-latest
permissions:
# Used to authenticate to PyPI via OIDC.
id-token: write
steps:
- name: Download the distribution files from PR artifact
uses: actions/download-artifact@v4
with:
name: "dist"
path: "dist/"
# This uses PyPI's trusted publishing, so no token is required
- name: Release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1