Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ci/container/build-ic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ if [ "${BUILD_IC_NESTED:-}" == 1 ]; then
fi
export BUILD_IC_NESTED=1

export ROOT_DIR="$(git rev-parse --show-toplevel)"
# Assign, then export: `export X="$(...)"` swallows the command
# substitution's exit status, so a failing git would leave X empty and
# `set -e` would not notice.
ROOT_DIR="$(git rev-parse --show-toplevel)"
export ROOT_DIR

# This script needs to be run inside the ic-build container
# If it isn't, we drop into the correct container.
Expand Down Expand Up @@ -105,7 +109,8 @@ if [ -n "$(git status --porcelain)" ]; then
exit 1
fi

export VERSION="$(git rev-parse HEAD)"
VERSION="$(git rev-parse HEAD)"
export VERSION

BAZEL_TARGETS=()

Expand Down
34 changes: 34 additions & 0 deletions ci/container/container-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,40 @@ RUNTIME_RUN_ARGS=(
--mount type=tmpfs,target="/tmp/containers" # expected by ic-os build
)

# When the checkout is a linked git worktree, its `.git` is a *file* holding an
# absolute path to an admin directory under the main checkout's `.git`, i.e. a
# path outside the checkout. Mounting only the checkout leaves that pointer
# dangling, so every `git` call inside the container fails -- including the
# `$(git rev-parse --show-toplevel)` that several ci scripts rely on. Mount the
# main checkout's `.git` at the very same absolute path so the pointer resolves.
if [ -f "${REPO_ROOT}/.git" ]; then
GIT_COMMON_DIR="$(git rev-parse --git-common-dir)"
GIT_COMMON_DIR="$(cd "$GIT_COMMON_DIR" && pwd)" # may be relative
case "$GIT_COMMON_DIR" in
"$REPO_ROOT" | "$REPO_ROOT"/*)
: # inside the checkout already, covered by the mount above
;;
*)
eprintln "Checkout is a git worktree, also mounting '$GIT_COMMON_DIR'"
RUNTIME_RUN_ARGS+=(
--mount type=bind,source="${GIT_COMMON_DIR}",target="${GIT_COMMON_DIR}"

# Each worktree admin directory holds a back-pointer to its
# worktree's *host* path, and those paths do not exist in the
# container (this checkout lives at $WORKDIR, the others are not
# mounted at all), so git considers every worktree prunable here.
# That is harmless for reading, but `git gc` -- which git runs
# automatically after commit/fetch/... -- prunes worktrees as
# part of its job and would delete the host's admin directories.
# Turn auto gc off; an explicit `git gc` remains the user's call.
-e GIT_CONFIG_COUNT=1
-e GIT_CONFIG_KEY_0=gc.auto
-e GIT_CONFIG_VALUE_0=0
)
;;
esac
fi

# Privilege/isolation flags required by the IC-OS guest build, per runtime.
if [ "$RUNTIME" = docker ]; then
# Under docker the IC-OS build runs (rootless) podman *inside* this
Expand Down
4 changes: 3 additions & 1 deletion ci/container/get-image-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -eEuo pipefail

cd "$(git rev-parse --show-toplevel)"
# Assign first: `cd "$(...)"` would silently `cd ""` (exit 0) if git failed.
REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "$REPO_ROOT"

INPUT_FILES=(
ci/container/Dockerfile
Expand Down
7 changes: 6 additions & 1 deletion ci/scripts/rust-lint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env bash
set -xeuo pipefail

cd "${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}"
# Note the assignment: `cd "$(git rev-parse ...)"` would `cd ""` and *succeed*
# (bash returns 0 for a null directory operand) if git failed, silently turning
# this script into a no-op that lints nothing and exits 0. An assignment, in
# contrast, takes the command substitution's exit status, so `set -e` fires.
REPO_ROOT="${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}"
cd "$REPO_ROOT"

cargo fmt -- --check

Expand Down
Loading