Skip to content

Commit 01aeccc

Browse files
authored
group output (#191)
1 parent 85b1f35 commit 01aeccc

5 files changed

+127
-2
lines changed

dist/index.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -5267,7 +5267,7 @@ class GitAuthHelper {
52675267
}
52685268
removeGlobalAuth() {
52695269
return __awaiter(this, void 0, void 0, function* () {
5270-
core.info(`Unsetting HOME override`);
5270+
core.debug(`Unsetting HOME override`);
52715271
this.git.removeEnvironmentVariable('HOME');
52725272
yield io.rmRF(this.temporaryHomePath);
52735273
});
@@ -5856,7 +5856,9 @@ function getSource(settings) {
58565856
yield io.mkdirP(settings.repositoryPath);
58575857
}
58585858
// Git command manager
5859+
core.startGroup('Getting Git version info');
58595860
const git = yield getGitCommandManager(settings);
5861+
core.endGroup();
58605862
// Prepare existing directory, otherwise recreate
58615863
if (isExisting) {
58625864
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
@@ -5878,46 +5880,66 @@ function getSource(settings) {
58785880
stateHelper.setRepositoryPath(settings.repositoryPath);
58795881
// Initialize the repository
58805882
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
5883+
core.startGroup('Initializing the repository');
58815884
yield git.init();
58825885
yield git.remoteAdd('origin', repositoryUrl);
5886+
core.endGroup();
58835887
}
58845888
// Disable automatic garbage collection
5889+
core.startGroup('Disabling automatic garbage collection');
58855890
if (!(yield git.tryDisableAutomaticGarbageCollection())) {
58865891
core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`);
58875892
}
5893+
core.endGroup();
58885894
const authHelper = gitAuthHelper.createAuthHelper(git, settings);
58895895
try {
58905896
// Configure auth
5897+
core.startGroup('Setting up auth');
58915898
yield authHelper.configureAuth();
5899+
core.endGroup();
58925900
// LFS install
58935901
if (settings.lfs) {
58945902
yield git.lfsInstall();
58955903
}
58965904
// Fetch
5905+
core.startGroup('Fetching the repository');
58975906
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
58985907
yield git.fetch(settings.fetchDepth, refSpec);
5908+
core.endGroup();
58995909
// Checkout info
5910+
core.startGroup('Determining the checkout info');
59005911
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
5912+
core.endGroup();
59015913
// LFS fetch
59025914
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
59035915
// Explicit lfs fetch will fetch lfs objects in parallel.
59045916
if (settings.lfs) {
5917+
core.startGroup('Fetching LFS objects');
59055918
yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
5919+
core.endGroup();
59065920
}
59075921
// Checkout
5922+
core.startGroup('Checking out the ref');
59085923
yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
5924+
core.endGroup();
59095925
// Submodules
59105926
if (settings.submodules) {
59115927
try {
59125928
// Temporarily override global config
5929+
core.startGroup('Setting up auth for fetching submodules');
59135930
yield authHelper.configureGlobalAuth();
5931+
core.endGroup();
59145932
// Checkout submodules
5933+
core.startGroup('Fetching submodules');
59155934
yield git.submoduleSync(settings.nestedSubmodules);
59165935
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
59175936
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
5937+
core.endGroup();
59185938
// Persist credentials
59195939
if (settings.persistCredentials) {
5940+
core.startGroup('Persisting credentials for submodules');
59205941
yield authHelper.configureSubmoduleAuth();
5942+
core.endGroup();
59215943
}
59225944
}
59235945
finally {
@@ -5931,7 +5953,9 @@ function getSource(settings) {
59315953
finally {
59325954
// Remove auth
59335955
if (!settings.persistCredentials) {
5956+
core.startGroup('Removing auth');
59345957
yield authHelper.removeAuth();
5958+
core.endGroup();
59355959
}
59365960
}
59375961
});
@@ -7231,13 +7255,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
72317255
return result;
72327256
};
72337257
Object.defineProperty(exports, "__esModule", { value: true });
7258+
const assert = __importStar(__webpack_require__(357));
72347259
const core = __importStar(__webpack_require__(470));
72357260
const fs = __importStar(__webpack_require__(747));
72367261
const fsHelper = __importStar(__webpack_require__(618));
72377262
const io = __importStar(__webpack_require__(1));
72387263
const path = __importStar(__webpack_require__(622));
72397264
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
72407265
return __awaiter(this, void 0, void 0, function* () {
7266+
assert.ok(repositoryPath, 'Expected repositoryPath to be defined');
7267+
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined');
7268+
// Indicates whether to delete the directory contents
72417269
let remove = false;
72427270
// Check whether using git or REST API
72437271
if (!git) {
@@ -7263,6 +7291,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
72637291
}
72647292
}
72657293
try {
7294+
core.startGroup('Removing previously created refs, to avoid conflicts');
72667295
// Checkout detached HEAD
72677296
if (!(yield git.isDetached())) {
72687297
yield git.checkoutDetach();
@@ -7277,15 +7306,18 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
72777306
for (const branch of branches) {
72787307
yield git.branchDelete(true, branch);
72797308
}
7309+
core.endGroup();
72807310
// Clean
72817311
if (clean) {
7312+
core.startGroup('Cleaning the repository');
72827313
if (!(yield git.tryClean())) {
72837314
core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`);
72847315
remove = true;
72857316
}
72867317
else if (!(yield git.tryReset())) {
72877318
remove = true;
72887319
}
7320+
core.endGroup();
72897321
if (remove) {
72907322
core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
72917323
}

src/git-auth-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class GitAuthHelper {
173173
}
174174

175175
async removeGlobalAuth(): Promise<void> {
176-
core.info(`Unsetting HOME override`)
176+
core.debug(`Unsetting HOME override`)
177177
this.git.removeEnvironmentVariable('HOME')
178178
await io.rmRF(this.temporaryHomePath)
179179
}

src/git-directory-helper.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
import * as assert from 'assert'
12
import * as core from '@actions/core'
23
import * as fs from 'fs'
34
import * as fsHelper from './fs-helper'
45
import * as io from '@actions/io'
56
import * as path from 'path'
67
import {IGitCommandManager} from './git-command-manager'
8+
import {IGitSourceSettings} from './git-source-settings'
79

810
export async function prepareExistingDirectory(
911
git: IGitCommandManager | undefined,
1012
repositoryPath: string,
1113
repositoryUrl: string,
1214
clean: boolean
1315
): Promise<void> {
16+
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
17+
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
18+
19+
// Indicates whether to delete the directory contents
1420
let remove = false
1521

1622
// Check whether using git or REST API
@@ -38,6 +44,7 @@ export async function prepareExistingDirectory(
3844
}
3945

4046
try {
47+
core.startGroup('Removing previously created refs, to avoid conflicts')
4148
// Checkout detached HEAD
4249
if (!(await git.isDetached())) {
4350
await git.checkoutDetach()
@@ -54,9 +61,11 @@ export async function prepareExistingDirectory(
5461
for (const branch of branches) {
5562
await git.branchDelete(true, branch)
5663
}
64+
core.endGroup()
5765

5866
// Clean
5967
if (clean) {
68+
core.startGroup('Cleaning the repository')
6069
if (!(await git.tryClean())) {
6170
core.debug(
6271
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
@@ -65,6 +74,7 @@ export async function prepareExistingDirectory(
6574
} else if (!(await git.tryReset())) {
6675
remove = true
6776
}
77+
core.endGroup()
6878

6979
if (remove) {
7080
core.warning(

src/git-source-provider.ts

+24
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
3232
}
3333

3434
// Git command manager
35+
core.startGroup('Getting Git version info')
3536
const git = await getGitCommandManager(settings)
37+
core.endGroup()
3638

3739
// Prepare existing directory, otherwise recreate
3840
if (isExisting) {
@@ -78,55 +80,72 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
7880
if (
7981
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
8082
) {
83+
core.startGroup('Initializing the repository')
8184
await git.init()
8285
await git.remoteAdd('origin', repositoryUrl)
86+
core.endGroup()
8387
}
8488

8589
// Disable automatic garbage collection
90+
core.startGroup('Disabling automatic garbage collection')
8691
if (!(await git.tryDisableAutomaticGarbageCollection())) {
8792
core.warning(
8893
`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`
8994
)
9095
}
96+
core.endGroup()
9197

9298
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
9399
try {
94100
// Configure auth
101+
core.startGroup('Setting up auth')
95102
await authHelper.configureAuth()
103+
core.endGroup()
96104

97105
// LFS install
98106
if (settings.lfs) {
99107
await git.lfsInstall()
100108
}
101109

102110
// Fetch
111+
core.startGroup('Fetching the repository')
103112
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
104113
await git.fetch(settings.fetchDepth, refSpec)
114+
core.endGroup()
105115

106116
// Checkout info
117+
core.startGroup('Determining the checkout info')
107118
const checkoutInfo = await refHelper.getCheckoutInfo(
108119
git,
109120
settings.ref,
110121
settings.commit
111122
)
123+
core.endGroup()
112124

113125
// LFS fetch
114126
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
115127
// Explicit lfs fetch will fetch lfs objects in parallel.
116128
if (settings.lfs) {
129+
core.startGroup('Fetching LFS objects')
117130
await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
131+
core.endGroup()
118132
}
119133

120134
// Checkout
135+
core.startGroup('Checking out the ref')
121136
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
137+
core.endGroup()
122138

123139
// Submodules
124140
if (settings.submodules) {
125141
try {
126142
// Temporarily override global config
143+
core.startGroup('Setting up auth for fetching submodules')
127144
await authHelper.configureGlobalAuth()
145+
core.endGroup()
128146

129147
// Checkout submodules
148+
core.startGroup('Fetching submodules')
130149
await git.submoduleSync(settings.nestedSubmodules)
131150
await git.submoduleUpdate(
132151
settings.fetchDepth,
@@ -136,10 +155,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
136155
'git config --local gc.auto 0',
137156
settings.nestedSubmodules
138157
)
158+
core.endGroup()
139159

140160
// Persist credentials
141161
if (settings.persistCredentials) {
162+
core.startGroup('Persisting credentials for submodules')
142163
await authHelper.configureSubmoduleAuth()
164+
core.endGroup()
143165
}
144166
} finally {
145167
// Remove temporary global config override
@@ -152,7 +174,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
152174
} finally {
153175
// Remove auth
154176
if (!settings.persistCredentials) {
177+
core.startGroup('Removing auth')
155178
await authHelper.removeAuth()
179+
core.endGroup()
156180
}
157181
}
158182
}

src/git-source-settings.ts

+59
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,76 @@
11
export interface IGitSourceSettings {
2+
/**
3+
* The location on disk where the repository will be placed
4+
*/
25
repositoryPath: string
6+
7+
/**
8+
* The repository owner
9+
*/
310
repositoryOwner: string
11+
12+
/**
13+
* The repository name
14+
*/
415
repositoryName: string
16+
17+
/**
18+
* The ref to fetch
19+
*/
520
ref: string
21+
22+
/**
23+
* The commit to checkout
24+
*/
625
commit: string
26+
27+
/**
28+
* Indicates whether to clean the repository
29+
*/
730
clean: boolean
31+
32+
/**
33+
* The depth when fetching
34+
*/
835
fetchDepth: number
36+
37+
/**
38+
* Indicates whether to fetch LFS objects
39+
*/
940
lfs: boolean
41+
42+
/**
43+
* Indicates whether to checkout submodules
44+
*/
1045
submodules: boolean
46+
47+
/**
48+
* Indicates whether to recursively checkout submodules
49+
*/
1150
nestedSubmodules: boolean
51+
52+
/**
53+
* The auth token to use when fetching the repository
54+
*/
1255
authToken: string
56+
57+
/**
58+
* The SSH key to configure
59+
*/
1360
sshKey: string
61+
62+
/**
63+
* Additional SSH known hosts
64+
*/
1465
sshKnownHosts: string
66+
67+
/**
68+
* Indicates whether the server must be a known host
69+
*/
1570
sshStrict: boolean
71+
72+
/**
73+
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
74+
*/
1675
persistCredentials: boolean
1776
}

0 commit comments

Comments
 (0)