forked from ChrisTitusTech/linutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·95 lines (74 loc) · 2.54 KB
/
publish.sh
File metadata and controls
executable file
·95 lines (74 loc) · 2.54 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
set -euo pipefail
# Enforce date-based versioning (YY.MM.DD) before publishing.
today_raw=$(date +%y-%m-%d)
expected_version=${today_raw//-/.}
read_versions=$(python - <<'PY'
import sys
def load_toml(path: str):
try:
import tomllib # Python 3.11+
except ModuleNotFoundError: # Fallback for older Python
import tomli as tomllib # type: ignore
with open(path, "rb") as f:
return tomllib.load(f)
workspace = load_toml("Cargo.toml")
core = load_toml("core/Cargo.toml")
tui = load_toml("tui/Cargo.toml")
workspace_version = workspace.get("workspace", {}).get("package", {}).get("version")
core_pkg = core.get("package", {})
core_version = core_pkg.get("version") or workspace_version
if isinstance(core_version, dict) and core_version.get("workspace"):
core_version = workspace_version
linutil_core_dep = tui.get("dependencies", {}).get("linutil_core")
linutil_core_dep_version = None
if isinstance(linutil_core_dep, dict):
linutil_core_dep_version = linutil_core_dep.get("version")
print(workspace_version or "")
print(core_version or "")
print(linutil_core_dep_version or "")
PY
)
workspace_version=$(echo "$read_versions" | sed -n '1p')
core_version=$(echo "$read_versions" | sed -n '2p')
tui_dep_version=$(echo "$read_versions" | sed -n '3p')
if [[ -z "$workspace_version" || -z "$core_version" || -z "$tui_dep_version" ]]; then
echo "Unable to determine required versions from Cargo manifests." >&2
exit 1
fi
if [[ "$workspace_version" != "$expected_version" ]]; then
echo "Workspace version $workspace_version does not match today's expected $expected_version." >&2
exit 1
fi
if [[ "$core_version" != "$expected_version" ]]; then
echo "linutil_core package version $core_version does not match today's expected $expected_version." >&2
exit 1
fi
if [[ "$tui_dep_version" != "$expected_version" ]]; then
echo "linutil_tui depends on linutil_core $tui_dep_version but expected $expected_version." >&2
exit 1
fi
echo "Version check passed: $expected_version"
echo "Running sort and format checks..."
if ! cargo sort --check --workspace; then
echo "cargo sort check failed. Please run 'cargo sort --workspace' to fix." >&2
exit 1
fi
if ! cargo fmt --check; then
echo "cargo fmt check failed. Please run 'cargo fmt' to fix." >&2
exit 1
fi
bash sort-tomlfiles.sh
cargo test --no-fail-fast --package linutil_core
cargo build --release
echo "Checks passed."
read -r -p "Publish to crates.io? [y/N]: " answer
case "$answer" in
[Yy]*)
cargo publish -p linutil_core
cargo publish -p linutil_tui
;;
*)
echo "Publish skipped."
;;
esac