navi/scripts/release

95 lines
1.8 KiB
Text
Raw Normal View History

2020-03-04 21:01:23 +00:00
#!/usr/bin/env bash
set -euo pipefail
##? release
2020-03-04 21:01:23 +00:00
export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"
is_windows() {
local -r target="$1"
echo "$target" | grep -q "windows"
}
get_env_target() {
eval $(rustc --print cfg | grep target)
local r raw="${target_arch}-${target_vendor}-${target_os}-${target_env}"
echoerr "env_raw: $raw"
if echo "$raw" | grep -q "x86_64-apple-macos"; then
echo "x86_64-apple-darwin"
else
echo "$raw"
fi
}
_tap() {
echoerr "$@"
"$@"
}
2020-03-04 21:01:23 +00:00
release() {
local -r cross_target="${1:-}"
echoerr "cross_target: $cross_target"
2020-03-04 21:01:23 +00:00
2020-03-11 14:30:25 +00:00
TAR_DIR="${NAVI_HOME}/target/tar"
local use_zip=false
local cross=true
local -r env_target="$(get_env_target)"
echoerr "env_target: $env_target"
2020-03-04 21:01:23 +00:00
if [[ $cross_target == $env_target ]]; then
cross=false
2020-03-11 14:30:25 +00:00
fi
2020-03-04 21:01:23 +00:00
2020-03-11 14:30:25 +00:00
cd "$NAVI_HOME"
2020-03-04 21:01:23 +00:00
2020-03-11 14:30:25 +00:00
rm -rf "${NAVI_HOME}/target" 2> /dev/null || true
2020-03-04 21:01:23 +00:00
if $cross; then
2020-03-11 14:30:25 +00:00
cargo install cross 2> /dev/null || true
_tap cross build --release --locked --target "$cross_target"
local -r bin_folder="${cross_target}/release"
2020-03-11 14:30:25 +00:00
else
_tap cargo build --release --locked
local -r bin_folder="release"
2020-03-11 14:30:25 +00:00
fi
2020-03-04 21:01:23 +00:00
_ls "${bin_folder}"
if is_windows "$cross_target"; then
local -r exe_ext=".exe"
use_zip=true
else
local -r exe_ext=""
fi
bin_path="${NAVI_HOME}/target/${bin_folder}/navi${exe_ext}"
2020-03-11 14:30:25 +00:00
chmod +x "$bin_path"
mkdir -p "$TAR_DIR" 2> /dev/null || true
2020-03-04 21:01:23 +00:00
2020-03-11 14:30:25 +00:00
cp "$bin_path" "$TAR_DIR"
2020-03-04 21:01:23 +00:00
2020-04-19 18:51:04 +00:00
cd "$TAR_DIR"
2020-03-04 21:01:23 +00:00
if $use_zip; then
zip -r navi.zip *
echo ::set-output name=EXTENSION::zip
else
tar -czf navi.tar.gz *
echo ::set-output name=EXTENSION::tar.gz
fi
_ls "${bin_path}"
_ls "${TAR_DIR}"
}
_ls() {
echoerr "contents from $@:"
ls -la "$@" || true
2020-03-04 21:01:23 +00:00
}
release "$@"