Add sparse checkout support

This commit is contained in:
Jonne Laagland Winder 2022-01-31 23:14:53 +00:00
parent 230611dbd0
commit ad6eac3f6b
11 changed files with 128 additions and 0 deletions

View file

@ -38,6 +38,7 @@ export interface IGitCommandManager {
revParse(ref: string): Promise<string>
setEnvironmentVariable(name: string, value: string): void
shaExists(sha: string): Promise<boolean>
sparseCheckout(cone: boolean, paths: string[]): Promise<void>
submoduleForeach(command: string, recursive: boolean): Promise<string>
submoduleSync(recursive: boolean): Promise<void>
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
@ -292,6 +293,19 @@ class GitCommandManager {
return output.exitCode === 0
}
async sparseCheckout(cone: boolean, paths: string[]): Promise<void> {
const args1 = ['sparse-checkout', 'init']
if (cone) {
args1.push('--cone')
}
const args2 = ['sparse-checkout', 'set', '--', ...paths]
await this.execGit(args1)
await this.execGit(args2)
}
async submoduleForeach(command: string, recursive: boolean): Promise<string> {
const args = ['submodule', 'foreach']
if (recursive) {

View file

@ -163,6 +163,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
core.endGroup()
}
// Sparse checkout
if (settings.sparse) {
core.startGroup('Sparse checkout')
await git.sparseCheckout(settings.sparseCone, settings.sparse)
core.endGroup()
}
// Checkout
core.startGroup('Checking out the ref')
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)

View file

@ -78,4 +78,14 @@ export interface IGitSourceSettings {
* Organization ID for the currently running workflow (used for auth settings)
*/
workflowOrganizationId: number | undefined
/**
* Patterns to do a sparse checkout on
*/
sparse: string[] | null
/**
* Whether or not to use cone pattern on sparse checkout
*/
sparseCone: boolean
}

View file

@ -93,6 +93,19 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
core.debug(`lfs = ${result.lfs}`)
if (core.getInput('sparse')) {
const paths = core
.getInput('sparse')
.trim()
.split(`\n`)
.map(s => s.trim())
result.sparse = paths
}
result.sparseCone =
(core.getInput('sparse-cone') || 'false').toUpperCase() === 'TRUE'
// Submodules
result.submodules = false
result.nestedSubmodules = false