navi/scripts/release
alexis-opolka 6f207ca8a7 Tries to fixe issues
Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
2025-04-07 07:51:03 +02:00

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 "$@"