Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group output #191

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5225,7 +5225,7 @@ class GitAuthHelper {
}
removeGlobalAuth() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.ref.farming.near

return __awaiter(this, void 0, void 0, function* () {
core.info(`Unsetting HOME override`);
core.debug(`Unsetting HOME override`);
this.git.removeEnvironmentVariable('HOME');
yield io.rmRF(this.temporaryHomePath);
});
Expand Down Expand Up @@ -5816,7 +5816,9 @@ function getSource(settings) {
yield io.mkdirP(settings.repositoryPath);
}
// Git command manager
core.startGroup('Getting Git version info');
const git = yield getGitCommandManager(settings);
core.endGroup();
// Prepare existing directory, otherwise recreate
if (isExisting) {
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
Expand All @@ -5838,46 +5840,66 @@ function getSource(settings) {
stateHelper.setRepositoryPath(settings.repositoryPath);
// Initialize the repository
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
core.startGroup('Initializing the repository');
yield git.init();
yield git.remoteAdd('origin', repositoryUrl);
core.endGroup();
}
// Disable automatic garbage collection
core.startGroup('Disabling automatic garbage collection');
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.endGroup();
const authHelper = gitAuthHelper.createAuthHelper(git, settings);
try {
// Configure auth
core.startGroup('Setting up auth');
yield authHelper.configureAuth();
core.endGroup();
// LFS install
if (settings.lfs) {
yield git.lfsInstall();
}
// Fetch
core.startGroup('Fetching the repository');
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
yield git.fetch(settings.fetchDepth, refSpec);
core.endGroup();
// Checkout info
core.startGroup('Determining the checkout info');
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
core.endGroup();
// LFS fetch
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
// Explicit lfs fetch will fetch lfs objects in parallel.
if (settings.lfs) {
core.startGroup('Fetching LFS objects');
yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
core.endGroup();
}
// Checkout
core.startGroup('Checking out the ref');
yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
core.endGroup();
// Submodules
if (settings.submodules) {
try {
// Temporarily override global config
core.startGroup('Setting up auth for fetching submodules');
yield authHelper.configureGlobalAuth();
core.endGroup();
// Checkout submodules
core.startGroup('Fetching submodules');
yield git.submoduleSync(settings.nestedSubmodules);
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
core.endGroup();
// Persist credentials
if (settings.persistCredentials) {
core.startGroup('Persisting credentials for submodules');
yield authHelper.configureSubmoduleAuth();
core.endGroup();
}
}
finally {
Expand All @@ -5891,7 +5913,9 @@ function getSource(settings) {
finally {
// Remove auth
if (!settings.persistCredentials) {
core.startGroup('Removing auth');
yield authHelper.removeAuth();
core.endGroup();
}
}
});
Expand Down Expand Up @@ -7191,13 +7215,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert = __importStar(__webpack_require__(357));
const core = __importStar(__webpack_require__(470));
const fs = __importStar(__webpack_require__(747));
const fsHelper = __importStar(__webpack_require__(618));
const io = __importStar(__webpack_require__(1));
const path = __importStar(__webpack_require__(622));
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
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;
// Check whether using git or REST API
if (!git) {
Expand All @@ -7223,6 +7251,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
}
}
try {
core.startGroup('Removing previously created refs, to avoid conflicts');
// Checkout detached HEAD
if (!(yield git.isDetached())) {
yield git.checkoutDetach();
Expand All @@ -7237,15 +7266,18 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
for (const branch of branches) {
yield git.branchDelete(true, branch);
}
core.endGroup();
// Clean
if (clean) {
core.startGroup('Cleaning the repository');
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}'.`);
remove = true;
}
else if (!(yield git.tryReset())) {
remove = true;
}
core.endGroup();
if (remove) {
core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/git-auth-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class GitAuthHelper {
}

async removeGlobalAuth(): Promise<void> {
core.info(`Unsetting HOME override`)
core.debug(`Unsetting HOME override`)
this.git.removeEnvironmentVariable('HOME')
await io.rmRF(this.temporaryHomePath)
}
Expand Down
10 changes: 10 additions & 0 deletions src/git-directory-helper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import * as assert from 'assert'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as fsHelper from './fs-helper'
import * as io from '@actions/io'
import * as path from 'path'
import {IGitCommandManager} from './git-command-manager'
import {IGitSourceSettings} from './git-source-settings'

export async function prepareExistingDirectory(
git: IGitCommandManager | undefined,
repositoryPath: string,
repositoryUrl: string,
clean: boolean
): 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

// Check whether using git or REST API
Expand Down Expand Up @@ -38,6 +44,7 @@ export async function prepareExistingDirectory(
}

try {
core.startGroup('Removing previously created refs, to avoid conflicts')
thboop marked this conversation as resolved.
Show resolved Hide resolved
// Checkout detached HEAD
if (!(await git.isDetached())) {
await git.checkoutDetach()
Expand All @@ -54,9 +61,11 @@ export async function prepareExistingDirectory(
for (const branch of branches) {
await git.branchDelete(true, branch)
}
core.endGroup()

// Clean
if (clean) {
core.startGroup('Cleaning the repository')
if (!(await 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}'.`
Expand All @@ -65,6 +74,7 @@ export async function prepareExistingDirectory(
} else if (!(await git.tryReset())) {
remove = true
}
core.endGroup()

if (remove) {
core.warning(
Expand Down
24 changes: 24 additions & 0 deletions src/git-source-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
}

// Git command manager
core.startGroup('Getting Git version info')
const git = await getGitCommandManager(settings)
core.endGroup()

// Prepare existing directory, otherwise recreate
if (isExisting) {
Expand Down Expand Up @@ -85,55 +87,72 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
if (
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
) {
core.startGroup('Initializing the repository')
await git.init()
await git.remoteAdd('origin', repositoryUrl)
core.endGroup()
}

// Disable automatic garbage collection
core.startGroup('Disabling automatic garbage collection')
if (!(await 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.endGroup()

const authHelper = gitAuthHelper.createAuthHelper(git, settings)
try {
// Configure auth
core.startGroup('Setting up auth')
await authHelper.configureAuth()
core.endGroup()

// LFS install
if (settings.lfs) {
await git.lfsInstall()
}

// Fetch
core.startGroup('Fetching the repository')
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
await git.fetch(settings.fetchDepth, refSpec)
core.endGroup()

// Checkout info
core.startGroup('Determining the checkout info')
const checkoutInfo = await refHelper.getCheckoutInfo(
git,
settings.ref,
settings.commit
)
core.endGroup()

// LFS fetch
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
// Explicit lfs fetch will fetch lfs objects in parallel.
if (settings.lfs) {
core.startGroup('Fetching LFS objects')
await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
core.endGroup()
}

// Checkout
core.startGroup('Checking out the ref')
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
core.endGroup()

// Submodules
if (settings.submodules) {
try {
// Temporarily override global config
core.startGroup('Setting up auth for fetching submodules')
await authHelper.configureGlobalAuth()
core.endGroup()

// Checkout submodules
core.startGroup('Fetching submodules')
await git.submoduleSync(settings.nestedSubmodules)
await git.submoduleUpdate(
settings.fetchDepth,
Expand All @@ -143,10 +162,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
'git config --local gc.auto 0',
settings.nestedSubmodules
)
core.endGroup()

// Persist credentials
if (settings.persistCredentials) {
core.startGroup('Persisting credentials for submodules')
await authHelper.configureSubmoduleAuth()
core.endGroup()
}
} finally {
// Remove temporary global config override
Expand All @@ -159,7 +181,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
} finally {
// Remove auth
if (!settings.persistCredentials) {
core.startGroup('Removing auth')
await authHelper.removeAuth()
core.endGroup()
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/git-source-settings.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
export interface IGitSourceSettings {
/**
* The location on disk where the repository will be placed
*/
repositoryPath: string

/**
* The repository owner
*/
repositoryOwner: string

/**
* The repository name
*/
repositoryName: string

/**
* The ref to fetch
*/
ref: string

/**
* The commit to checkout
*/
commit: string

/**
* Indicates whether to clean the repository
*/
clean: boolean

/**
* The depth when fetching
*/
fetchDepth: number

/**
* Indicates whether to fetch LFS objects
*/
lfs: boolean

/**
* Indicates whether to checkout submodules
*/
submodules: boolean

/**
* Indicates whether to recursively checkout submodules
*/
nestedSubmodules: boolean

/**
* The auth token to use when fetching the repository
*/
authToken: string

/**
* The SSH key to configure
*/
sshKey: string

/**
* Additional SSH known hosts
*/
sshKnownHosts: string

/**
* Indicates whether the server must be a known host
*/
sshStrict: boolean

/**
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
*/
persistCredentials: boolean
}