Add fetchJobs option to parallelize submodule updates

This commit is contained in:
Frits Talbot 2020-08-09 23:30:32 +02:00
parent 2036a08e25
commit ad5dc19390
9 changed files with 49 additions and 5 deletions

View file

@ -93,6 +93,11 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
# Default: 1 # Default: 1
fetch-depth: '' fetch-depth: ''
# Number of fetches to perform simultaneously when updating submodules. 0
# indicates default (serial updates).
# Default: 0
fetch-jobs: ''
# Whether to download Git-LFS files # Whether to download Git-LFS files
# Default: false # Default: false
lfs: '' lfs: ''

View file

@ -760,6 +760,7 @@ async function setup(testName: string): Promise<void> {
clean: true, clean: true,
commit: '', commit: '',
fetchDepth: 1, fetchDepth: 1,
fetchJobs: 0,
lfs: false, lfs: false,
submodules: false, submodules: false,
nestedSubmodules: false, nestedSubmodules: false,

View file

@ -75,6 +75,7 @@ describe('input-helper tests', () => {
expect(settings.commit).toBeTruthy() expect(settings.commit).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890') expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.fetchDepth).toBe(1) expect(settings.fetchDepth).toBe(1)
expect(settings.fetchJobs).toBe(0)
expect(settings.lfs).toBe(false) expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref') expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.repositoryName).toBe('some-repo') expect(settings.repositoryName).toBe('some-repo')

View file

@ -56,6 +56,9 @@ inputs:
fetch-depth: fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.' description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
default: 1 default: 1
fetch-jobs:
description: 'Number of fetches to perform simultaneously when updating submodules. 0 indicates default (serial updates).'
default: 0
lfs: lfs:
description: 'Whether to download Git-LFS files' description: 'Whether to download Git-LFS files'
default: false default: false

13
dist/index.js vendored
View file

@ -5939,7 +5939,7 @@ class GitCommandManager {
yield this.execGit(args); yield this.execGit(args);
}); });
} }
submoduleUpdate(fetchDepth, recursive) { submoduleUpdate(fetchDepth, recursive, fetchJobs) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const args = ['-c', 'protocol.version=2']; const args = ['-c', 'protocol.version=2'];
args.push('submodule', 'update', '--init', '--force'); args.push('submodule', 'update', '--init', '--force');
@ -5949,6 +5949,9 @@ class GitCommandManager {
if (recursive) { if (recursive) {
args.push('--recursive'); args.push('--recursive');
} }
if (fetchJobs > 0) {
args.push(`--jobs=${fetchJobs}`);
}
yield this.execGit(args); yield this.execGit(args);
}); });
} }
@ -6252,7 +6255,7 @@ function getSource(settings) {
// Checkout submodules // Checkout submodules
core.startGroup('Fetching submodules'); core.startGroup('Fetching submodules');
yield git.submoduleSync(settings.nestedSubmodules); yield git.submoduleSync(settings.nestedSubmodules);
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules); yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules, settings.fetchJobs);
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules); yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
core.endGroup(); core.endGroup();
// Persist credentials // Persist credentials
@ -14567,6 +14570,12 @@ function getInputs() {
result.fetchDepth = 0; result.fetchDepth = 0;
} }
core.debug(`fetch depth = ${result.fetchDepth}`); core.debug(`fetch depth = ${result.fetchDepth}`);
// Fetch jobs
result.fetchJobs = Math.floor(Number(core.getInput('fetch-jobs') || '0'));
if (isNaN(result.fetchJobs) || result.fetchJobs < 0) {
result.fetchJobs = 0;
}
core.debug(`fetch jobs = ${result.fetchJobs}`);
// LFS // LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'; result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
core.debug(`lfs = ${result.lfs}`); core.debug(`lfs = ${result.lfs}`);

View file

@ -39,7 +39,11 @@ export interface IGitCommandManager {
shaExists(sha: string): Promise<boolean> shaExists(sha: string): Promise<boolean>
submoduleForeach(command: string, recursive: boolean): Promise<string> submoduleForeach(command: string, recursive: boolean): Promise<string>
submoduleSync(recursive: boolean): Promise<void> submoduleSync(recursive: boolean): Promise<void>
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> submoduleUpdate(
fetchDepth: number,
recursive: boolean,
fetchJobs: number
): Promise<void>
tagExists(pattern: string): Promise<boolean> tagExists(pattern: string): Promise<boolean>
tryClean(): Promise<boolean> tryClean(): Promise<boolean>
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean> tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
@ -308,7 +312,11 @@ class GitCommandManager {
await this.execGit(args) await this.execGit(args)
} }
async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> { async submoduleUpdate(
fetchDepth: number,
recursive: boolean,
fetchJobs: number
): Promise<void> {
const args = ['-c', 'protocol.version=2'] const args = ['-c', 'protocol.version=2']
args.push('submodule', 'update', '--init', '--force') args.push('submodule', 'update', '--init', '--force')
if (fetchDepth > 0) { if (fetchDepth > 0) {
@ -319,6 +327,10 @@ class GitCommandManager {
args.push('--recursive') args.push('--recursive')
} }
if (fetchJobs > 0) {
args.push(`--jobs=${fetchJobs}`)
}
await this.execGit(args) await this.execGit(args)
} }

View file

@ -181,7 +181,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
await git.submoduleSync(settings.nestedSubmodules) await git.submoduleSync(settings.nestedSubmodules)
await git.submoduleUpdate( await git.submoduleUpdate(
settings.fetchDepth, settings.fetchDepth,
settings.nestedSubmodules settings.nestedSubmodules,
settings.fetchJobs
) )
await git.submoduleForeach( await git.submoduleForeach(
'git config --local gc.auto 0', 'git config --local gc.auto 0',

View file

@ -34,6 +34,11 @@ export interface IGitSourceSettings {
*/ */
fetchDepth: number fetchDepth: number
/**
* The number of fetches to perform simultaneously when updating submodules
*/
fetchJobs: number
/** /**
* Indicates whether to fetch LFS objects * Indicates whether to fetch LFS objects
*/ */

View file

@ -88,6 +88,13 @@ export function getInputs(): IGitSourceSettings {
} }
core.debug(`fetch depth = ${result.fetchDepth}`) core.debug(`fetch depth = ${result.fetchDepth}`)
// Fetch jobs
result.fetchJobs = Math.floor(Number(core.getInput('fetch-jobs') || '0'))
if (isNaN(result.fetchJobs) || result.fetchJobs < 0) {
result.fetchJobs = 0
}
core.debug(`fetch jobs = ${result.fetchJobs}`)
// LFS // LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
core.debug(`lfs = ${result.lfs}`) core.debug(`lfs = ${result.lfs}`)