diff --git a/bifrost/bifrost b/bifrost/bifrost index 2777c86e..83928ba1 100755 --- a/bifrost/bifrost +++ b/bifrost/bifrost @@ -22,7 +22,10 @@ main() { ensure curl -L https://raw.githubusercontent.com/Jon-Becker/heimdall-rs/main/bifrost/install | bash exit 0 ;; - -v|--version) shift; TARGET_VERSION=$1 ;; + -v|--version) shift; + TARGET_VERSION=$1 + shift + ;; -B|--binary|--bin) shift; USE_BINARY=true ;; +nightly) shift; NIGHTLY_CHANNEL=true ;; -h|--help) @@ -66,8 +69,21 @@ main() { cd "heimdall-rs" ensure git fetch origin + # if we are nightly, use `main` branch + if [ -n "$NIGHTLY_CHANNEL" ]; then + ensure git checkout main > /dev/null 2>&1 + + # get the latest short commit hash + TARGET_VERSION=$(git rev-parse --short HEAD) + + # get the latest tag + tag=$(git describe --tags `git rev-list --tags --max-count=1`) + + # build nightly version + nightly_version="$tag+nightly.$TARGET_VERSION" + echo "bifrost: installing version $nightly_version." # if they specified a version, checkout that tag or branch - if [ -n "$TARGET_VERSION" ]; then + elif [ -n "$TARGET_VERSION" ]; then echo "bifrost: installing version $TARGET_VERSION." ensure git checkout $TARGET_VERSION > /dev/null 2>&1 @@ -84,6 +100,12 @@ main() { # if the user wants to use the precompiled binary, download it if [ -n "$USE_BINARY" ]; then + # nightly binaries are not available + if [ -n "$NIGHTLY_CHANNEL" ]; then + echo "bifrost: nightly binaries are not available." + exit 1 + fi + # cd into the binary directory ensure cd $BIFROST_BIN_DIR echo "bifrost: fetching binary." @@ -109,6 +131,13 @@ main() { # remove periods from version and cast as int VERSION=$(echo $VERSION | sed -E 's/\.//g') + # if nightly, we need to update cargo.toml versions (hacky lol) + if [ -n "$NIGHTLY_CHANNEL" ]; then + find . -name 'Cargo.toml' -type f | while read -r file; do + set_version "$file" "$nightly_version" + done + fi + # if VERSION > 0.6.0 (60), use the new build system if [ $VERSION -ge 60 ]; then RUSTFLAGS="-C target-cpu=native -C codegen-units=1" CARGO_PROFILE_RELEASE_LTO=true ensure cargo install --path ./cli --bins --locked --force --root $BIFROST_PATH @@ -155,7 +184,7 @@ Bifrost is the version manager for Heimdall. Install and manage specific versions of Heimdall and it's packages. USAGE: - bifrost + bifrost [FLAGS] OPTIONS: -h, --help Print help information @@ -164,6 +193,9 @@ OPTIONS: -v, --version Install a specific version -l, --list List all available versions +FLAGS: + +nightly Install the latest nightly build + EOF } @@ -185,5 +217,12 @@ requires_cmd() { fi } +# set the version of $1 to $2 +set_version() { + local file=$1 + local version=$2 + sed -i "" "s/^version.*/version = \"${version}\"/" $file +} + # run main main "$@" || exit 1 diff --git a/common/src/utils/version.rs b/common/src/utils/version.rs index 30dc24d6..c17d897e 100644 --- a/common/src/utils/version.rs +++ b/common/src/utils/version.rs @@ -13,6 +13,10 @@ pub struct Version { pub fn current_version() -> Version { // get the current version from the cargo package let version_string = env!("CARGO_PKG_VERSION"); + + // remove +... from the version string + let version_string = version_string.split('+').collect::>()[0]; + let version_parts: Vec<&str> = version_string.split('.').collect(); Version {