mirror of
git://f0xx.org/android_cast
synced 2026-07-29 06:58:51 +03:00
orchestration beginning
This commit is contained in:
124
scripts/ci-build-and-publish-ota.sh
Executable file
124
scripts/ci-build-and-publish-ota.sh
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env bash
|
||||
# CI pipeline entry: optional git checkout, native, gradle, OTA publish.
|
||||
#
|
||||
# Env:
|
||||
# GRADLE_TASK assembleDebug | assembleRelease | testDebugUnitTest | …
|
||||
# RUN_UNIT_TESTS 1 (default) | 0
|
||||
# RUN_NATIVE 1 (default) | 0
|
||||
# RUN_APK 1 (default) | 0 — set 0 for tests-only
|
||||
# OTA_BASE_URL public base for v0/ota (empty = skip OTA)
|
||||
# OTA_CHANNEL stable | staging | dev | nightly | custom name
|
||||
# AUTO_OTA 1 to emit OTA tree under OUT_DIR
|
||||
# OUT_DIR artifact root (default ./out/builds/$BUILD_ID)
|
||||
# BUILD_ID build record id
|
||||
# GIT_REF branch | tag | commit to checkout before build
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
BUILD_ID="${BUILD_ID:-local}"
|
||||
OUT_DIR="${OUT_DIR:-${ROOT}/out/builds/${BUILD_ID}}"
|
||||
GRADLE_TASK="${GRADLE_TASK:-assembleDebug}"
|
||||
RUN_UNIT_TESTS="${RUN_UNIT_TESTS:-1}"
|
||||
RUN_NATIVE="${RUN_NATIVE:-1}"
|
||||
RUN_APK="${RUN_APK:-1}"
|
||||
OTA_CHANNEL="${OTA_CHANNEL:-staging}"
|
||||
AUTO_OTA="${AUTO_OTA:-0}"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
exec > >(tee -a "${OUT_DIR}/build.log") 2>&1
|
||||
|
||||
echo "==> Phase: init build_id=${BUILD_ID} channel=${OTA_CHANNEL}"
|
||||
|
||||
if [[ -n "${GIT_REF:-}" ]]; then
|
||||
echo "==> Phase: git checkout ${GIT_REF}"
|
||||
git fetch --all --tags 2>/dev/null || true
|
||||
git checkout --force "$GIT_REF"
|
||||
if [[ -n "${GIT_SHA:-}" ]]; then
|
||||
git reset --hard "$GIT_SHA"
|
||||
fi
|
||||
fi
|
||||
|
||||
export ANDROIDCAST_ROOT="$ROOT"
|
||||
export ANDROIDCAST_CCACHE="${ANDROIDCAST_CCACHE:-1}"
|
||||
# shellcheck source=android-ndk.sh
|
||||
source "$ROOT/scripts/android-ndk.sh"
|
||||
export ANDROID_NDK_HOME="$(androidcast_find_ndk_root "$ROOT")"
|
||||
export ANDROID_NDK_ROOT="$ANDROID_NDK_HOME"
|
||||
|
||||
if [[ "$RUN_NATIVE" == "1" && "$RUN_APK" == "1" ]]; then
|
||||
echo "==> Phase: native codecs"
|
||||
ABIS="${ANDROIDCAST_CI_ABIS:-armeabi-v7a arm64-v8a x86_64}"
|
||||
rm -rf "$ROOT/build/native"
|
||||
mkdir -p "$ROOT/build/native"
|
||||
for abi in $ABIS; do
|
||||
./scripts/build-native-codecs.sh "$abi"
|
||||
done
|
||||
else
|
||||
echo "==> Phase: native codecs (skipped)"
|
||||
fi
|
||||
|
||||
if [[ "$RUN_APK" == "1" ]]; then
|
||||
echo "==> Phase: gradle ${GRADLE_TASK}"
|
||||
if [[ "$RUN_UNIT_TESTS" == "1" ]]; then
|
||||
./gradlew --no-daemon clean "${GRADLE_TASK}" testDebugUnitTest
|
||||
else
|
||||
./gradlew --no-daemon clean "${GRADLE_TASK}"
|
||||
fi
|
||||
else
|
||||
echo "==> Phase: gradle tests-only"
|
||||
./gradlew --no-daemon testDebugUnitTest
|
||||
fi
|
||||
|
||||
APK=""
|
||||
if [[ "$RUN_APK" == "1" ]]; then
|
||||
for candidate in \
|
||||
"$ROOT/app/build/outputs/apk/debug/app-debug.apk" \
|
||||
"$ROOT/app/build/outputs/apk/release/app-release-unsigned.apk" \
|
||||
"$ROOT/app/build/outputs/apk/release/app-release.apk"; do
|
||||
if [[ -f "$candidate" ]]; then
|
||||
APK="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z "$APK" ]]; then
|
||||
echo "ERROR: no APK produced" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp -f "$APK" "${OUT_DIR}/android_cast-latest.apk"
|
||||
echo "==> APK: ${OUT_DIR}/android_cast-latest.apk"
|
||||
fi
|
||||
|
||||
if [[ "$AUTO_OTA" == "1" && -n "${OTA_BASE_URL:-}" && -n "$APK" ]]; then
|
||||
echo "==> Phase: OTA publish channel=${OTA_CHANNEL}"
|
||||
OTA_PUBLISH="${OUT_DIR}/ota-publish"
|
||||
rm -rf "$OTA_PUBLISH"
|
||||
./scripts/generate-ota-v0.sh "$APK" "$OTA_BASE_URL" "$OTA_PUBLISH" "$OTA_CHANNEL"
|
||||
mkdir -p "${OUT_DIR}/ota"
|
||||
cp -rf "${OTA_PUBLISH}/v0" "${OUT_DIR}/ota/"
|
||||
for ch in staging dev nightly stable; do
|
||||
if [[ "$OTA_CHANNEL" == "$ch" ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ "$OTA_CHANNEL" == "stable" || "$OTA_CHANNEL" == "prod" || "$OTA_CHANNEL" == "production" || "$OTA_CHANNEL" == "release" ]]; then
|
||||
./scripts/generate-ota-v0.sh "$APK" "$OTA_BASE_URL" "${OUT_DIR}/ota-publish-${ch}" "$ch" || true
|
||||
mkdir -p "${OUT_DIR}/ota-${ch}"
|
||||
cp -rf "${OUT_DIR}/ota-publish-${ch}/v0" "${OUT_DIR}/ota-${ch}/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
cat >"${OUT_DIR}/BUILD_INFO.json" <<EOF
|
||||
{
|
||||
"buildId": "${BUILD_ID}",
|
||||
"gradleTask": "${GRADLE_TASK}",
|
||||
"otaChannel": "${OTA_CHANNEL}",
|
||||
"apk": "android_cast-latest.apk",
|
||||
"gitSha": "$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || echo unknown)",
|
||||
"gitRef": "${GIT_REF:-}",
|
||||
"ciVersion": "${ANDROIDCAST_CI_VERSION:-00.01.00.1000}"
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "==> Phase: done"
|
||||
47
scripts/docker-build-runner.sh
Executable file
47
scripts/docker-build-runner.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host wrapper: build CI image + run pipeline with log capture.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/docker-build-runner.sh --build-id 42 --workdir /path/to/repo
|
||||
#
|
||||
# Env: see ci-build-and-publish-ota.sh
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
IMAGE="${ANDROIDCAST_CI_IMAGE:-androidcast-ci:latest}"
|
||||
CI_VERSION="${ANDROIDCAST_CI_VERSION:-00.01.00.1000}"
|
||||
BUILD_ID="${BUILD_ID:-local}"
|
||||
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}}"
|
||||
|
||||
mkdir -p "$(dirname "$LOG_FILE")" "$OUT_DIR"
|
||||
|
||||
echo "[runner] image=${IMAGE} ci_version=${CI_VERSION} build_id=${BUILD_ID}" | tee -a "$LOG_FILE"
|
||||
echo "[runner] workdir=${WORK_DIR} out=${OUT_DIR}" | tee -a "$LOG_FILE"
|
||||
|
||||
docker build \
|
||||
--build-arg ANDROIDCAST_CI_VERSION="${CI_VERSION}" \
|
||||
-t "$IMAGE" \
|
||||
-f "${ROOT}/Dockerfile" \
|
||||
"${ROOT}" 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
docker run --rm \
|
||||
-v "${WORK_DIR}:/workspace" \
|
||||
-v "${ROOT}/out:/workspace/out" \
|
||||
-w /workspace \
|
||||
-e BUILD_ID="${BUILD_ID}" \
|
||||
-e OUT_DIR="/workspace/out/builds/${BUILD_ID}" \
|
||||
-e OTA_BASE_URL="${OTA_BASE_URL:-}" \
|
||||
-e OTA_CHANNEL="${OTA_CHANNEL:-staging}" \
|
||||
-e GRADLE_TASK="${GRADLE_TASK:-assembleDebug}" \
|
||||
-e RUN_UNIT_TESTS="${RUN_UNIT_TESTS:-1}" \
|
||||
-e RUN_NATIVE="${RUN_NATIVE:-1}" \
|
||||
-e AUTO_OTA="${AUTO_OTA:-0}" \
|
||||
-e GIT_REF="${GIT_REF:-}" \
|
||||
-e GIT_SHA="${GIT_SHA:-}" \
|
||||
-e RELEASE_NOTES="${RELEASE_NOTES:-}" \
|
||||
"$IMAGE" \
|
||||
./scripts/ci-build-and-publish-ota.sh 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
echo "[runner] finished build_id=${BUILD_ID}" | tee -a "$LOG_FILE"
|
||||
@@ -2,8 +2,9 @@
|
||||
# Generate v0 OTA artifacts for one APK (stdout = channel stable.json).
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/generate-ota-v0.sh path/to/app-release.apk https://host[:port] [out-dir]
|
||||
# ./scripts/generate-ota-v0.sh path/to/app-release.apk https://host[:port] [out-dir] [channel]
|
||||
#
|
||||
# channel — JSON under v0/ota/channel/ (stable, staging, dev, nightly, or custom)
|
||||
# Writes under out-dir (default: ./ota-publish):
|
||||
# v0/ota/channel/stable.json
|
||||
# v0/ota/00/00.MM/00.MM.mm/android_cast_00.MM.mm.BB_manifest.json
|
||||
@@ -15,6 +16,7 @@ set -euo pipefail
|
||||
apk="${1:?APK path required}"
|
||||
host_base="${2:?Base URL required, e.g. https://192.168.1.1:8080}"
|
||||
out_dir="${3:-ota-publish}"
|
||||
channel="${4:-stable}"
|
||||
|
||||
if [[ ! -f "$apk" ]]; then
|
||||
echo "APK not found: $apk" >&2
|
||||
@@ -115,7 +117,8 @@ cat >"${rel_dir}/${manifest_name}" <<EOF
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >"${rel_root}/channel/stable.json" <<EOF
|
||||
channel_file="${rel_root}/channel/${channel}.json"
|
||||
cat >"${channel_file}" <<EOF
|
||||
{
|
||||
"schema": "v0",
|
||||
"manifestUrl": "${manifest_url}"
|
||||
@@ -123,6 +126,6 @@ cat >"${rel_root}/channel/stable.json" <<EOF
|
||||
EOF
|
||||
|
||||
echo "Published v0 OTA under ${out_dir}/v0/ota" >&2
|
||||
echo "Channel: ${host_base%/}/v0/ota/channel/stable.json" >&2
|
||||
echo "Channel: ${host_base%/}/v0/ota/channel/${channel}.json" >&2
|
||||
echo "Bundle: ${bundle_url} (${bundle_size} bytes)" >&2
|
||||
cat "${rel_root}/channel/stable.json"
|
||||
cat "${channel_file}"
|
||||
|
||||
Reference in New Issue
Block a user