Skip to content

Commit ba4104a

Browse files
committedAug 27, 2024
Add string[] option to submodules
Allows checking out only specific submodules instead of all
1 parent 9a9194f commit ba4104a

File tree

7 files changed

+78
-23
lines changed

7 files changed

+78
-23
lines changed
 

‎.github/workflows/test.yml

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ jobs:
154154
submodules: true
155155
- name: Verify submodules true
156156
run: __test__/verify-submodules-true.sh
157+
158+
# Submodules limited
159+
- name: Checkout submodules true
160+
uses: ./
161+
with:
162+
ref: test-data/v2/submodule-ssh-url
163+
path: submodules-true
164+
submodules: submodule-level-1
165+
- name: Verify submodules true
166+
run: __test__/verify-submodules-true.sh
157167

158168
# Submodules recursive
159169
- name: Checkout submodules recursive

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
108108
lfs: ''
109109

110110
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
111-
# recursively checkout submodules.
111+
# recursively checkout submodules. Provide a list to specify which submodules to
112+
# check out.
112113
#
113114
# When the `ssh-key` input is not provided, SSH URLs beginning with
114115
# `git@github.com:` are converted to HTTPS.

‎action.yml

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ inputs:
8787
description: >
8888
Whether to checkout submodules: `true` to checkout submodules or `recursive` to
8989
recursively checkout submodules.
90+
Provide a list to specify which submodules to check out.
9091
9192
9293
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are

‎dist/index.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -795,17 +795,32 @@ class GitCommandManager {
795795
yield this.execGit(args);
796796
});
797797
}
798-
submoduleUpdate(fetchDepth, recursive) {
798+
submoduleUpdate(fetchDepth, recursive, submodules) {
799799
return __awaiter(this, void 0, void 0, function* () {
800-
const args = ['-c', 'protocol.version=2'];
801-
args.push('submodule', 'update', '--init', '--force');
802-
if (fetchDepth > 0) {
803-
args.push(`--depth=${fetchDepth}`);
800+
if (Array.isArray(submodules)) {
801+
for (const submodule of submodules) {
802+
const args = ['-c', 'protocol.version=2'];
803+
args.push('submodule', 'update', '--init', '--force', submodule);
804+
if (fetchDepth > 0) {
805+
args.push(`--depth=${fetchDepth}`);
806+
}
807+
if (recursive) {
808+
args.push('--recursive');
809+
}
810+
yield this.execGit(args);
811+
}
804812
}
805-
if (recursive) {
806-
args.push('--recursive');
813+
else {
814+
const args = ['-c', 'protocol.version=2'];
815+
args.push('submodule', 'update', '--init', '--force');
816+
if (fetchDepth > 0) {
817+
args.push(`--depth=${fetchDepth}`);
818+
}
819+
if (recursive) {
820+
args.push('--recursive');
821+
}
822+
yield this.execGit(args);
807823
}
808-
yield this.execGit(args);
809824
});
810825
}
811826
submoduleStatus() {
@@ -1342,7 +1357,7 @@ function getSource(settings) {
13421357
// Checkout submodules
13431358
core.startGroup('Fetching submodules');
13441359
yield git.submoduleSync(settings.nestedSubmodules);
1345-
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
1360+
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules, settings.submodules);
13461361
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
13471362
core.endGroup();
13481363
// Persist credentials

‎src/git-command-manager.ts

+35-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export interface IGitCommandManager {
5454
shaExists(sha: string): Promise<boolean>
5555
submoduleForeach(command: string, recursive: boolean): Promise<string>
5656
submoduleSync(recursive: boolean): Promise<void>
57-
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
57+
submoduleUpdate(
58+
fetchDepth: number,
59+
recursive: boolean,
60+
submodules: boolean | string[]
61+
): Promise<void>
5862
submoduleStatus(): Promise<boolean>
5963
tagExists(pattern: string): Promise<boolean>
6064
tryClean(): Promise<boolean>
@@ -409,18 +413,38 @@ class GitCommandManager {
409413
await this.execGit(args)
410414
}
411415

412-
async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> {
413-
const args = ['-c', 'protocol.version=2']
414-
args.push('submodule', 'update', '--init', '--force')
415-
if (fetchDepth > 0) {
416-
args.push(`--depth=${fetchDepth}`)
417-
}
416+
async submoduleUpdate(
417+
fetchDepth: number,
418+
recursive: boolean,
419+
submodules: boolean | string[]
420+
): Promise<void> {
421+
if (Array.isArray(submodules)) {
422+
for (const submodule of submodules) {
423+
const args = ['-c', 'protocol.version=2']
424+
args.push('submodule', 'update', '--init', '--force', submodule)
425+
if (fetchDepth > 0) {
426+
args.push(`--depth=${fetchDepth}`)
427+
}
418428

419-
if (recursive) {
420-
args.push('--recursive')
421-
}
429+
if (recursive) {
430+
args.push('--recursive')
431+
}
422432

423-
await this.execGit(args)
433+
await this.execGit(args)
434+
}
435+
} else {
436+
const args = ['-c', 'protocol.version=2']
437+
args.push('submodule', 'update', '--init', '--force')
438+
if (fetchDepth > 0) {
439+
args.push(`--depth=${fetchDepth}`)
440+
}
441+
442+
if (recursive) {
443+
args.push('--recursive')
444+
}
445+
446+
await this.execGit(args)
447+
}
424448
}
425449

426450
async submoduleStatus(): Promise<boolean> {

‎src/git-source-provider.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
242242
// Checkout submodules
243243
core.startGroup('Fetching submodules')
244244
await git.submoduleSync(settings.nestedSubmodules)
245-
await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules)
245+
await git.submoduleUpdate(
246+
settings.fetchDepth,
247+
settings.nestedSubmodules,
248+
settings.submodules
249+
)
246250
await git.submoduleForeach(
247251
'git config --local gc.auto 0',
248252
settings.nestedSubmodules

‎src/git-source-settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface IGitSourceSettings {
6767
/**
6868
* Indicates whether to checkout submodules
6969
*/
70-
submodules: boolean
70+
submodules: boolean | string[]
7171

7272
/**
7373
* Indicates whether to recursively checkout submodules

0 commit comments

Comments
 (0)
Failed to load comments.