build: fallback to GitHub archive on fetch failure
If git fetch fails for a GitHub branch, download and extract the branch archive tarball. Also tolerate missing .git when reading u-boot/kernel hash.
This commit is contained in:
parent
5609b17e9e
commit
f84cd6a168
|
|
@ -137,7 +137,11 @@ compile_uboot()
|
|||
# read uboot version
|
||||
local version hash
|
||||
version=$(grab_version "$ubootdir")
|
||||
hash=$(improved_git --git-dir="$ubootdir"/.git rev-parse HEAD)
|
||||
if [[ -d "$ubootdir"/.git ]]; then
|
||||
hash=$(improved_git --git-dir="$ubootdir"/.git rev-parse HEAD 2>/dev/null || true)
|
||||
else
|
||||
hash="nogit"
|
||||
fi
|
||||
|
||||
display_alert "Compiling u-boot" "v$version" "info"
|
||||
|
||||
|
|
@ -390,7 +394,11 @@ compile_kernel()
|
|||
version=$(grab_version "$kerneldir")
|
||||
|
||||
# read kernel git hash
|
||||
hash=$(improved_git --git-dir="$kerneldir"/.git rev-parse HEAD)
|
||||
if [[ -d "$kerneldir"/.git ]]; then
|
||||
hash=$(improved_git --git-dir="$kerneldir"/.git rev-parse HEAD 2>/dev/null || true)
|
||||
else
|
||||
hash="nogit"
|
||||
fi
|
||||
|
||||
# Apply a series of patches if a series file exists
|
||||
if test -f "${EXTER}"/patch/kernel/${KERNELPATCHDIR}/series.conf; then
|
||||
|
|
|
|||
|
|
@ -350,6 +350,42 @@ clean_up_git ()
|
|||
git -C $target_dir checkout -qf HEAD
|
||||
}
|
||||
|
||||
# Fallback for environments where large git pack transfers are unreliable.
|
||||
# Downloads a GitHub branch archive and extracts it into the workdir.
|
||||
fetch_from_github_archive()
|
||||
{
|
||||
local upstream_url=$1
|
||||
local workdir=$2
|
||||
local ref_name=$3
|
||||
|
||||
[[ $upstream_url == https://github.com/* ]] || return 1
|
||||
[[ -n $ref_name ]] || return 1
|
||||
|
||||
local base=${upstream_url%.git}
|
||||
local tar_url="${base}/archive/refs/heads/${ref_name}.tar.gz"
|
||||
local archive_dir="${EXTER}/cache/sources/.github-archives"
|
||||
local tar_path="${archive_dir}/$(basename "${base}")-${ref_name}.tar.gz"
|
||||
|
||||
mkdir -p "${archive_dir}" || return 1
|
||||
|
||||
display_alert "Downloading GitHub archive" "${tar_url}" "wrn"
|
||||
# -c enables resume; keep a cached tarball in EXTER/cache/sources
|
||||
wget -q -c -t 10 --timeout=30 --waitretry=5 -O "${tar_path}" "${tar_url}" || return 1
|
||||
|
||||
display_alert "Extracting archive" "${workdir}" "wrn"
|
||||
mkdir -p "${workdir}" || return 1
|
||||
(
|
||||
cd "${workdir}" || exit 1
|
||||
rm -rf ./* ./.??* 2>/dev/null || true
|
||||
)
|
||||
|
||||
tar -xzf "${tar_path}" -C "${workdir}" --strip-components=1 || return 1
|
||||
|
||||
# Mark as archive-based sources (helps debugging; no functional dependency)
|
||||
echo "${tar_url}" > "${workdir}/.orangepi-source-archive" 2>/dev/null || true
|
||||
return 0
|
||||
}
|
||||
|
||||
# used : waiter_local_git arg1='value' arg2:'value'
|
||||
# waiter_local_git \
|
||||
# url='https://github.com/megous/linux' \
|
||||
|
|
@ -655,7 +691,16 @@ fetch_from_repo()
|
|||
esac
|
||||
fetch_status=$?
|
||||
fi
|
||||
[[ $fetch_status -ne 0 ]] && exit_with_error "Failed to fetch git sources" "${url} ${ref}"
|
||||
if [[ $fetch_status -ne 0 ]]; then
|
||||
# If we're targeting a GitHub branch, fall back to downloading the branch archive.
|
||||
if [[ $ref_type == branch && $upstream_url == https://github.com/* ]]; then
|
||||
display_alert "Git fetch failed; using archive fallback" "${ref_name}" "wrn"
|
||||
# Ensure we don't keep a broken git repository around.
|
||||
rm -rf "${workdir}/.git" 2>/dev/null || true
|
||||
fetch_from_github_archive "${upstream_url}" "${workdir}" "${ref_name}" && return 0
|
||||
fi
|
||||
exit_with_error "Failed to fetch git sources" "${url} ${ref}"
|
||||
fi
|
||||
|
||||
# commit type needs support for older git servers that doesn't support fetching id directly
|
||||
if [[ $ref_type == commit ]]; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue