From fc356fa5a81be196cb3f029b6b794bf369c35b61 Mon Sep 17 00:00:00 2001 From: Jonathan Becker Date: Sat, 30 Dec 2023 10:54:55 -0600 Subject: [PATCH] feat(bifrost): add *hacky* nightly build system (#258) * test * feat(bifrost): add nightly build system --- bifrost/bifrost | 86 +++++++++++++++++++++++++++++++------ common/src/utils/version.rs | 4 ++ 2 files changed, 76 insertions(+), 14 deletions(-) mode change 100644 => 100755 bifrost/bifrost diff --git a/bifrost/bifrost b/bifrost/bifrost old mode 100644 new mode 100755 index 0b4da40b..83928ba1 --- a/bifrost/bifrost +++ b/bifrost/bifrost @@ -13,9 +13,8 @@ main() { # parsing parameters while [[ $1 ]]; do case $1 in - --) shift; break ;; - - -u|--upgrade|--update) + --) shift; break ;; + -u|--upgrade|--update) shift; echo "bifrost: removing old binaries" rm -rf "$BIFROST_PATH" @@ -23,23 +22,34 @@ main() { ensure curl -L https://raw.githubusercontent.com/Jon-Becker/heimdall-rs/main/bifrost/install | bash exit 0 ;; - -v|--version) shift; TARGET_VERSION=$1 ;; - -B|--binary|--bin) shift; USE_BINARY=true ;; + -v|--version) shift; + TARGET_VERSION=$1 + shift + ;; + -B|--binary|--bin) shift; USE_BINARY=true ;; + +nightly) shift; NIGHTLY_CHANNEL=true ;; -h|--help) usage exit 0 ;; - -l|--list|--versions) + -l|--list|--versions) shift; versions exit 0 ;; *) - echo "bifrost: option '$1' not recognized\n" + echo "bifrost: option '$1' not recognized" exit 1 ;; - esac; shift + esac; done + # print channel + if [ -n "$NIGHTLY_CHANNEL" ]; then + echo "bifrost: using nightly channel" + else + echo "bifrost: using stable channel" + fi + # remove the current heimdall installation if it exists ensure rm -f "$BIFROST_BIN_DIR/heimdall" @@ -59,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 @@ -77,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." @@ -102,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 @@ -115,28 +151,40 @@ main() { echo "bifrost: installation complete." } +# list all available versions of heimdall versions() { - cat 1>&2 <&2 <0; i--) print line[i]}' } + + +# usage prints the usage message usage() { cat 1>&2 < + bifrost [FLAGS] OPTIONS: -h, --help Print help information @@ -145,6 +193,9 @@ OPTIONS: -v, --version Install a specific version -l, --list List all available versions +FLAGS: + +nightly Install the latest nightly build + EOF } @@ -166,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 {