Skip to content

Commit

Permalink
Set version automatically during release
Browse files Browse the repository at this point in the history
up until now you had to remember to update the version manually
  • Loading branch information
aantn committed Jun 9, 2024
1 parent 3e43486 commit 157d3b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build-on-publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
run: |-
gcloud config get-value project
- name: Update package version
run: |
sed -i 's/__version__ = .*/__version__ = "${{github.ref_name}}"/g' holmes/__init__.py
sed -i 's/0.0.0/${{github.ref_name}}/g' helm/holmes/Chart.yaml helm/holmes/values.yaml
sed -i 's/0.0.1/${{github.ref_name}}/g' helm/holmes/Chart.yaml
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

Expand All @@ -41,11 +47,6 @@ jobs:
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Update package version
run: |
sed -i 's/0.0.0/${{github.ref_name}}/g' helm/holmes/Chart.yaml helm/holmes/values.yaml
sed -i 's/0.0.1/${{github.ref_name}}/g' helm/holmes/Chart.yaml
- name: Save artifact with helm chart
uses: actions/upload-artifact@v2
with:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/build-on-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y binutils
- name: Update package version (Linux)
if: matrix.os == 'ubuntu-latest'
run: sed -i 's/__version__ = .*/__version__ = "${{ github.ref_name }}"/g' holmes/__init__.py

# mac has BSD style sed command where you specify -i '' and not just -i
- name: Update package version (macOS)
if: matrix.os == 'macos-latest'
run: sed -i '' 's/__version__ = .*/__version__ = "${{ github.ref_name }}"/g' holmes/__init__.py

# windows has no sed, so we use powershell
- name: Update package version (Windows)
if: matrix.os == 'windows-latest'
run: |
$filePath = 'holmes/__init__.py'
(Get-Content $filePath) -replace '__version__ = .+', '__version__ = "${{ github.ref_name }}"' | Set-Content $filePath
shell: pwsh

- name: Build with PyInstaller
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions holmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from holmes.config import Config, LLMType
from holmes.plugins.destinations import DestinationType
from holmes.plugins.prompts import load_prompt
from holmes import __version__
from holmes import get_version

app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
investigate_app = typer.Typer(
Expand Down Expand Up @@ -337,7 +337,7 @@ def jira(

@app.command()
def version() -> None:
typer.echo(__version__)
typer.echo(get_version())

if __name__ == "__main__":
app()
35 changes: 31 additions & 4 deletions holmes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# For relative imports to work in Python 3.6
# See https://stackoverflow.com/a/49375740
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
import os
import subprocess
import sys

__version__ = "0.2.1"
# For relative imports to work in Python 3.6 - see https://stackoverflow.com/a/49375740
sys.path.append(os.path.dirname(os.path.realpath(__file__)))

# This is patched by github actions during release
__version__ = "0.0.0"


def get_version() -> str:
# the version string was patched by a release - return __version__ which will be correct
if not __version__.startswith("0.0.0"):
return __version__

# we are running from an unreleased dev version
try:
# Get the latest git tag
tag = subprocess.check_output(["git", "describe", "--tags"]).decode().strip()

# Get the current branch name
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode().strip()

# Check if there are uncommitted changes
status = subprocess.check_output(["git", "status", "--porcelain"]).decode().strip()
dirty = "-dirty" if status else ""

return f"{tag}-{branch}{dirty}"

except Exception:
return f"dev-version"

0 comments on commit 157d3b3

Please sign in to comment.