Skip to content

Commit 107e56e

Browse files
committed
single source of truth for version
1 parent 3047679 commit 107e56e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

.github/workflows/build-release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ jobs:
4141

4242
- name: Sync dependencies
4343
run: uv sync
44+
45+
- name: Set version in the code
46+
run: |
47+
VERSION=${GITHUB_REF#refs/tags/v}
48+
sed -i "s/VERSION_PLACEHOLDER/\"$VERSION\"/" exportify-cli.py
4449
4550
- name: Build executable
4651
run: |

exportify-cli.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import re
7+
import subprocess
78
import sys
89
from pathlib import Path
910
from typing import Any
@@ -48,6 +49,22 @@
4849
logger = logging.getLogger(__name__)
4950

5051

52+
def get_version():
53+
try:
54+
version = "VERSION_PLACEHOLDER"
55+
if version == "VERSION_PLACEHOLDER":
56+
version = (
57+
subprocess.check_output(
58+
["git", "describe", "--tags", "--always"], stderr=subprocess.DEVNULL
59+
)
60+
.decode("utf-8")
61+
.strip()
62+
)
63+
return version.replace("v", "")
64+
except Exception:
65+
return "0.0.0"
66+
67+
5168
def validate_config(config: configparser.ConfigParser) -> bool:
5269
"""Validate that the Spotify section exists and has all required keys, and that the redirect URI is valid."""
5370
if not config.has_section("spotify"):
@@ -595,7 +612,7 @@ def format_usage(self, ctx, formatter) -> None:
595612
)
596613
@click.help_option("-h", "--help")
597614
@click.version_option(
598-
"0.5.2",
615+
get_version(),
599616
"-v",
600617
"--version",
601618
prog_name="exportify-cli",

0 commit comments

Comments
 (0)