mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
fix: use explicit commit hash for docker package versioning (#856)
This commit is contained in:
22
version.py
22
version.py
@@ -3,6 +3,7 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from datetime import datetime, timezone
|
||||
@@ -10,14 +11,21 @@ from datetime import datetime, timezone
|
||||
|
||||
# used in pyproject.toml [tool.pdm.version]
|
||||
def get_version() -> str:
|
||||
commit_hash = os.environ.get("GIT_COMMIT_HASH", "").strip()
|
||||
if commit_hash:
|
||||
return f"{datetime.now(timezone.utc).year}+{commit_hash}"
|
||||
|
||||
git = shutil.which("git")
|
||||
if git is None:
|
||||
raise RuntimeError("git executable not found, unable to compute version")
|
||||
result = subprocess.run( # noqa: S603 running git is safe here
|
||||
[git, "rev-parse", "--short", "HEAD"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
raise RuntimeError("unable to compute version: set GIT_COMMIT_HASH or build from a valid git checkout")
|
||||
try:
|
||||
result = subprocess.run( # noqa: S603 running git is safe here
|
||||
[git, "rev-parse", "--short", "HEAD"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as ex:
|
||||
raise RuntimeError("unable to compute version: set GIT_COMMIT_HASH or build from a valid git checkout") from ex
|
||||
commit_hash = result.stdout.strip()
|
||||
return f"{datetime.now(timezone.utc).year}+{commit_hash}"
|
||||
|
||||
Reference in New Issue
Block a user