1
0
Fork 0
mirror of https://github.com/actions/checkout synced 2024-12-22 13:12:42 +00:00

group output (#191)

This commit is contained in:
eric sciple 2020-03-27 13:12:15 -04:00 committed by GitHub
parent 85b1f35505
commit 01aecccf73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 127 additions and 2 deletions

34
dist/index.js vendored
View file

@ -5267,7 +5267,7 @@ class GitAuthHelper {
} }
removeGlobalAuth() { removeGlobalAuth() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info(`Unsetting HOME override`); core.debug(`Unsetting HOME override`);
this.git.removeEnvironmentVariable('HOME'); this.git.removeEnvironmentVariable('HOME');
yield io.rmRF(this.temporaryHomePath); yield io.rmRF(this.temporaryHomePath);
}); });
@ -5856,7 +5856,9 @@ function getSource(settings) {
yield io.mkdirP(settings.repositoryPath); yield io.mkdirP(settings.repositoryPath);
} }
// Git command manager // Git command manager
core.startGroup('Getting Git version info');
const git = yield getGitCommandManager(settings); const git = yield getGitCommandManager(settings);
core.endGroup();
// Prepare existing directory, otherwise recreate // Prepare existing directory, otherwise recreate
if (isExisting) { if (isExisting) {
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean); yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
@ -5878,46 +5880,66 @@ function getSource(settings) {
stateHelper.setRepositoryPath(settings.repositoryPath); stateHelper.setRepositoryPath(settings.repositoryPath);
// Initialize the repository // Initialize the repository
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) { if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
core.startGroup('Initializing the repository');
yield git.init(); yield git.init();
yield git.remoteAdd('origin', repositoryUrl); yield git.remoteAdd('origin', repositoryUrl);
core.endGroup();
} }
// Disable automatic garbage collection // Disable automatic garbage collection
core.startGroup('Disabling automatic garbage collection');
if (!(yield git.tryDisableAutomaticGarbageCollection())) { if (!(yield git.tryDisableAutomaticGarbageCollection())) {
core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`); core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`);
} }
core.endGroup();
const authHelper = gitAuthHelper.createAuthHelper(git, settings); const authHelper = gitAuthHelper.createAuthHelper(git, settings);
try { try {
// Configure auth // Configure auth
core.startGroup('Setting up auth');
yield authHelper.configureAuth(); yield authHelper.configureAuth();
core.endGroup();
// LFS install // LFS install
if (settings.lfs) { if (settings.lfs) {
yield git.lfsInstall(); yield git.lfsInstall();
} }
// Fetch // Fetch
core.startGroup('Fetching the repository');
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit); const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
yield git.fetch(settings.fetchDepth, refSpec); yield git.fetch(settings.fetchDepth, refSpec);
core.endGroup();
// Checkout info // Checkout info
core.startGroup('Determining the checkout info');
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit); const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
core.endGroup();
// LFS fetch // LFS fetch
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time). // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
// Explicit lfs fetch will fetch lfs objects in parallel. // Explicit lfs fetch will fetch lfs objects in parallel.
if (settings.lfs) { if (settings.lfs) {
core.startGroup('Fetching LFS objects');
yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref); yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
core.endGroup();
} }
// Checkout // Checkout
core.startGroup('Checking out the ref');
yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint); yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
core.endGroup();
// Submodules // Submodules
if (settings.submodules) { if (settings.submodules) {
try { try {
// Temporarily override global config // Temporarily override global config
core.startGroup('Setting up auth for fetching submodules');
yield authHelper.configureGlobalAuth(); yield authHelper.configureGlobalAuth();
core.endGroup();
// Checkout submodules // Checkout 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);
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules); yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
core.endGroup();
// Persist credentials // Persist credentials
if (settings.persistCredentials) { if (settings.persistCredentials) {
core.startGroup('Persisting credentials for submodules');
yield authHelper.configureSubmoduleAuth(); yield authHelper.configureSubmoduleAuth();
core.endGroup();
} }
} }
finally { finally {
@ -5931,7 +5953,9 @@ function getSource(settings) {
finally { finally {
// Remove auth // Remove auth
if (!settings.persistCredentials) { if (!settings.persistCredentials) {
core.startGroup('Removing auth');
yield authHelper.removeAuth(); yield authHelper.removeAuth();
core.endGroup();
} }
} }
}); });
@ -7231,6 +7255,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const assert = __importStar(__webpack_require__(357));
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const fs = __importStar(__webpack_require__(747)); const fs = __importStar(__webpack_require__(747));
const fsHelper = __importStar(__webpack_require__(618)); const fsHelper = __importStar(__webpack_require__(618));
@ -7238,6 +7263,9 @@ const io = __importStar(__webpack_require__(1));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) { function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
assert.ok(repositoryPath, 'Expected repositoryPath to be defined');
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined');
// Indicates whether to delete the directory contents
let remove = false; let remove = false;
// Check whether using git or REST API // Check whether using git or REST API
if (!git) { if (!git) {
@ -7263,6 +7291,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
} }
} }
try { try {
core.startGroup('Removing previously created refs, to avoid conflicts');
// Checkout detached HEAD // Checkout detached HEAD
if (!(yield git.isDetached())) { if (!(yield git.isDetached())) {
yield git.checkoutDetach(); yield git.checkoutDetach();
@ -7277,8 +7306,10 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
for (const branch of branches) { for (const branch of branches) {
yield git.branchDelete(true, branch); yield git.branchDelete(true, branch);
} }
core.endGroup();
// Clean // Clean
if (clean) { if (clean) {
core.startGroup('Cleaning the repository');
if (!(yield git.tryClean())) { if (!(yield git.tryClean())) {
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}'.`); 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}'.`);
remove = true; remove = true;
@ -7286,6 +7317,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
else if (!(yield git.tryReset())) { else if (!(yield git.tryReset())) {
remove = true; remove = true;
} }
core.endGroup();
if (remove) { if (remove) {
core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`); core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
} }

View file

@ -173,7 +173,7 @@ class GitAuthHelper {
} }
async removeGlobalAuth(): Promise<void> { async removeGlobalAuth(): Promise<void> {
core.info(`Unsetting HOME override`) core.debug(`Unsetting HOME override`)
this.git.removeEnvironmentVariable('HOME') this.git.removeEnvironmentVariable('HOME')
await io.rmRF(this.temporaryHomePath) await io.rmRF(this.temporaryHomePath)
} }

View file

@ -1,9 +1,11 @@
import * as assert from 'assert'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as fs from 'fs' import * as fs from 'fs'
import * as fsHelper from './fs-helper' import * as fsHelper from './fs-helper'
import * as io from '@actions/io' import * as io from '@actions/io'
import * as path from 'path' import * as path from 'path'
import {IGitCommandManager} from './git-command-manager' import {IGitCommandManager} from './git-command-manager'
import {IGitSourceSettings} from './git-source-settings'
export async function prepareExistingDirectory( export async function prepareExistingDirectory(
git: IGitCommandManager | undefined, git: IGitCommandManager | undefined,
@ -11,6 +13,10 @@ export async function prepareExistingDirectory(
repositoryUrl: string, repositoryUrl: string,
clean: boolean clean: boolean
): Promise<void> { ): Promise<void> {
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
// Indicates whether to delete the directory contents
let remove = false let remove = false
// Check whether using git or REST API // Check whether using git or REST API
@ -38,6 +44,7 @@ export async function prepareExistingDirectory(
} }
try { try {
core.startGroup('Removing previously created refs, to avoid conflicts')
// Checkout detached HEAD // Checkout detached HEAD
if (!(await git.isDetached())) { if (!(await git.isDetached())) {
await git.checkoutDetach() await git.checkoutDetach()
@ -54,9 +61,11 @@ export async function prepareExistingDirectory(
for (const branch of branches) { for (const branch of branches) {
await git.branchDelete(true, branch) await git.branchDelete(true, branch)
} }
core.endGroup()
// Clean // Clean
if (clean) { if (clean) {
core.startGroup('Cleaning the repository')
if (!(await git.tryClean())) { if (!(await git.tryClean())) {
core.debug( 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}'.` `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(
} else if (!(await git.tryReset())) { } else if (!(await git.tryReset())) {
remove = true remove = true
} }
core.endGroup()
if (remove) { if (remove) {
core.warning( core.warning(

View file

@ -32,7 +32,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
} }
// Git command manager // Git command manager
core.startGroup('Getting Git version info')
const git = await getGitCommandManager(settings) const git = await getGitCommandManager(settings)
core.endGroup()
// Prepare existing directory, otherwise recreate // Prepare existing directory, otherwise recreate
if (isExisting) { if (isExisting) {
@ -78,21 +80,27 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
if ( if (
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git')) !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
) { ) {
core.startGroup('Initializing the repository')
await git.init() await git.init()
await git.remoteAdd('origin', repositoryUrl) await git.remoteAdd('origin', repositoryUrl)
core.endGroup()
} }
// Disable automatic garbage collection // Disable automatic garbage collection
core.startGroup('Disabling automatic garbage collection')
if (!(await git.tryDisableAutomaticGarbageCollection())) { if (!(await git.tryDisableAutomaticGarbageCollection())) {
core.warning( core.warning(
`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.` `Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`
) )
} }
core.endGroup()
const authHelper = gitAuthHelper.createAuthHelper(git, settings) const authHelper = gitAuthHelper.createAuthHelper(git, settings)
try { try {
// Configure auth // Configure auth
core.startGroup('Setting up auth')
await authHelper.configureAuth() await authHelper.configureAuth()
core.endGroup()
// LFS install // LFS install
if (settings.lfs) { if (settings.lfs) {
@ -100,33 +108,44 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
} }
// Fetch // Fetch
core.startGroup('Fetching the repository')
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit) const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
await git.fetch(settings.fetchDepth, refSpec) await git.fetch(settings.fetchDepth, refSpec)
core.endGroup()
// Checkout info // Checkout info
core.startGroup('Determining the checkout info')
const checkoutInfo = await refHelper.getCheckoutInfo( const checkoutInfo = await refHelper.getCheckoutInfo(
git, git,
settings.ref, settings.ref,
settings.commit settings.commit
) )
core.endGroup()
// LFS fetch // LFS fetch
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time). // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
// Explicit lfs fetch will fetch lfs objects in parallel. // Explicit lfs fetch will fetch lfs objects in parallel.
if (settings.lfs) { if (settings.lfs) {
core.startGroup('Fetching LFS objects')
await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref) await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
core.endGroup()
} }
// Checkout // Checkout
core.startGroup('Checking out the ref')
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
core.endGroup()
// Submodules // Submodules
if (settings.submodules) { if (settings.submodules) {
try { try {
// Temporarily override global config // Temporarily override global config
core.startGroup('Setting up auth for fetching submodules')
await authHelper.configureGlobalAuth() await authHelper.configureGlobalAuth()
core.endGroup()
// Checkout submodules // Checkout submodules
core.startGroup('Fetching submodules')
await git.submoduleSync(settings.nestedSubmodules) await git.submoduleSync(settings.nestedSubmodules)
await git.submoduleUpdate( await git.submoduleUpdate(
settings.fetchDepth, settings.fetchDepth,
@ -136,10 +155,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
'git config --local gc.auto 0', 'git config --local gc.auto 0',
settings.nestedSubmodules settings.nestedSubmodules
) )
core.endGroup()
// Persist credentials // Persist credentials
if (settings.persistCredentials) { if (settings.persistCredentials) {
core.startGroup('Persisting credentials for submodules')
await authHelper.configureSubmoduleAuth() await authHelper.configureSubmoduleAuth()
core.endGroup()
} }
} finally { } finally {
// Remove temporary global config override // Remove temporary global config override
@ -152,7 +174,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
} finally { } finally {
// Remove auth // Remove auth
if (!settings.persistCredentials) { if (!settings.persistCredentials) {
core.startGroup('Removing auth')
await authHelper.removeAuth() await authHelper.removeAuth()
core.endGroup()
} }
} }
} }

View file

@ -1,17 +1,76 @@
export interface IGitSourceSettings { export interface IGitSourceSettings {
/**
* The location on disk where the repository will be placed
*/
repositoryPath: string repositoryPath: string
/**
* The repository owner
*/
repositoryOwner: string repositoryOwner: string
/**
* The repository name
*/
repositoryName: string repositoryName: string
/**
* The ref to fetch
*/
ref: string ref: string
/**
* The commit to checkout
*/
commit: string commit: string
/**
* Indicates whether to clean the repository
*/
clean: boolean clean: boolean
/**
* The depth when fetching
*/
fetchDepth: number fetchDepth: number
/**
* Indicates whether to fetch LFS objects
*/
lfs: boolean lfs: boolean
/**
* Indicates whether to checkout submodules
*/
submodules: boolean submodules: boolean
/**
* Indicates whether to recursively checkout submodules
*/
nestedSubmodules: boolean nestedSubmodules: boolean
/**
* The auth token to use when fetching the repository
*/
authToken: string authToken: string
/**
* The SSH key to configure
*/
sshKey: string sshKey: string
/**
* Additional SSH known hosts
*/
sshKnownHosts: string sshKnownHosts: string
/**
* Indicates whether the server must be a known host
*/
sshStrict: boolean sshStrict: boolean
/**
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
*/
persistCredentials: boolean persistCredentials: boolean
} }