Skip to content

Commit 89b870d

Browse files
committed
Set version from git tag
1 parent ea353a6 commit 89b870d

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,27 @@ jobs:
4848
with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
4949
out.write(f'tags={tags_csv}\n')
5050
out.write(f'push={push}\n')
51+
- name: Set version
52+
run: |
53+
if [ '${{ github.ref_type }}' = 'tag' ]; then
54+
rye version '${{ github.ref_name }}'
55+
else
56+
commit='${{ github.sha }}'
57+
rye version "0.0.0-commit.${commit:0:7}"
58+
fi
59+
rye version > src/chrisomatic/version.txt
5160
- name: Build Python wheel
5261
run: rye build --wheel --clean
5362
- uses: docker/setup-buildx-action@v3
5463
- name: Login to DockerHub
55-
if: github.event_name == 'push' || github.event_name == 'release'
64+
if: github.event_name == 'push'
5665
id: dockerhub_login
5766
uses: docker/login-action@v3
5867
with:
5968
username: ${{ secrets.DOCKERHUB_USERNAME }}
6069
password: ${{ secrets.DOCKERHUB_PASSWORD }}
6170
- name: Login to GitHub Container Registry
62-
if: github.event_name == 'push' || github.event_name == 'release'
71+
if: github.event_name == 'push'
6372
uses: docker/login-action@v3
6473
with:
6574
registry: ghcr.io

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "chrisomatic"
3-
version = "0.9.0"
3+
version = "0.0.0" # version is set by `rye version` in .github/workflows/build.yml
44
description = "ChRIS backend provisioner"
55
authors = [
66
{ name = "Jennings Zhang", email = "[email protected]" }

src/chrisomatic/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
from importlib.metadata import Distribution, PackageNotFoundError
2-
3-
4-
try:
5-
_pkg = Distribution.from_name(__package__)
6-
__version__ = _pkg.version
7-
except PackageNotFoundError:
8-
__version__ = "unknown"
1+
from __version__ import __version__

src/chrisomatic/__version__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pathlib import Path
2+
3+
__file = Path(__file__).parent / "version.txt"
4+
__version__ = __file.read_text() if __file.exists() else "0.0.0-unknown"

0 commit comments

Comments
 (0)