Skip to content

Commit

Permalink
feat(bifrost): add *hacky* nightly build system (#258)
Browse files Browse the repository at this point in the history
* test

* feat(bifrost): add nightly build system
  • Loading branch information
Jon-Becker authored Dec 30, 2023
1 parent d3d66ae commit fc356fa
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
86 changes: 72 additions & 14 deletions bifrost/bifrost
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,43 @@ 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"

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"

Expand All @@ -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
Expand All @@ -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."
Expand All @@ -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
Expand All @@ -115,28 +151,40 @@ main() {
echo "bifrost: installation complete."
}

# list all available versions of heimdall
versions() {
cat 1>&2 <<EOF
if [ "$NIGHTLY_CHANNEL" = true ]; then
msg="Available versions of Heimdall (including nightly builds):"
tag_filter="cat" # Do not filter any tags
else
msg="Available versions of Heimdall:"
tag_filter="grep -v '+nightly'" # Exclude nightly builds
fi

cat 1>&2 <<EOF
Available versions of Heimdall:
$msg
Version | Tag |
----------------------------------------- | -------------------------- |
EOF
git ls-remote --tags "https://github.com/Jon-Becker/heimdall-rs"
git ls-remote --tags "https://github.com/Jon-Becker/heimdall-rs" \
| eval $tag_filter \
| awk '{line[NR]=$0} END {for (i=NR; i>0; i--) print line[i]}'
}



# usage prints the usage message
usage() {
cat 1>&2 <<EOF
Bifrost is the version manager for Heimdall.
Install and manage specific versions of Heimdall and it's packages.
USAGE:
bifrost <OPTIONS>
bifrost [FLAGS] <OPTIONS>
OPTIONS:
-h, --help Print help information
Expand All @@ -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
}

Expand All @@ -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
4 changes: 4 additions & 0 deletions common/src/utils/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 +<channel>... from the version string
let version_string = version_string.split('+').collect::<Vec<&str>>()[0];

let version_parts: Vec<&str> = version_string.split('.').collect();

Version {
Expand Down

0 comments on commit fc356fa

Please sign in to comment.