mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 10:16:08 +00:00
91 lines
2.9 KiB
Bash
Executable file
91 lines
2.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
### Logging functions
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
|
|
log::info() {
|
|
### Will print `[INFO]` in black foreground colour and magenta background colour
|
|
### then will print the given text in a magenta foreground colour and default background colour.
|
|
printf "\033[35m\033[7m[INFO]\033[27;39m \033[35m$*\033[39m\n"
|
|
}
|
|
|
|
log::error() {
|
|
### Will print `[ERROR]` in black foreground colour and red background colour
|
|
### then will print the given text in a red foreground colour and default background colour.
|
|
printf "\033[31m\033[7m[ERROR]\033[27;39m \033[31m$*\033[39m\n"
|
|
}
|
|
|
|
log::warn() {
|
|
### Will print `[WARNING]` in black foreground colour and yellow background colour
|
|
### then will print the given text in a yellow foreground colour and default background colour.
|
|
printf "\033[33m\033[7m[WARNING]\033[27;39m \033[33m$*\033[39m\n"
|
|
}
|
|
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
### Utils functions
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
|
|
is_windows() {
|
|
local -r target="$1"
|
|
echo "$target" | grep -q "windows"
|
|
}
|
|
|
|
get_env_target() {
|
|
eval "$(rustc --print cfg | grep target)"
|
|
local -rr raw="${target_arch:-}-${target_vendor:-}-${target_os:-}-${target_env:-}"
|
|
|
|
if echo "$raw" | grep -q "x86_64-apple-macos"; then
|
|
echo "x86_64-apple-darwin"
|
|
else
|
|
echo "$raw"
|
|
fi
|
|
}
|
|
|
|
_tap() {
|
|
log::info "$@"
|
|
"$@"
|
|
}
|
|
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
### Release-Related functions
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
|
|
release() {
|
|
local -r env_target="$1"
|
|
log::info "env target: $env_target"
|
|
|
|
local -r cross_target="${1:-"$env_target"}"
|
|
log::info "desired target: $cross_target"
|
|
|
|
TAR_DIR="$(pwd)/target/tar"
|
|
rm -rf "$(pwd)/target" 2> /dev/null || true
|
|
|
|
rustup target add $env_target
|
|
cargo install cross
|
|
cross build --release --target "$env_target"
|
|
|
|
cd target/"$env_target"/release/
|
|
|
|
if is_windows "$env_target"; then
|
|
zip -r "navi.zip" "navi.exe"
|
|
echo "EXTENSION=zip" >> $GITHUB_OUTPUT
|
|
else
|
|
tar -czf "navi.tar.gz" "navi"
|
|
echo "EXTENSION=tar.gz" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
log::info "PWD: $(pwd), LS: $(ls ./)"
|
|
}
|
|
|
|
_ls() {
|
|
log::info "contents from $*:"
|
|
ls -la "$@" || true
|
|
}
|
|
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
### Main script
|
|
### --------------------------------------------------------------------------------------------------------------------
|
|
|
|
release "$@"
|