Skip to content

Commit

Permalink
Pin bazelisk version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemnmez committed Jan 23, 2025
1 parent 03d7810 commit 881b075
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
3 changes: 2 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"description": "Renovate directives",
"fileMatch": [
"^MODULE.bazel$",
"^WORKSPACE$"
"^WORKSPACE$",
"^sh/bin/bazel$"
],
"matchStrings": [
"#\\s*renovate:\n#\\s*datasource\\s*=\\s*(?<datasource>.*)\n#\\s*versioning\\s*=\\s*(?<versioning>.*)\n#\\s*depName\\s*=\\s*(?<depName>.*)\n[^=]+=\\s*\"(?<currentValue>[^\"]*)\""
Expand Down
48 changes: 12 additions & 36 deletions sh/bin/bazel
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
#!/usr/bin/env bash
#
# A pure Bash script that downloads (if necessary) and runs Bazelisk
# from a cache folder stored at ../../.script_cache/bazelisk relative
# to this script's location.
#
set -euo pipefail

# 1. Determine the directory where this script resides.
# This allows us to place the cache in ../../.script_cache/bazelisk
# relative to this file.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# renovate:
# datasource=github-releases
# versioning=semver-coerced
# depName=bazelbuild/bazelisk
BAZELISK_VERSION="v1.25.0"

# 2. Construct the cache path.
CACHE_DIR="${SCRIPT_DIR}/../../.script_cache/bazelisk"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CACHE_DIR="${SCRIPT_DIR}/../../.script_cache/bazelisk/${BAZELISK_VERSION}"
mkdir -p "${CACHE_DIR}"

# 3. Identify OS and architecture.
OS="$(uname -s)"
ARCH="$(uname -m)"

# Normalise a few typical architecture strings
case "${ARCH}" in
x86_64|amd64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
# Extend as needed for other architectures
x86_64|amd64) ARCH="amd64";;
aarch64|arm64) ARCH="arm64";;
esac

# Map the OS/ARCH pair to the correct Bazelisk asset name
ASSET=""
case "${OS}" in
Linux)
Expand Down Expand Up @@ -60,31 +47,20 @@ case "${OS}" in
;;
esac

# 4. Construct the path to the cached Bazelisk binary
CACHED_BAZELISK="${CACHE_DIR}/${ASSET}"

# 5. If the Bazelisk binary isn't cached yet, download it from GitHub.
if [ ! -f "${CACHED_BAZELISK}" ]; then
echo "Downloading Bazelisk asset '${ASSET}' to '${CACHED_BAZELISK}'..."
echo "Downloading Bazelisk ${BAZELISK_VERSION} (${ASSET})..."
curl --fail -L \
"https://github.com/bazelbuild/bazelisk/releases/latest/download/${ASSET}" \
"https://github.com/bazelbuild/bazelisk/releases/${BAZELISK_VERSION}/download/${ASSET}" \
-o "${CACHED_BAZELISK}"

if [ ! -f "${CACHED_BAZELISK}" ]; then
echo "Error: Could not download Bazelisk asset '${ASSET}'."
exit 1
fi

# Make it executable if on a Unix-like OS
case "${OS}" in
Linux|Darwin)
chmod +x "${CACHED_BAZELISK}"
;;
Windows)
# On Windows, .exe doesn't need special permissions
;;
# Windows requires no special execute permissions
esac
fi

# 6. Run Bazelisk from the cache, forwarding user arguments
exec "${CACHED_BAZELISK}" "$@"

0 comments on commit 881b075

Please sign in to comment.