-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add support for sparse checkouts #1369
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/sh | ||
|
||
# Verify .git folder | ||
if [ ! -d "./sparse-checkout/.git" ]; then | ||
echo "Expected ./sparse-checkout/.git folder to exist" | ||
exit 1 | ||
fi | ||
|
||
# Verify sparse-checkout | ||
cd sparse-checkout | ||
|
||
SPARSE=$(git sparse-checkout list) | ||
|
||
if [ "$?" != "0" ]; then | ||
echo "Failed to validate sparse-checkout" | ||
exit 1 | ||
fi | ||
|
||
# Check that sparse-checkout list is not empty | ||
if [ -z "$SPARSE" ]; then | ||
echo "Expected sparse-checkout list to not be empty" | ||
exit 1 | ||
fi | ||
|
||
# Check that all folders of the sparse checkout exist | ||
for pattern in $SPARSE | ||
do | ||
if [ ! -d "$pattern" ]; then | ||
echo "Expected directory '$pattern' to exist" | ||
exit 1 | ||
fi | ||
done | ||
|
||
checkSparse () { | ||
if [ ! -d "./$1" ]; then | ||
echo "Expected directory '$1' to exist" | ||
exit 1 | ||
fi | ||
|
||
for file in $(git ls-tree -r --name-only HEAD $1) | ||
do | ||
if [ ! -f "$file" ]; then | ||
echo "Expected file '$file' to exist" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Check that all folders and their children have been checked out | ||
checkSparse __test__ | ||
checkSparse .github | ||
checkSparse dist | ||
|
||
# Check that only sparse-checkout folders have been checked out | ||
for pattern in $(git ls-tree --name-only HEAD) | ||
do | ||
if [ -d "$pattern" ]; then | ||
if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then | ||
echo "Expected directory '$pattern' to not exist" | ||
exit 1 | ||
fi | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,23 +153,26 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |
|
||
// Fetch | ||
core.startGroup('Fetching the repository') | ||
const fetchOptions: {filter?: string; fetchDepth?: number} = {} | ||
if (settings.sparseCheckout) fetchOptions.filter = 'blob:none' | ||
if (settings.fetchDepth <= 0) { | ||
// Fetch all branches and tags | ||
let refSpec = refHelper.getRefSpecForAllHistory( | ||
settings.ref, | ||
settings.commit | ||
) | ||
await git.fetch(refSpec) | ||
await git.fetch(refSpec, fetchOptions) | ||
|
||
// When all history is fetched, the ref we're interested in may have moved to a different | ||
// commit (push or force push). If so, fetch again with a targeted refspec. | ||
if (!(await refHelper.testRef(git, settings.ref, settings.commit))) { | ||
refSpec = refHelper.getRefSpec(settings.ref, settings.commit) | ||
await git.fetch(refSpec) | ||
await git.fetch(refSpec, fetchOptions) | ||
} | ||
} else { | ||
fetchOptions.fetchDepth = settings.fetchDepth | ||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit) | ||
await git.fetch(refSpec, settings.fetchDepth) | ||
await git.fetch(refSpec, fetchOptions) | ||
} | ||
core.endGroup() | ||
|
||
|
@@ -191,6 +194,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |
core.endGroup() | ||
} | ||
|
||
// Sparse checkout | ||
if (settings.sparseCheckout) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what will happen if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That shouldn't happen, you can see that the You can find this here |
||
core.startGroup('Setting up sparse checkout') | ||
await git.sparseCheckout(settings.sparseCheckout) | ||
core.endGroup() | ||
} | ||
|
||
// Checkout | ||
core.startGroup('Checking out the ref') | ||
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to have extra check to make sure git is greater than certain version that support
sparse-checkout
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @TingluoHuang git sparse-checkout is supported since the git version
2.26.0
and the current version onactions/checkout
of git is2.40.1
so I don't think this is something necessary 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current Git version on hosted runners is v2.40.1. But
actions/checkout
also supports self-hosted runners where users are often not at liberty to bump the Git version, e.g. because they're stuck on old Ubuntu LTS versions which simply refuse to move the needle.I added c4602b4 to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uu nice! I understand perfect ✨