1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 13:50:09 +00:00

feat(version): show commit hash for nightly installs (#517)

Display commit hash in parentheses after "Nightly" channel label
to help users identify exact version when testing nightly builds.
This commit is contained in:
tw93
2026-03-03 16:51:49 +08:00
parent c8ed94698d
commit 814b3680b9
2 changed files with 37 additions and 5 deletions

View File

@@ -217,6 +217,17 @@ get_source_version() {
fi
}
get_source_commit_hash() {
# Try to get from local git repo first
if [[ -d "$SOURCE_DIR/.git" ]]; then
git -C "$SOURCE_DIR" rev-parse --short HEAD 2> /dev/null && return
fi
# Fallback to GitHub API
curl -fsSL --connect-timeout 3 \
"https://api.github.com/repos/tw93/mole/commits/main" 2> /dev/null |
sed -n 's/.*"sha"[[:space:]]*:[[:space:]]*"\([a-f0-9]\{7\}\).*/\1/p' | head -1
}
get_latest_release_tag() {
local tag
if ! command -v curl > /dev/null 2>&1; then
@@ -288,12 +299,14 @@ resolve_install_channel() {
write_install_channel_metadata() {
local channel="$1"
local commit_hash="${2:-}"
local metadata_file="$CONFIG_DIR/install_channel"
local tmp_file
tmp_file=$(mktemp "${CONFIG_DIR}/install_channel.XXXXXX") || return 1
{
printf 'CHANNEL=%s\n' "$channel"
[[ -n "$commit_hash" ]] && printf 'COMMIT_HASH=%s\n' "$commit_hash"
} > "$tmp_file" || {
rm -f "$tmp_file" 2> /dev/null || true
return 1
@@ -751,9 +764,12 @@ perform_install() {
installed_version="$source_version"
fi
local install_channel
local install_channel commit_hash=""
install_channel="$(resolve_install_channel)"
if ! write_install_channel_metadata "$install_channel"; then
if [[ "$install_channel" == "nightly" ]]; then
commit_hash=$(get_source_commit_hash)
fi
if ! write_install_channel_metadata "$install_channel" "$commit_hash"; then
log_warning "Could not write install channel metadata"
fi
@@ -840,9 +856,12 @@ perform_update() {
updated_version="$target_version"
fi
local install_channel
local install_channel commit_hash=""
install_channel="$(resolve_install_channel)"
if ! write_install_channel_metadata "$install_channel"; then
if [[ "$install_channel" == "nightly" ]]; then
commit_hash=$(get_source_commit_hash)
fi
if ! write_install_channel_metadata "$install_channel" "$commit_hash"; then
log_warning "Could not write install channel metadata"
fi

15
mole
View File

@@ -99,6 +99,13 @@ get_install_channel() {
esac
}
get_install_commit() {
local channel_file="$SCRIPT_DIR/install_channel"
if [[ -f "$channel_file" ]]; then
sed -n 's/^COMMIT_HASH=\(.*\)$/\1/p' "$channel_file" | head -1
fi
}
# Background update notice
check_for_updates() {
local msg_cache="$HOME/.cache/mole/update_message"
@@ -222,7 +229,13 @@ show_version() {
printf '\nMole version %s\n' "$VERSION"
if [[ "$channel" == "nightly" ]]; then
printf 'Channel: Nightly\n'
local commit
commit=$(get_install_commit)
if [[ -n "$commit" ]]; then
printf 'Channel: Nightly (%s)\n' "$commit"
else
printf 'Channel: Nightly\n'
fi
fi
printf 'macOS: %s\n' "$os_ver"
printf 'Architecture: %s\n' "$arch"