Skip to content

Commit c2af567

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

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

.github/workflows/build-release.yml

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

4242
- name: Sync dependencies
4343
run: uv sync
44+
45+
- name: Set version in the code
46+
shell: bash
47+
run: |
48+
VERSION=${GITHUB_REF#refs/tags/v}
49+
if [[ "$OSTYPE" == "darwin"* ]]; then
50+
sed -i '' "s/VERSION_PLACEHOLDER/$VERSION/" exportify-cli.py
51+
else
52+
sed -i "s/VERSION_PLACEHOLDER/$VERSION/" exportify-cli.py
53+
fi
4454
4555
- name: Build executable
4656
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)