Repository navigation
Expand file tree
/
Copy pathauto-version.sh
More file actions
executable file
·63 lines (54 loc) · 2.3 KB
/
Copy pathauto-version.sh
File metadata and controls
executable file
·63 lines (54 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# auto-version.sh — CalVer (YYYY.MM.DD[.N]) bump for feishu-bridge
# Called by session-done-commit.sh before staging, or manually.
# Prints the new version to stdout.
set -euo pipefail
cd "$(dirname "$0")/.."
INIT_FILE="feishu_bridge/__init__.py"
TOML_FILE="pyproject.toml"
# Current version from __init__.py (single source of truth for bump base)
CURRENT=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "$INIT_FILE")
TOML_CURRENT=$(sed -n 's/^version = "\(.*\)"/\1/p' "$TOML_FILE")
# Refuse to bump from an inconsistent base — otherwise the bump computes off
# the wrong number (e.g. 2026.05.28 → 2026.05.28.1 while pyproject is already
# 2026.05.29, producing a regression that PyPI's version comparator ignores).
if [ "$CURRENT" != "$TOML_CURRENT" ]; then
echo "auto-version: version mismatch — __init__.py=$CURRENT pyproject.toml=$TOML_CURRENT" >&2
echo "auto-version: align both files manually, then re-run" >&2
exit 1
fi
# Today's CalVer base
TODAY=$(date +%Y.%m.%d)
# Parse CURRENT into date prefix + optional .N suffix.
if [[ "$CURRENT" =~ ^([0-9]{4}\.[0-9]{2}\.[0-9]{2})(\.([0-9]+))?$ ]]; then
CURRENT_DATE="${BASH_REMATCH[1]}"
CURRENT_N="${BASH_REMATCH[3]}"
else
echo "auto-version: unparseable version: $CURRENT" >&2
exit 1
fi
# Bump base = max(CURRENT_DATE, TODAY). Never regress when CURRENT carries a
# future date (manual edit, timezone skew, prior bump on a clock-ahead box).
# sort -V on zero-padded CalVer date prefixes matches calendar order.
HIGHER=$(printf '%s\n%s\n' "$CURRENT_DATE" "$TODAY" | sort -V | tail -1)
if [ "$HIGHER" = "$CURRENT_DATE" ]; then
if [ -z "$CURRENT_N" ]; then
NEW="${CURRENT_DATE}.1"
else
NEW="${CURRENT_DATE}.$((CURRENT_N + 1))"
fi
else
NEW="$TODAY"
fi
# Update both sources of truth
sed -i '' "s/^__version__ = .*/__version__ = \"$NEW\"/" "$INIT_FILE"
sed -i '' "s/^version = .*/version = \"$NEW\"/" "$TOML_FILE"
# Keep uv.lock's pinned project version in sync, so the version-bump commit is
# self-contained and the lockfile never drifts into an unrelated later commit.
# uv writes progress to stderr, leaving stdout clean for the version capture.
if command -v uv >/dev/null 2>&1; then
uv lock >&2 || echo "auto-version: 'uv lock' failed; sync uv.lock manually" >&2
else
echo "auto-version: uv not found; skipping uv.lock sync" >&2
fi
echo "$NEW"