Skip to content

Commit ad5dc19

Browse files
committed
Add fetchJobs option to parallelize submodule updates
1 parent 2036a08 commit ad5dc19

File tree

9 files changed

+49
-5
lines changed

9 files changed

+49
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
9393
# Default: 1
9494
fetch-depth: ''
9595

96+
# Number of fetches to perform simultaneously when updating submodules. 0
97+
# indicates default (serial updates).
98+
# Default: 0
99+
fetch-jobs: ''
100+
96101
# Whether to download Git-LFS files
97102
# Default: false
98103
lfs: ''

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ async function setup(testName: string): Promise<void> {
760760
clean: true,
761761
commit: '',
762762
fetchDepth: 1,
763+
fetchJobs: 0,
763764
lfs: false,
764765
submodules: false,
765766
nestedSubmodules: false,

__test__/input-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('input-helper tests', () => {
7575
expect(settings.commit).toBeTruthy()
7676
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
7777
expect(settings.fetchDepth).toBe(1)
78+
expect(settings.fetchJobs).toBe(0)
7879
expect(settings.lfs).toBe(false)
7980
expect(settings.ref).toBe('refs/heads/some-ref')
8081
expect(settings.repositoryName).toBe('some-repo')

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ inputs:
5656
fetch-depth:
5757
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
5858
default: 1
59+
fetch-jobs:
60+
description: 'Number of fetches to perform simultaneously when updating submodules. 0 indicates default (serial updates).'
61+
default: 0
5962
lfs:
6063
description: 'Whether to download Git-LFS files'
6164
default: false

dist/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5939,7 +5939,7 @@ class GitCommandManager {
59395939
yield this.execGit(args);
59405940
});
59415941
}
5942-
submoduleUpdate(fetchDepth, recursive) {
5942+
submoduleUpdate(fetchDepth, recursive, fetchJobs) {
59435943
return __awaiter(this, void 0, void 0, function* () {
59445944
const args = ['-c', 'protocol.version=2'];
59455945
args.push('submodule', 'update', '--init', '--force');
@@ -5949,6 +5949,9 @@ class GitCommandManager {
59495949
if (recursive) {
59505950
args.push('--recursive');
59515951
}
5952+
if (fetchJobs > 0) {
5953+
args.push(`--jobs=${fetchJobs}`);
5954+
}
59525955
yield this.execGit(args);
59535956
});
59545957
}
@@ -6252,7 +6255,7 @@ function getSource(settings) {
62526255
// Checkout submodules
62536256
core.startGroup('Fetching submodules');
62546257
yield git.submoduleSync(settings.nestedSubmodules);
6255-
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
6258+
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules, settings.fetchJobs);
62566259
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
62576260
core.endGroup();
62586261
// Persist credentials
@@ -14567,6 +14570,12 @@ function getInputs() {
1456714570
result.fetchDepth = 0;
1456814571
}
1456914572
core.debug(`fetch depth = ${result.fetchDepth}`);
14573+
// Fetch jobs
14574+
result.fetchJobs = Math.floor(Number(core.getInput('fetch-jobs') || '0'));
14575+
if (isNaN(result.fetchJobs) || result.fetchJobs < 0) {
14576+
result.fetchJobs = 0;
14577+
}
14578+
core.debug(`fetch jobs = ${result.fetchJobs}`);
1457014579
// LFS
1457114580
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1457214581
core.debug(`lfs = ${result.lfs}`);

src/git-command-manager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export interface IGitCommandManager {
3939
shaExists(sha: string): Promise<boolean>
4040
submoduleForeach(command: string, recursive: boolean): Promise<string>
4141
submoduleSync(recursive: boolean): Promise<void>
42-
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
42+
submoduleUpdate(
43+
fetchDepth: number,
44+
recursive: boolean,
45+
fetchJobs: number
46+
): Promise<void>
4347
tagExists(pattern: string): Promise<boolean>
4448
tryClean(): Promise<boolean>
4549
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
@@ -308,7 +312,11 @@ class GitCommandManager {
308312
await this.execGit(args)
309313
}
310314

311-
async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> {
315+
async submoduleUpdate(
316+
fetchDepth: number,
317+
recursive: boolean,
318+
fetchJobs: number
319+
): Promise<void> {
312320
const args = ['-c', 'protocol.version=2']
313321
args.push('submodule', 'update', '--init', '--force')
314322
if (fetchDepth > 0) {
@@ -319,6 +327,10 @@ class GitCommandManager {
319327
args.push('--recursive')
320328
}
321329

330+
if (fetchJobs > 0) {
331+
args.push(`--jobs=${fetchJobs}`)
332+
}
333+
322334
await this.execGit(args)
323335
}
324336

src/git-source-provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
181181
await git.submoduleSync(settings.nestedSubmodules)
182182
await git.submoduleUpdate(
183183
settings.fetchDepth,
184-
settings.nestedSubmodules
184+
settings.nestedSubmodules,
185+
settings.fetchJobs
185186
)
186187
await git.submoduleForeach(
187188
'git config --local gc.auto 0',

src/git-source-settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export interface IGitSourceSettings {
3434
*/
3535
fetchDepth: number
3636

37+
/**
38+
* The number of fetches to perform simultaneously when updating submodules
39+
*/
40+
fetchJobs: number
41+
3742
/**
3843
* Indicates whether to fetch LFS objects
3944
*/

src/input-helper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ export function getInputs(): IGitSourceSettings {
8888
}
8989
core.debug(`fetch depth = ${result.fetchDepth}`)
9090

91+
// Fetch jobs
92+
result.fetchJobs = Math.floor(Number(core.getInput('fetch-jobs') || '0'))
93+
if (isNaN(result.fetchJobs) || result.fetchJobs < 0) {
94+
result.fetchJobs = 0
95+
}
96+
core.debug(`fetch jobs = ${result.fetchJobs}`)
97+
9198
// LFS
9299
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
93100
core.debug(`lfs = ${result.lfs}`)

0 commit comments

Comments
 (0)