1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 04:38:53 +03:00
This commit is contained in:
Anton Afanasyeu
2026-06-05 16:38:33 +02:00
parent a7e71bb39c
commit b47e05490f
3 changed files with 74 additions and 5 deletions

View File

@@ -31,6 +31,9 @@ return [
'ota_mount' => '/workspace/orchestration/runtime/ota-artifacts',
'ota_base_url' => 'http://localhost:8080',
'runner_script' => '/workspace/scripts/docker-build-runner.sh',
// Per-build shallow clone to out/builds/{id}/src (safe for parallel jobs)
'isolate_source' => true,
'git_clone_depth' => 1,
// Repo copy preferred; generated YAML used if missing on builder host
'pipeline_config' => '/workspace/build.config.yml',
'default_channels' => ['stable', 'staging', 'dev', 'nightly'],

View File

@@ -142,6 +142,8 @@ YAML;
'BUILD_ID=' . $id,
'BUILD_LOG_FILE=' . escapeshellarg($logPath),
'BUILD_LOG_STDOUT_ONLY=1',
'BUILD_ISOLATE_SOURCE=' . (cfg('build.isolate_source', true) ? '1' : '0'),
'BUILD_GIT_DEPTH=' . max(1, (int) cfg('build.git_clone_depth', 1)),
'BUILD_WORK_DIR=' . escapeshellarg($repo),
'BUILD_OUT_DIR=' . escapeshellarg($dir),
'ANDROIDCAST_CI_VERSION=' . escapeshellarg((string) cfg('build.ci_version', '00.01.00.1000')),

View File

@@ -6,6 +6,9 @@
#
# Env: see ci-build-and-publish-ota.sh
# When invoked from PHP (BUILD_LOG_STDOUT_ONLY=1), log via stdout only — parent redirects to build.log.
#
# Parallel builds: set BUILD_ISOLATE_SOURCE=1 (default from builder) to shallow-clone into
# $OUT_DIR/src instead of mutating the shared deploy checkout.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -16,6 +19,10 @@ LOG_FILE="${BUILD_LOG_FILE:-${ROOT}/out/builds/${BUILD_ID}/build.log}"
WORK_DIR="${BUILD_WORK_DIR:-${ROOT}}"
OUT_DIR="${BUILD_OUT_DIR:-${WORK_DIR}/out/builds/${BUILD_ID}}"
LOG_STDOUT_ONLY="${BUILD_LOG_STDOUT_ONLY:-0}"
ISOLATE_SOURCE="${BUILD_ISOLATE_SOURCE:-1}"
CLONE_DEPTH="${BUILD_GIT_DEPTH:-1}"
SOURCE_DIR="${OUT_DIR}/src"
DOCKER_WORKSPACE="${WORK_DIR}"
mkdir -p "$(dirname "$LOG_FILE")" "$OUT_DIR"
@@ -40,16 +47,73 @@ git_safe() {
git -c safe.directory="${WORK_DIR}" "$@"
}
log "[runner] image=${IMAGE} ci_version=${CI_VERSION} build_id=${BUILD_ID}"
log "[runner] workdir=${WORK_DIR} out=${OUT_DIR}"
resolve_git_remote() {
if [[ -n "${GIT_REMOTE:-}" ]]; then
echo "$GIT_REMOTE"
return
fi
if [[ -d "${WORK_DIR}/.git" ]]; then
git_safe -C "${WORK_DIR}" remote get-url origin 2>/dev/null || true
fi
}
if [[ -n "${GIT_REF:-}" ]] && [[ -d "${WORK_DIR}/.git" ]]; then
log "[runner] syncing git ref=${GIT_REF}"
prepare_isolated_source() {
local ref="${GIT_REF:-}"
local remote sha
remote="$(resolve_git_remote)"
if [[ -z "$ref" || -z "$remote" ]]; then
log "[runner] isolate: skip (need GIT_REF and origin remote)"
return 0
fi
rm -rf "${SOURCE_DIR}"
mkdir -p "${SOURCE_DIR}"
log "[runner] isolate: shallow clone depth=${CLONE_DEPTH} ref=${ref} -> ${SOURCE_DIR}"
if git clone --depth "${CLONE_DEPTH}" --recurse-submodules --shallow-submodules \
--single-branch --branch "${ref}" "${remote}" "${SOURCE_DIR}" 2>/dev/null; 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 \
"${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}"
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}"
fi
run_logged git -c safe.directory="${SOURCE_DIR}" -C "${SOURCE_DIR}" rev-parse HEAD
DOCKER_WORKSPACE="${SOURCE_DIR}"
}
sync_shared_checkout() {
if [[ -z "${GIT_REF:-}" ]] || [[ ! -d "${WORK_DIR}/.git" ]]; then
return 0
fi
log "[runner] syncing shared checkout ref=${GIT_REF}"
run_logged git_safe -C "${WORK_DIR}" fetch origin --prune || true
run_logged git_safe -C "${WORK_DIR}" checkout "${GIT_REF}"
run_logged git_safe -C "${WORK_DIR}" pull --rebase origin "${GIT_REF}" || true
run_logged git_safe -C "${WORK_DIR}" rev-parse HEAD
if [[ -n "${GIT_SHA:-}" ]]; then
run_logged git_safe -C "${WORK_DIR}" checkout "${GIT_SHA}"
fi
run_logged git_safe -C "${WORK_DIR}" rev-parse HEAD
}
log "[runner] image=${IMAGE} ci_version=${CI_VERSION} build_id=${BUILD_ID}"
log "[runner] workdir=${WORK_DIR} out=${OUT_DIR} isolate=${ISOLATE_SOURCE}"
if [[ "$ISOLATE_SOURCE" == "1" ]]; then
prepare_isolated_source
else
sync_shared_checkout
fi
log "[runner] docker workspace=${DOCKER_WORKSPACE}"
run_logged docker build \
--build-arg ANDROIDCAST_CI_VERSION="${CI_VERSION}" \
@@ -58,7 +122,7 @@ run_logged docker build \
"${ROOT}"
run_logged docker run --rm \
-v "${WORK_DIR}:/workspace" \
-v "${DOCKER_WORKSPACE}:/workspace" \
-v "${ROOT}/out:/workspace/out" \
-w /workspace \
-e BUILD_ID="${BUILD_ID}" \