1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 03:38:52 +03:00

sync BE/builders

This commit is contained in:
Anton Afanasyeu
2026-06-05 16:46:31 +02:00
parent b47e05490f
commit 7dc992fb19
6 changed files with 168 additions and 24 deletions

View File

@@ -9,6 +9,7 @@
#
# Parallel builds: set BUILD_ISOLATE_SOURCE=1 (default from builder) to shallow-clone into
# $OUT_DIR/src instead of mutating the shared deploy checkout.
# Per-build step logs: $OUT_DIR/docker-build.log, $OUT_DIR/docker-run.log (also echoed to build.log).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -23,6 +24,7 @@ ISOLATE_SOURCE="${BUILD_ISOLATE_SOURCE:-1}"
CLONE_DEPTH="${BUILD_GIT_DEPTH:-1}"
SOURCE_DIR="${OUT_DIR}/src"
DOCKER_WORKSPACE="${WORK_DIR}"
CONTAINER_NAME="androidcast-bld-${BUILD_ID}"
mkdir -p "$(dirname "$LOG_FILE")" "$OUT_DIR"
@@ -42,6 +44,36 @@ run_logged() {
fi
}
# Mirror command output to build.log (stdout) and a per-build step file for parallel debugging.
run_step() {
local step_name="$1"
shift
local step_log="${OUT_DIR}/${step_name}.log"
log "[runner] step ${step_name} -> ${step_log}"
"$@" 2>&1 | tee -a "${step_log}"
}
on_runner_err() {
local ec=$?
log "[runner] ERROR: command failed (exit ${ec}) at ${BASH_SOURCE[0]}:${LINENO}: ${BASH_COMMAND}"
if command -v docker >/dev/null 2>&1; then
if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -qx "${CONTAINER_NAME}"; then
log "[runner] docker logs ${CONTAINER_NAME} (last 100 lines):"
docker logs --tail 100 "${CONTAINER_NAME}" 2>&1 | while IFS= read -r line; do log "$line"; done
fi
fi
echo "${ec}" > "${OUT_DIR}/runner.exit"
exit "${ec}"
}
on_runner_exit() {
local ec=$?
echo "${ec}" > "${OUT_DIR}/runner.exit"
}
trap on_runner_err ERR
trap on_runner_exit EXIT
# Git 2.35+ refuses repos owned by another uid (PHP-FPM nginx vs deploy user).
git_safe() {
git -c safe.directory="${WORK_DIR}" "$@"
@@ -69,24 +101,24 @@ prepare_isolated_source() {
rm -rf "${SOURCE_DIR}"
mkdir -p "${SOURCE_DIR}"
log "[runner] isolate: shallow clone depth=${CLONE_DEPTH} ref=${ref} -> ${SOURCE_DIR}"
log "[runner] isolate: shallow clone depth=${CLONE_DEPTH} ref=${ref} remote=${remote} -> ${SOURCE_DIR}"
if git clone --depth "${CLONE_DEPTH}" --recurse-submodules --shallow-submodules \
--single-branch --branch "${ref}" "${remote}" "${SOURCE_DIR}" 2>/dev/null; then
--single-branch --branch "${ref}" "${remote}" "${SOURCE_DIR}"; then
:
else
log "[runner] isolate: branch clone failed; clone default branch then checkout ${ref}"
run_logged git clone --depth "${CLONE_DEPTH}" --recurse-submodules --shallow-submodules \
run_step git-clone git clone --depth "${CLONE_DEPTH}" --recurse-submodules --shallow-submodules \
"${remote}" "${SOURCE_DIR}"
run_logged git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" fetch --depth "${CLONE_DEPTH}" origin "${ref}"
run_logged git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" checkout "${ref}"
run_step git-fetch git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" fetch --depth "${CLONE_DEPTH}" origin "${ref}"
run_step git-checkout git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" checkout "${ref}"
fi
if [[ -n "${GIT_SHA:-}" ]]; then
log "[runner] isolate: checkout pin GIT_SHA=${GIT_SHA}"
run_logged git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" checkout "${GIT_SHA}"
run_step git-pin git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" checkout "${GIT_SHA}"
fi
run_logged git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" rev-parse HEAD
run_step git-rev-parse git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" rev-parse HEAD
DOCKER_WORKSPACE="${SOURCE_DIR}"
}
@@ -104,7 +136,7 @@ sync_shared_checkout() {
run_logged git_safe -C "${WORK_DIR}" rev-parse HEAD
}
log "[runner] image=${IMAGE} ci_version=${CI_VERSION} build_id=${BUILD_ID}"
log "[runner] image=${IMAGE} ci_version=${CI_VERSION} build_id=${BUILD_ID} container=${CONTAINER_NAME}"
log "[runner] workdir=${WORK_DIR} out=${OUT_DIR} isolate=${ISOLATE_SOURCE}"
if [[ "$ISOLATE_SOURCE" == "1" ]]; then
@@ -115,13 +147,13 @@ fi
log "[runner] docker workspace=${DOCKER_WORKSPACE}"
run_logged docker build \
run_step docker-build docker build \
--build-arg ANDROIDCAST_CI_VERSION="${CI_VERSION}" \
-t "$IMAGE" \
-f "${ROOT}/Dockerfile" \
"${ROOT}"
run_logged docker run --rm \
run_step docker-run docker run --rm --name "${CONTAINER_NAME}" \
-v "${DOCKER_WORKSPACE}:/workspace" \
-v "${ROOT}/out:/workspace/out" \
-w /workspace \