Skip to content

Commit c218a7d

Browse files
Add github action to automatically publish package to pypi on tag (#62)
* Add github action to build and publish package to pypi when a new tag is pushed * Only publish builds for tags that start with v * Automatically create new github release after publishing to pypi * Update release script to use pypi token * Make sure tagged version matches setup.py version * Bump version to test auto release * Fix version check * Bump version for testing * Get tag version with leading v * Bump version to test * Add information about how to make a new release
1 parent 2d2354e commit c218a7d

File tree

4 files changed

+105
-31
lines changed

4 files changed

+105
-31
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: test
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
11+
fail-fast: false
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Install python v${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
cache: pip
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install -r tests/requirements.txt
26+
sudo apt update && sudo apt install ffmpeg -y
27+
28+
- name: Run Tests
29+
run: |
30+
python -m unittest discover
31+
32+
# see https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
33+
build:
34+
name: Build distribution 📦
35+
runs-on: ubuntu-latest
36+
if: startsWith(github.ref, 'refs/tags/v') # only build on tag pushes
37+
needs:
38+
- test
39+
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
persist-credentials: false
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.x"
50+
51+
- name: Check version
52+
run: |
53+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
54+
PACKAGE_VERSION=$(grep -Po 'version\s*=\s*["\x27]\K[^"\x27]+' setup.py)
55+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
56+
echo "Version mismatch! GitHub tag is $TAG_VERSION but package version is $PACKAGE_VERSION."
57+
exit 1
58+
fi
59+
60+
- name: Install pypa/build
61+
run: >-
62+
python3 -m
63+
pip install
64+
build
65+
--user
66+
67+
- name: Build a binary wheel and a source tarball
68+
run: python3 -m build
69+
70+
- name: Store the distribution packages
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: python-package-distributions
74+
path: dist/
75+
76+
release:
77+
name: >-
78+
Publish Python 🐍 distribution 📦 to PyPI and Github
79+
if: startsWith(github.ref, 'refs/tags/v') # only publish on version tag pushes
80+
needs:
81+
- build
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- name: Download all the dists
86+
uses: actions/download-artifact@v4
87+
with:
88+
name: python-package-distributions
89+
path: dist/
90+
91+
- name: Publish distribution 📦 to PyPI
92+
uses: pypa/gh-action-pypi-publish@release/v1
93+
with:
94+
password: ${{ secrets.DF3D_PYPI_API_TOKEN }}
95+
96+
- name: Make Github release
97+
uses: softprops/action-gh-release@v2

.github/workflows/test.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ We previously published our DeepFly3D work on eLife journal. You can read the pu
3232
- [Calibration](#calibration)
3333
- [Running GUI](#running-gui)
3434
- [Development](#development)
35+
- [Releasing a new version](#releasing-a-new-version)
3536
- [References](#references)
3637
- [Version History](#version-history)
3738
- [Changes in 0.5](#changes-in-05)
@@ -465,6 +466,12 @@ DeepFly3D consists of 3 pip packages:
465466

466467
The master branch of the DeepFly3D package is kept up-to-date with the last version of the pip package. Development is done under dev branch. Before pushing changes to the master branch, make sure all test cases are passing. You can run the tests using `python -m unittest discover`. Unittests make sure several scenarios can be processed using cli without failing.
467468

469+
# Releasing a new version
470+
471+
1. Update the version in `setup.py` (eg. 1.0.1)
472+
2. Create a tag for the release that matches the new version (eg. v1.0.1)
473+
3. Push the latest commit and tag - this will trigger a github action to make a new release for DeepFly3D on pypi and github
474+
4. Edit the github release https://github.com/NeLy-EPFL/DeepFly3D/releases to add information about the latest changes
468475

469476
# References
470477
You can cite our paper in case you find it useful.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="nely-df3d",
9-
version="1.0.0",
9+
version="1.0.1.dev4",
1010
description="GUI and 3D pose estimation pipeline for tethered Drosophila.",
1111
author="Semih Gunel",
1212
author_email="[email protected]",

0 commit comments

Comments
 (0)