Skip to content

Commit

Permalink
Use sparse-checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
cucxabong committed Apr 11, 2024
1 parent 5bf92cd commit b7adea0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ inputs:
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
filter:
description: >
Partially clone against a given filter.
default: ""
use_sparse_checkout:
description: >
Wheter to use sparse-checkout
default: false
sparse_checkout:
description: >
Do a sparse checkout on given patterns.
Each pattern should be separated with a space.
default: ""
merge:
description: >
Whether to actually merge the pull request or only check whether
Expand Down Expand Up @@ -57,6 +70,9 @@ runs:
export GITHUB_TOKEN=${{ inputs.github_token }}
export DEBUG=${{ inputs.debug }}
export COMMENT=${{ inputs.comment }}
export FILTER=${{ inputs.filter }}
export USE_SPARSE_CHECKOUT=${{ inputs.use_sparse_checkout}}
export SPARSE_CHECKOUT="${{ inputs.sparse_checkout }}"
# github.action_path is set to $REPO.
if test "x${{ inputs.merge }}" = xtrue
Expand Down
34 changes: 32 additions & 2 deletions src/fast-forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# And a comment is posted (if possible).

set -e
set -ex

# Set to 1 to get some debugging information dumped to stderr.
case "${DEBUG:-0}" in
Expand All @@ -34,6 +34,21 @@ case "${DEBUG:-0}" in
;;
esac

filter_string=""
if [[ -n "${FILTER:-}" ]]
then
filter_string="--filter=${FILTER}"
fi

case "${USE_SPARSE_CHECKOUT:-false}" in
0 | false | False| FALSE) USE_SPARSE_CHECKOUT=false;;
1 | true | True | TRUE) USE_SPARSE_CHECKOUT=true;;
*)
echo "Warning: Invalid value ('$USE_SPARSE_CHECKOUT') for USE_SPARSE_CHECKOUT." >&2;
USE_SPARSE_CHECKOUT=false
;;
esac

# Set to true to post a comment to the issue.
case "${COMMENT:-true}" in
0 | never | false | FALSE) COMMENT=never;;
Expand Down Expand Up @@ -180,8 +195,23 @@ LOG=$(mktemp)
} | git credential approve

CLONE_URL="${CLONE_URL%://*}://${GITHUB_ACTOR}@${CLONE_URL#*://}"
git clone --quiet --single-branch --filter=blob:none --branch "$BASE_REF" "$CLONE_URL" .
git clone --quiet ${filter_string} --no-checkout "$CLONE_URL" .

if [[ ${USE_SPARSE_CHECKOUT} == true ]]
then
echo "Initialize sparse-checkout"
git sparse-checkout init
if [[ -n "${SPARSE_CHECKOUT}" ]]
then
set -x
ls -la
git sparse-checkout add ${SPARSE_CHECKOUT}
ls -la
fi
fi
git checkout "$BASE_REF"
ls -la
set +x
BASE_SHA="$(git rev-parse origin/$BASE_REF 2>/dev/null)"
fi

Expand Down

0 comments on commit b7adea0

Please sign in to comment.