Skip to content

Commit

Permalink
Set version from git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jul 27, 2024
1 parent ea353a6 commit 89b870d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,27 @@ jobs:
with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
out.write(f'tags={tags_csv}\n')
out.write(f'push={push}\n')
- name: Set version
run: |
if [ '${{ github.ref_type }}' = 'tag' ]; then
rye version '${{ github.ref_name }}'
else
commit='${{ github.sha }}'
rye version "0.0.0-commit.${commit:0:7}"
fi
rye version > src/chrisomatic/version.txt
- name: Build Python wheel
run: rye build --wheel --clean
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: github.event_name == 'push' || github.event_name == 'release'
if: github.event_name == 'push'
id: dockerhub_login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name == 'push' || github.event_name == 'release'
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "chrisomatic"
version = "0.9.0"
version = "0.0.0" # version is set by `rye version` in .github/workflows/build.yml
description = "ChRIS backend provisioner"
authors = [
{ name = "Jennings Zhang", email = "Jennings.Zhang@childrens.harvard.edu" }
Expand Down
9 changes: 1 addition & 8 deletions src/chrisomatic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
from importlib.metadata import Distribution, PackageNotFoundError


try:
_pkg = Distribution.from_name(__package__)
__version__ = _pkg.version
except PackageNotFoundError:
__version__ = "unknown"
from __version__ import __version__
4 changes: 4 additions & 0 deletions src/chrisomatic/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pathlib import Path

__file = Path(__file__).parent / "version.txt"
__version__ = __file.read_text() if __file.exists() else "0.0.0-unknown"

0 comments on commit 89b870d

Please sign in to comment.