Skip to content

Commit 27a2cc5

Browse files
committed
feat: show nightly channel in version output
Refs #517
1 parent 0a8f92c commit 27a2cc5

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

install.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,45 @@ get_installed_version() {
266266
fi
267267
}
268268

269+
resolve_install_channel() {
270+
case "${MOLE_VERSION:-}" in
271+
main | latest)
272+
printf 'nightly\n'
273+
return 0
274+
;;
275+
dev)
276+
printf 'dev\n'
277+
return 0
278+
;;
279+
esac
280+
281+
if [[ "${MOLE_EDGE_INSTALL:-}" == "true" ]]; then
282+
printf 'nightly\n'
283+
return 0
284+
fi
285+
286+
printf 'stable\n'
287+
}
288+
289+
write_install_channel_metadata() {
290+
local channel="$1"
291+
local metadata_file="$CONFIG_DIR/install_channel"
292+
293+
local tmp_file
294+
tmp_file=$(mktemp "${CONFIG_DIR}/install_channel.XXXXXX") || return 1
295+
{
296+
printf 'CHANNEL=%s\n' "$channel"
297+
} > "$tmp_file" || {
298+
rm -f "$tmp_file" 2> /dev/null || true
299+
return 1
300+
}
301+
302+
mv -f "$tmp_file" "$metadata_file" || {
303+
rm -f "$tmp_file" 2> /dev/null || true
304+
return 1
305+
}
306+
}
307+
269308
# CLI parsing (supports main/latest and version tokens).
270309
parse_args() {
271310
local -a args=("$@")
@@ -712,6 +751,12 @@ perform_install() {
712751
installed_version="$source_version"
713752
fi
714753

754+
local install_channel
755+
install_channel="$(resolve_install_channel)"
756+
if ! write_install_channel_metadata "$install_channel"; then
757+
log_warning "Could not write install channel metadata"
758+
fi
759+
715760
# Edge installs get a suffix to make the version explicit.
716761
if [[ "${MOLE_EDGE_INSTALL:-}" == "true" ]]; then
717762
installed_version="${installed_version}-edge"
@@ -795,6 +840,12 @@ perform_update() {
795840
updated_version="$target_version"
796841
fi
797842

843+
local install_channel
844+
install_channel="$(resolve_install_channel)"
845+
if ! write_install_channel_metadata "$install_channel"; then
846+
log_warning "Could not write install channel metadata"
847+
fi
848+
798849
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version, $updated_version"
799850
}
800851

mole

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ is_homebrew_install() {
8787
return 1
8888
}
8989

90+
get_install_channel() {
91+
local channel_file="$SCRIPT_DIR/install_channel"
92+
local channel="stable"
93+
if [[ -f "$channel_file" ]]; then
94+
channel=$(sed -n 's/^CHANNEL=\(.*\)$/\1/p' "$channel_file" | head -1)
95+
fi
96+
case "$channel" in
97+
nightly | dev | stable) printf '%s\n' "$channel" ;;
98+
*) printf 'stable\n' ;;
99+
esac
100+
}
101+
90102
# Background update notice
91103
check_for_updates() {
92104
local msg_cache="$HOME/.cache/mole/update_message"
@@ -205,7 +217,13 @@ show_version() {
205217
install_method="Homebrew"
206218
fi
207219

220+
local channel
221+
channel=$(get_install_channel)
222+
208223
printf '\nMole version %s\n' "$VERSION"
224+
if [[ "$channel" == "nightly" ]]; then
225+
printf 'Channel: Nightly\n'
226+
fi
209227
printf 'macOS: %s\n' "$os_ver"
210228
printf 'Architecture: %s\n' "$arch"
211229
printf 'Kernel: %s\n' "$kernel"

tests/cli.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ setup_file() {
1414
}
1515

1616
teardown_file() {
17+
rm -f "$PROJECT_ROOT/install_channel"
1718
rm -rf "$HOME"
1819
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
1920
export HOME="$ORIGINAL_HOME"
@@ -47,6 +48,7 @@ SCRIPT
4748
setup() {
4849
rm -rf "$HOME/.config"
4950
mkdir -p "$HOME"
51+
rm -f "$PROJECT_ROOT/install_channel"
5052
}
5153

5254
@test "mole --help prints command overview" {
@@ -63,6 +65,18 @@ setup() {
6365
[[ "$output" == *"$expected_version"* ]]
6466
}
6567

68+
@test "mole --version shows nightly channel metadata" {
69+
expected_version="$(grep '^VERSION=' "$PROJECT_ROOT/mole" | head -1 | sed 's/VERSION=\"\(.*\)\"/\1/')"
70+
cat > "$PROJECT_ROOT/install_channel" <<'EOF'
71+
CHANNEL=nightly
72+
EOF
73+
74+
run env HOME="$HOME" "$PROJECT_ROOT/mole" --version
75+
[ "$status" -eq 0 ]
76+
[[ "$output" == *"Mole version $expected_version"* ]]
77+
[[ "$output" == *"Channel: Nightly"* ]]
78+
}
79+
6680
@test "mole unknown command returns error" {
6781
run env HOME="$HOME" "$PROJECT_ROOT/mole" unknown-command
6882
[ "$status" -ne 0 ]

0 commit comments

Comments
 (0)