Skip to content

Commit f2e4b70

Browse files
lurtzopajonk
andauthored
Remove USE_BAZEL_VERSION from /etc/profile.d and fix bash completion for bazel >= 8.4.0 (#51)
* Fix setting USE_BAZEL_VERSION in /etc/profile.d bazel completions are generated for the bazel version specified with `.bazelversion`. But USE_BAZEL_VERSION was not updated accordingly. This resulted in the wrong bazel version being used and completions not working. Fixes #48 * avoid installing another bazel version on version mismatch * do not set USE_BAZEL_VERSION it override .bazelversion which should not happen by default * add bash argument if minimum bazel version is met * fix: add missing parameters * ensure that bash is used, with fail-fast options According to https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstepsshell, this should result in bash --noprofile --norc -eo pipefail {0} being used. * break it again to see fail-fast working * make sur ebash fails fast cf. devcontainers/ci#294 * fix ci again * dummy commit to retrigger github actions * Revert "dummy commit to retrigger github actions" This reverts commit 6342cc0. * Remove the separate build step Maybe caching does not work as expected, and with this, the publish step at the latest will definitely build the images. * Force bazel version in tests * revert workflow changes should be fixed in separate PR --------- Co-authored-by: Oliver Pajonk <oliver.pajonk@elektrobit.com>
1 parent 24b2140 commit f2e4b70

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/s-core-devcontainer/.devcontainer/s-core-local/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ rm /tmp/bazelisk.deb
5757

5858
# Pre-install a fixed Bazel version, setup the bash command completion
5959
export USE_BAZEL_VERSION=${bazel_version}
60-
bazel help completion > /tmp/bazel-complete.bash
60+
bazel help completion bash > /tmp/bazel-complete.bash
6161
ls -lah /tmp/bazel-complete.bash
6262
mkdir -p /etc/bash_completion.d
6363
mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
64-
sh -c "echo 'export USE_BAZEL_VERSION=${bazel_version}' >> /etc/profile.d/bazel.sh"
64+
sh -c "echo 'INSTALLED_BAZEL_VERSION=${bazel_version}' >> /devcontainer/features/s-core-local/bazel_setup.sh"
6565

6666
# Buildifier, directly from GitHub (apparently no APT repository available)
6767
# The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file.
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$(bazel version | grep 'Build label:' | awk '{print $3}')" ]; then
4+
. /devcontainer/features/s-core-local/bazel_setup.sh || true
5+
6+
if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$INSTALLED_BAZEL_VERSION" ]; then
57
# Pre-install the matching Bazel version, setup the bash command completion
68
USE_BAZEL_VERSION=$(cat .bazelversion)
7-
bazel help completion > /tmp/bazel-complete.bash
9+
10+
min_bazel_version_for_bash_option="8.4.0"
11+
bash=""
12+
if [ "$(printf '%s\n' "$min_bazel_version_for_bash_option" "$USE_BAZEL_VERSION" | sort -V | head -n1)" = "$min_bazel_version_for_bash_option" ]; then
13+
bash="bash"
14+
fi
15+
16+
bazel help completion ${bash} > /tmp/bazel-complete.bash
817
sudo mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
9-
sudo sed -i '/^USE_BAZEL_VERSION=/c\USE_BAZEL_VERSION=${USE_BAZEL_VERSION}' /etc/profile.d/bazel.sh || true
18+
echo "INSTALLED_BAZEL_VERSION=$USE_BAZEL_VERSION" | sudo tee /devcontainer/features/s-core-local/bazel_setup.sh
1019
fi

src/s-core-devcontainer/.devcontainer/s-core-local/tests/test_default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ check "validate pylint is working" bash -c "pylint --version"
2929

3030
# Bazel-related tools
3131
check "validate bazelisk is working and has the correct version" bash -c "bazelisk version | grep '${bazelisk_version}'"
32+
33+
## This is the bazel version preinstalled in the devcontainer.
34+
## A solid test would disable the network interface first to prevent a different version from being downloaded,
35+
## but that requires CAP_NET_ADMIN, which is not yet added.
36+
export USE_BAZEL_VERSION=${bazel_version}
3237
check "validate bazel is working and has the correct version" bash -c "bazel version | grep '${bazel_version}'"
38+
unset USE_BAZEL_VERSION
39+
3340
check "validate buildifier is working and has the correct version" bash -c "buildifier --version | grep '${buildifier_version}'"
3441
check "validate starpls is working and has the correct version" bash -c "starpls version | grep '${starpls_version}'"
3542
check "validate bazel-compile-commands is working and has the correct version" bash -c "bazel-compile-commands --version 2>&1 | grep '${bazel_compile_commands_version}'"

0 commit comments

Comments
 (0)