Skip to content

Commit d2db7f5

Browse files
authored
Merge pull request #357 from urchade/auto-pypi-releases
Add github workflow for automatic PyPI releases
2 parents 85044ca + 2eb752d commit d2db7f5

2 files changed

Lines changed: 147 additions & 0 deletions

File tree

.github/workflows/release.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release GLiNER to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Trigger on version tags (e.g., v1.0.0, v2.1.3)
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
build:
14+
name: Build distribution 📦
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
persist-credentials: false
21+
- name: Set up Python
22+
uses: actions/setup-python@v6
23+
with:
24+
python-version: "3.x"
25+
- name: Install pypa/build
26+
run: >-
27+
python3 -m
28+
pip install
29+
build
30+
--user
31+
- name: Build a binary wheel and a source tarball
32+
run: python3 -m build
33+
- name: Store the distribution packages
34+
uses: actions/upload-artifact@v5
35+
with:
36+
name: python-package-distributions
37+
path: dist/
38+
39+
publish-to-pypi:
40+
name: >-
41+
Publish Python 🐍 distribution 📦 to PyPI
42+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
43+
needs:
44+
- build
45+
runs-on: ubuntu-latest
46+
environment:
47+
name: pypi
48+
url: https://pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name
49+
permissions:
50+
id-token: write # IMPORTANT: mandatory for trusted publishing
51+
52+
steps:
53+
- name: Checkout code
54+
uses: actions/checkout@v6
55+
with:
56+
fetch-depth: 0 # Fetch all history to check branches
57+
- name: Verify tag is on main branch
58+
run: |
59+
if ! git branch -r --contains ${{ github.ref_name }} | grep -q 'origin/main'; then
60+
echo "Error: Tag ${{ github.ref_name }} is not on the main branch"
61+
exit 1
62+
fi
63+
echo "✓ Tag ${{ github.ref_name }} is on main branch"
64+
- name: Download all the dists
65+
uses: actions/download-artifact@v6
66+
with:
67+
name: python-package-distributions
68+
path: dist/
69+
- name: Publish distribution 📦 to PyPI
70+
uses: pypa/gh-action-pypi-publish@release/v1

RELEASE.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,81 @@ The very first release should be "0.1.0".
2222

2323
## Releases
2424

25+
GLiNER supports two release methods: **automated releases via GitHub Actions** (recommended) and manual releases via `twine`. The automated method is preferred as it ensures consistency and uses PyPI's trusted publishing.
26+
27+
### Automated Release via GitHub Actions (Recommended)
28+
29+
The repository includes a GitHub Actions workflow (`.github/workflows/release.yaml`) that automatically builds and publishes releases to PyPI when you push a version tag to the main branch.
30+
31+
#### Prerequisites
32+
33+
1. Ensure PyPI trusted publishing is configured for the GLiNER project in your PyPI account settings
34+
2. The GitHub Actions workflow must have the proper PyPI environment configured
35+
36+
#### Steps for Automated Release
37+
38+
**Step 1: Adjust the version of your package**
39+
40+
Update the version in [`gliner/__init__.py`](gliner/__init__.py) from dev to release version:
41+
42+
```diff
43+
- __version__ = "0.4.0.dev"
44+
+ __version__ = "0.4.0"
45+
```
46+
47+
Commit and push to main:
48+
49+
```bash
50+
git add gliner
51+
git commit -m "Release: v{VERSION}"
52+
git push origin main
53+
```
54+
55+
**Step 2: Create and push a version tag**
56+
57+
Create a tag matching the pattern `v*` (e.g., `v0.4.0`) and push it to trigger the release:
58+
59+
```bash
60+
git tag v<VERSION>
61+
git push origin v<VERSION>
62+
```
63+
64+
**Important:** The tag MUST be pushed to the main branch. The workflow will automatically verify this and fail if the tag is from any other branch.
65+
66+
**Step 3: Monitor the GitHub Actions workflow**
67+
68+
1. Go to [https://github.com/urchade/GLiNER/actions](https://github.com/urchade/GLiNER/actions)
69+
2. Watch the "Release GLiNER to PyPI" workflow execution
70+
3. The workflow will:
71+
- Build the distribution packages (wheel and source tarball)
72+
- Verify the tag is on the main branch
73+
- Publish to PyPI using trusted publishing
74+
75+
**Step 4: (Optional) Prepare release notes**
76+
77+
Create release notes on GitHub at [https://github.com/urchade/GLiNER/releases](https://github.com/urchade/GLiNER/releases) using the tag you just created.
78+
79+
**Step 5: Bump the dev version**
80+
81+
After a successful release, update [`gliner/__init__.py`](gliner/__init__.py) to the next dev version:
82+
83+
```diff
84+
- __version__ = "0.4.0"
85+
+ __version__ = "0.4.1.dev"
86+
```
87+
88+
Commit and push:
89+
90+
```bash
91+
git add gliner
92+
git commit -m "Bump version to {NEXT_VERSION}.dev"
93+
git push origin main
94+
```
95+
96+
### Manual Release via twine
97+
98+
If you need to release manually or the automated workflow is unavailable, follow these steps:
99+
25100
### Step 1: Adjust the version of your package
26101

27102
You should have the current version specified in [`gliner/__init__.py`](gliner/__init__.py). This version should be a dev version (e.g. `0.1.0.dev`) before you release, change it to the name of the version you are releasing:
@@ -154,3 +229,5 @@ Go back to the draft you did at step 4 ([https://github.com/urchade/GLiNER/relea
154229
### Step 9: Bump the dev version on the main branch
155230

156231
You’re almost done! Just go back to the `main` branch and change the dev version in [`gliner/__init__.py`](gliner/__init__.py) to the new version you’re developing, for instance `4.13.0.dev` if just released `4.12.0`.
232+
233+
**Note:** This step applies to both the automated and manual release processes.

0 commit comments

Comments
 (0)