mirror of http://gitea.com/actions/checkout
Default branch checkout option
This commit is contained in:
parent
e72243fb91
commit
5bbdf118df
|
@ -813,8 +813,7 @@ async function setup(testName: string): Promise<void> {
|
||||||
nestedSubmodules: false,
|
nestedSubmodules: false,
|
||||||
persistCredentials: true,
|
persistCredentials: true,
|
||||||
ref: 'refs/heads/main',
|
ref: 'refs/heads/main',
|
||||||
defaultRefOnError: true,
|
defaultBranchCheckout: false,
|
||||||
defaultBranch: 'main',
|
|
||||||
repositoryName: 'my-repo',
|
repositoryName: 'my-repo',
|
||||||
repositoryOwner: 'my-org',
|
repositoryOwner: 'my-org',
|
||||||
repositoryPath: '',
|
repositoryPath: '',
|
||||||
|
|
|
@ -1226,17 +1226,6 @@ function getSource(settings) {
|
||||||
core.startGroup('Setting up auth');
|
core.startGroup('Setting up auth');
|
||||||
yield authHelper.configureAuth();
|
yield authHelper.configureAuth();
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
|
||||||
// Configure default branch
|
|
||||||
core.startGroup('Setting up default branch');
|
|
||||||
if (settings.sshKey) {
|
|
||||||
settings.defaultBranch = yield git.getDefaultBranch(repositoryUrl);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
settings.defaultBranch = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
|
||||||
}
|
|
||||||
core.endGroup();
|
|
||||||
}
|
|
||||||
// Determine the default branch
|
// Determine the default branch
|
||||||
if (!settings.ref && !settings.commit) {
|
if (!settings.ref && !settings.commit) {
|
||||||
core.startGroup('Determining the default branch');
|
core.startGroup('Determining the default branch');
|
||||||
|
@ -1261,8 +1250,7 @@ function getSource(settings) {
|
||||||
else if (settings.sparseCheckout) {
|
else if (settings.sparseCheckout) {
|
||||||
fetchOptions.filter = 'blob:none';
|
fetchOptions.filter = 'blob:none';
|
||||||
}
|
}
|
||||||
if (settings.fetchDepth <= 0 ||
|
if (settings.fetchDepth <= 0 || settings.defaultBranchCheckout) {
|
||||||
(settings.defaultRefOnError && settings.defaultRefOnError === true)) {
|
|
||||||
// Fetch all branches and tags
|
// Fetch all branches and tags
|
||||||
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
|
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
|
||||||
yield git.fetch(refSpec, fetchOptions);
|
yield git.fetch(refSpec, fetchOptions);
|
||||||
|
@ -1283,17 +1271,20 @@ function getSource(settings) {
|
||||||
// Checkout info
|
// Checkout info
|
||||||
core.startGroup('Determining the checkout info');
|
core.startGroup('Determining the checkout info');
|
||||||
let checkoutInfo;
|
let checkoutInfo;
|
||||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
|
||||||
try {
|
try {
|
||||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.info('Could not determine the checkout info. Trying the default repo branch');
|
if (settings.defaultBranchCheckout) {
|
||||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.defaultBranch, settings.commit);
|
core.info('Could not determine the checkout info. Trying the default repository branch');
|
||||||
}
|
const repositoryDefaultBranch = settings.sshKey
|
||||||
|
? yield git.getDefaultBranch(repositoryUrl)
|
||||||
|
: yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
||||||
|
checkoutInfo = yield refHelper.getCheckoutInfo(git, repositoryDefaultBranch, settings.commit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// LFS fetch
|
// LFS fetch
|
||||||
|
@ -1748,10 +1739,10 @@ function getInputs() {
|
||||||
}
|
}
|
||||||
core.debug(`ref = '${result.ref}'`);
|
core.debug(`ref = '${result.ref}'`);
|
||||||
core.debug(`commit = '${result.commit}'`);
|
core.debug(`commit = '${result.commit}'`);
|
||||||
// Default ref on error
|
// Default branch checkout
|
||||||
result.defaultRefOnError =
|
result.defaultBranchCheckout =
|
||||||
(core.getInput('default-ref-on-error') || 'true').toUpperCase() === 'TRUE';
|
(core.getInput('default-branch-checkout') || 'true').toUpperCase() === 'TRUE';
|
||||||
core.debug(`default-ref-on-error = '${result.defaultRefOnError}'`);
|
core.debug(`default-branch-checkout = '${result.defaultBranchCheckout}'`);
|
||||||
// Clean
|
// Clean
|
||||||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE';
|
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE';
|
||||||
core.debug(`clean = ${result.clean}`);
|
core.debug(`clean = ${result.clean}`);
|
||||||
|
|
|
@ -130,21 +130,6 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
await authHelper.configureAuth()
|
await authHelper.configureAuth()
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
|
||||||
// Configure default branch
|
|
||||||
core.startGroup('Setting up default branch')
|
|
||||||
if (settings.sshKey) {
|
|
||||||
settings.defaultBranch = await git.getDefaultBranch(repositoryUrl)
|
|
||||||
} else {
|
|
||||||
settings.defaultBranch = await githubApiHelper.getDefaultBranch(
|
|
||||||
settings.authToken,
|
|
||||||
settings.repositoryOwner,
|
|
||||||
settings.repositoryName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
core.endGroup()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the default branch
|
// Determine the default branch
|
||||||
if (!settings.ref && !settings.commit) {
|
if (!settings.ref && !settings.commit) {
|
||||||
core.startGroup('Determining the default branch')
|
core.startGroup('Determining the default branch')
|
||||||
|
@ -181,10 +166,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
fetchOptions.filter = 'blob:none'
|
fetchOptions.filter = 'blob:none'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (settings.fetchDepth <= 0 || settings.defaultBranchCheckout) {
|
||||||
settings.fetchDepth <= 0 ||
|
|
||||||
(settings.defaultRefOnError && settings.defaultRefOnError === true)
|
|
||||||
) {
|
|
||||||
// Fetch all branches and tags
|
// Fetch all branches and tags
|
||||||
let refSpec = refHelper.getRefSpecForAllHistory(
|
let refSpec = refHelper.getRefSpecForAllHistory(
|
||||||
settings.ref,
|
settings.ref,
|
||||||
|
@ -209,7 +191,6 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
// Checkout info
|
// Checkout info
|
||||||
core.startGroup('Determining the checkout info')
|
core.startGroup('Determining the checkout info')
|
||||||
let checkoutInfo: refHelper.ICheckoutInfo
|
let checkoutInfo: refHelper.ICheckoutInfo
|
||||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
|
||||||
try {
|
try {
|
||||||
checkoutInfo = await refHelper.getCheckoutInfo(
|
checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
git,
|
git,
|
||||||
|
@ -217,21 +198,25 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
settings.commit
|
settings.commit
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (settings.defaultBranchCheckout) {
|
||||||
core.info(
|
core.info(
|
||||||
'Could not determine the checkout info. Trying the default repo branch'
|
'Could not determine the checkout info. Trying the default repository branch'
|
||||||
|
)
|
||||||
|
const repositoryDefaultBranch = settings.sshKey
|
||||||
|
? await git.getDefaultBranch(repositoryUrl)
|
||||||
|
: await githubApiHelper.getDefaultBranch(
|
||||||
|
settings.authToken,
|
||||||
|
settings.repositoryOwner,
|
||||||
|
settings.repositoryName
|
||||||
)
|
)
|
||||||
checkoutInfo = await refHelper.getCheckoutInfo(
|
checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
git,
|
git,
|
||||||
settings.defaultBranch,
|
repositoryDefaultBranch,
|
||||||
settings.commit
|
settings.commit
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
checkoutInfo = await refHelper.getCheckoutInfo(
|
throw error
|
||||||
git,
|
}
|
||||||
settings.ref,
|
|
||||||
settings.commit
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,9 @@ export interface IGitSourceSettings {
|
||||||
ref: string
|
ref: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to checkout the default repository branch if specified ref does not exist.
|
* Indicates whether to checkout the default repository branch if the requested ref does not exist
|
||||||
*/
|
*/
|
||||||
defaultRefOnError: boolean
|
defaultBranchCheckout: boolean
|
||||||
|
|
||||||
/**
|
|
||||||
* The target ref to fetch if it exists
|
|
||||||
*/
|
|
||||||
defaultBranch: string
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The commit to checkout
|
* The commit to checkout
|
||||||
|
|
|
@ -78,10 +78,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
core.debug(`ref = '${result.ref}'`)
|
core.debug(`ref = '${result.ref}'`)
|
||||||
core.debug(`commit = '${result.commit}'`)
|
core.debug(`commit = '${result.commit}'`)
|
||||||
|
|
||||||
// Default ref on error
|
// Default branch checkout
|
||||||
result.defaultRefOnError =
|
result.defaultBranchCheckout =
|
||||||
(core.getInput('default-ref-on-error') || 'true').toUpperCase() === 'TRUE'
|
(core.getInput('default-branch-checkout') || 'true').toUpperCase() ===
|
||||||
core.debug(`default-ref-on-error = '${result.defaultRefOnError}'`)
|
'TRUE'
|
||||||
|
core.debug(`default-branch-checkout = '${result.defaultBranchCheckout}'`)
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
||||||
|
|
Loading…
Reference in New Issue