From 977a07e44914ff8cc6b6e9632b3a0b46c118e93f Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Sat, 27 Jul 2024 01:29:11 -0400 Subject: [PATCH] Set version from git tag --- .github/workflows/build.yml | 13 +++++++++++-- pyproject.toml | 2 +- src/chrisomatic/__init__.py | 9 +-------- src/chrisomatic/__version__.py | 4 ++++ 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/chrisomatic/__version__.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b778898..cec9dc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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.dev1+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 diff --git a/pyproject.toml b/pyproject.toml index 77dc859..1aa467e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" } diff --git a/src/chrisomatic/__init__.py b/src/chrisomatic/__init__.py index f8d3f15..70cd492 100644 --- a/src/chrisomatic/__init__.py +++ b/src/chrisomatic/__init__.py @@ -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__ diff --git a/src/chrisomatic/__version__.py b/src/chrisomatic/__version__.py new file mode 100644 index 0000000..1e8a228 --- /dev/null +++ b/src/chrisomatic/__version__.py @@ -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"