Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: multiple patterns for sparse-checkout #123

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
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
71 changes: 49 additions & 22 deletions tools/archive-sparse-checkout.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
#!/bin/sh
#!/bin/bash

die() {
echo "${@}"
exit 1
}

if [ -z "$ARCH" ]; then
ARCH="*"
else
case ${ARCH} in
"x86_64")
ARCH="x86_64"
;;
"aarch64"|"arm64")
ARCH="arm64"
;;
*)
die "unsupported architecture: ${ARCH}"
;;
esac
if [ -z "$VERSION" ]; then
VERSION="*"
fi

if [ -z "$DISTRO" ]; then
DISTRO="*"
fi
set -f # disable globbing
DISTROS=${DISTRO:-"*"}
ARCHS=${ARCH:-"*"}

if [ -z "$VERSION" ]; then
VERSION="*"
ARCHS="${ARCHS//aarch64/arm64}"
for arch in $ARCHS; do
case $arch in
x86_64|arm64|'*')
;;
*)
die "invalid ARCH: $arch"
;;
esac
done
set +f # enable globbing

IFS=' ' read -r -a DISTROS_ARRAY <<< "$DISTROS"
IFS=' ' read -r -a ARCHS_ARRAY <<< "$ARCHS"

# count the number of elements
NUM_DISTROS=${#DISTROS_ARRAY[@]}
NUM_ARCHS=${#ARCHS_ARRAY[@]}

if [ "$VERSION" != "*" ] && { [ "$NUM_DISTROS" -gt 1 ] || [ "$NUM_ARCHS" -gt 1 ]; }; then
die "VERSION must be * when DISTRO or ARCH are arrays"
fi

BASE_DIR=$(dirname "$(realpath "$0")")
Expand All @@ -46,11 +53,31 @@ else
git clone --sparse --filter=blob:none "$REPO_URL" "$ARCHIVE_DIR"
fi

SPARSE_CHECKOUT_FILE="$ARCHIVE_DIR/.git/info/sparse-checkout"
true > "$SPARSE_CHECKOUT_FILE" # clear existing file

# initialize sparse-checkout
git -C "$ARCHIVE_DIR" sparse-checkout init --no-cone

# write patterns for the files we want to pull
echo "$DISTRO/$VERSION/$ARCH/*.btf.tar.xz" > "$ARCHIVE_DIR/.git/info/sparse-checkout"
echo "Settings patterns to $SPARSE_CHECKOUT_FILE file..."
if [ "$NUM_DISTROS" -eq 1 ] && [ "$NUM_ARCHS" -eq 1 ]; then
echo "${DISTROS_ARRAY[0]}/$VERSION/${ARCHS_ARRAY[0]}/*.btf.tar.xz" | tee "$SPARSE_CHECKOUT_FILE"
elif [ "$NUM_DISTROS" -gt 1 ] && [ "$NUM_ARCHS" -eq 1 ]; then
for distro in "${DISTROS_ARRAY[@]}"; do
echo "$distro/*/${ARCHS_ARRAY[0]}/*.btf.tar.xz" | tee -a "$SPARSE_CHECKOUT_FILE"
done
elif [ "$NUM_DISTROS" -eq 1 ] && [ "$NUM_ARCHS" -gt 1 ]; then
for arch in "${ARCHS_ARRAY[@]}"; do
echo "${DISTROS_ARRAY[0]}/*/$arch/*.btf.tar.xz" | tee -a "$SPARSE_CHECKOUT_FILE"
done
else
for distro in "${DISTROS_ARRAY[@]}"; do
for arch in "${ARCHS_ARRAY[@]}"; do
echo "$distro/*/$arch/*.btf.tar.xz" | tee -a "$SPARSE_CHECKOUT_FILE"
done
done
fi

git -C "$ARCHIVE_DIR" sparse-checkout reapply || die "failed to reapply sparse-checkout"

echo "Sparse checkout completed successfully in $ARCHIVE_DIR"
Loading