Skip to content

Commit 4475b1c

Browse files
authored
Allow configuration of fetch.parallel (#2)
1 parent edc3278 commit 4475b1c

File tree

8 files changed

+63
-13
lines changed

8 files changed

+63
-13
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
ref: test-data/v2/submodule-ssh-url
158158
path: submodules-true
159159
submodules: recursive
160-
submodulesFetchJobs: "10"
160+
submodules-fetch-jobs: "10"
161161
- name: Verify submodules true
162162
run: __test__/verify-submodules-with-jobs.sh
163163

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
9494
# Default: false
9595
fetch-tags: ''
9696

97+
# Specifies the maximal number of fetch operations to be run in parallel at a time
98+
# (submodules, or remotes when the --multiple option of git-fetch is in effect). A
99+
# value of 0 will give some reasonable default. If unset, it defaults to 1.
100+
# Default: 1
101+
fetch-parallel: ''
102+
97103
# Whether to show progress status output when fetching.
98104
# Default: true
99105
show-progress: ''
@@ -115,7 +121,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
115121
# integer allows up to that number of submodules fetched in parallel. A value of 0
116122
# will give some reasonable default. If unset, it defaults to 1.
117123
# Default: 1
118-
submodulesFetchJobs: ''
124+
submodules-fetch-jobs: ''
119125

120126
# Add repository path as safe.directory for Git global config by running `git
121127
# config --global --add safe.directory <path>`

__test__/git-auth-helper.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,12 @@ async function setup(testName: string): Promise<void> {
807807
sparseCheckoutConeMode: true,
808808
fetchDepth: 1,
809809
fetchTags: false,
810+
fetchParallel: 1,
810811
showProgress: true,
811812
lfs: false,
812813
submodules: false,
813814
nestedSubmodules: false,
814-
submodulesFetchJobs: '1',
815+
submodulesFetchJobs: 1,
815816
persistCredentials: true,
816817
ref: 'refs/heads/main',
817818
repositoryName: 'my-repo',

action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ inputs:
7373
fetch-tags:
7474
description: 'Whether to fetch tags, even if fetch-depth > 0.'
7575
default: false
76+
fetch-parallel:
77+
description: >
78+
Specifies the maximal number of fetch operations to be run in parallel at a time (submodules, or remotes when the --multiple option of git-fetch is in effect).
79+
A value of 0 will give some reasonable default. If unset, it defaults to 1.
80+
default: 1
7681
show-progress:
7782
description: 'Whether to show progress status output when fetching.'
7883
default: true
@@ -88,7 +93,7 @@ inputs:
8893
When the `ssh-key` input is not provided, SSH URLs beginning with `[email protected]:` are
8994
converted to HTTPS.
9095
default: false
91-
submodulesFetchJobs:
96+
submodules-fetch-jobs:
9297
description: >
9398
Specifies how many submodules are fetched/cloned at the same time. A positive integer allows up to that number of submodules fetched in parallel. A value of 0 will give some reasonable default. If unset, it defaults to 1.
9499
default: 1

dist/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ function getSource(settings) {
12431243
}
12441244
// Fetch
12451245
core.startGroup('Fetching the repository');
1246+
yield git.config('fetch.parallel', settings.fetchParallel.toString(), true);
12461247
const fetchOptions = {};
12471248
if (settings.filter) {
12481249
fetchOptions.filter = settings.filter;
@@ -1304,7 +1305,7 @@ function getSource(settings) {
13041305
core.endGroup();
13051306
// Checkout submodules
13061307
core.startGroup('Fetching submodules');
1307-
yield git.config('submodule.fetchJobs', settings.submodulesFetchJobs);
1308+
yield git.config('submodule.fetchJobs', settings.submodulesFetchJobs.toString(), true);
13081309
yield git.submoduleSync(settings.nestedSubmodules);
13091310
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
13101311
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
@@ -1753,6 +1754,12 @@ function getInputs() {
17531754
result.fetchTags =
17541755
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE';
17551756
core.debug(`fetch tags = ${result.fetchTags}`);
1757+
// Fetch tags
1758+
result.fetchParallel = Math.floor(Number(core.getInput('fetch-parallel') || '1'));
1759+
if (isNaN(result.fetchParallel) || result.fetchParallel < 0) {
1760+
result.fetchParallel = 0;
1761+
}
1762+
core.debug(`fetch parallel = ${result.fetchParallel}`);
17561763
// Show fetch progress
17571764
result.showProgress =
17581765
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE';
@@ -1771,12 +1778,17 @@ function getInputs() {
17711778
else if (submodulesString == 'TRUE') {
17721779
result.submodules = true;
17731780
}
1774-
result.submodulesFetchJobs = core.getInput('submodulesFetchJobs') || '1';
1781+
result.submodulesFetchJobs = Math.floor(Number(core.getInput('submodules-fetch-jobs') || '1'));
1782+
if (isNaN(result.submodulesFetchJobs) || result.submodulesFetchJobs < 0) {
1783+
result.submodulesFetchJobs = 0;
1784+
}
17751785
core.debug(`submodules = ${result.submodules}`);
17761786
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
1777-
core.debug(`submodules fetchJobs= ${result.submodulesFetchJobs}`);
1787+
core.debug(`submodules submodules-fetch-jobs = ${result.submodulesFetchJobs}`);
17781788
// Auth token
1779-
result.authToken = core.getInput('token', { required: true });
1789+
result.authToken = core.getInput('token', {
1790+
required: true
1791+
});
17801792
// SSH
17811793
result.sshKey = core.getInput('ssh-key');
17821794
result.sshKnownHosts = core.getInput('ssh-known-hosts');

src/git-source-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
153153

154154
// Fetch
155155
core.startGroup('Fetching the repository')
156+
await git.config('fetch.parallel', settings.fetchParallel.toString(), true)
156157
const fetchOptions: {
157158
filter?: string
158159
fetchDepth?: number
@@ -232,7 +233,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
232233

233234
// Checkout submodules
234235
core.startGroup('Fetching submodules')
235-
await git.config('submodule.fetchJobs', settings.submodulesFetchJobs)
236+
await git.config(
237+
'submodule.fetchJobs',
238+
settings.submodulesFetchJobs.toString(),
239+
true
240+
)
236241
await git.submoduleSync(settings.nestedSubmodules)
237242
await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules)
238243
await git.submoduleForeach(

src/git-source-settings.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export interface IGitSourceSettings {
5454
*/
5555
fetchTags: boolean
5656

57+
/**
58+
* Indicates the maximal number of fetch operations to be run in parallel at a time
59+
*/
60+
fetchParallel: number
61+
5762
/**
5863
* Indicates whether to use the --progress option when fetching
5964
*/
@@ -77,7 +82,7 @@ export interface IGitSourceSettings {
7782
/**
7883
* Indicates the number of parallel jobs to use when fetching submodules
7984
*/
80-
submodulesFetchJobs: string
85+
submodulesFetchJobs: number
8186

8287
/**
8388
* The auth token to use when fetching the repository

src/input-helper.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ export async function getInputs(): Promise<IGitSourceSettings> {
113113
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE'
114114
core.debug(`fetch tags = ${result.fetchTags}`)
115115

116+
// Fetch tags
117+
result.fetchParallel = Math.floor(
118+
Number(core.getInput('fetch-parallel') || '1')
119+
)
120+
if (isNaN(result.fetchParallel) || result.fetchParallel < 0) {
121+
result.fetchParallel = 0
122+
}
123+
core.debug(`fetch parallel = ${result.fetchParallel}`)
124+
116125
// Show fetch progress
117126
result.showProgress =
118127
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE'
@@ -132,13 +141,20 @@ export async function getInputs(): Promise<IGitSourceSettings> {
132141
} else if (submodulesString == 'TRUE') {
133142
result.submodules = true
134143
}
135-
result.submodulesFetchJobs = core.getInput('submodulesFetchJobs') || '1'
144+
result.submodulesFetchJobs = Math.floor(
145+
Number(core.getInput('submodules-fetch-jobs') || '1')
146+
)
147+
if (isNaN(result.submodulesFetchJobs) || result.submodulesFetchJobs < 0) {
148+
result.submodulesFetchJobs = 0
149+
}
136150
core.debug(`submodules = ${result.submodules}`)
137151
core.debug(`recursive submodules = ${result.nestedSubmodules}`)
138-
core.debug(`submodules fetchJobs= ${result.submodulesFetchJobs}`)
152+
core.debug(`submodules submodules-fetch-jobs = ${result.submodulesFetchJobs}`)
139153

140154
// Auth token
141-
result.authToken = core.getInput('token', {required: true})
155+
result.authToken = core.getInput('token', {
156+
required: true
157+
})
142158

143159
// SSH
144160
result.sshKey = core.getInput('ssh-key')

0 commit comments

Comments
 (0)