feat: add fetch input (#423)

* chore: add additional log notes

* feat: add `fetch` input

Ref #386

* fix: add warnings about not fetching

* docs: `fetch` input & large repos FAQ

* chore: fix typo
This commit is contained in:
Federico Grandi
2022-08-22 19:26:22 +02:00
committed by GitHub
parent 68e252f6d5
commit f7edecabb7
5 changed files with 61 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ interface InputTypes {
committer_email: string
cwd: string
default_author: 'github_actor' | 'user_info' | 'github_actions'
fetch: string
message: string
new_branch: string | undefined
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
@@ -124,6 +125,20 @@ export async function checkInputs() {
)
// #endregion
// #region fetch
if (getInput('fetch')) {
let value: string | boolean
try {
value = getInput('fetch', true)
} catch {
value = getInput('fetch')
}
core.debug(`Currrent fetch option: '${value}' (parsed as ${typeof value})`)
}
// #endregion
// #region author_name, author_email
let name, email
switch (getInput('default_author')) {

View File

@@ -55,10 +55,29 @@ core.info(`Running in ${baseDir}`)
JSON.stringify((await git.listConfig()).all, null, 2)
)
await git.fetch(['--tags', '--force'], log)
let fetchOption: string | boolean
try {
fetchOption = getInput('fetch', true)
} catch {
fetchOption = getInput('fetch')
}
if (fetchOption) {
core.info('> Fetching repo...')
await git.fetch(
matchGitArgs(fetchOption === true ? '' : fetchOption),
log
)
} else core.info('> Not fetching repo.')
const targetBranch = getInput('new_branch')
if (targetBranch) {
core.info('> Checking-out branch...')
if (!fetchOption)
core.warning(
'Creating a new branch without fetching the repo first could result in an error when pushing to GitHub. Refer to the action README for more info about this topic.'
)
await git
.checkout(targetBranch)
.then(() => {
@@ -110,6 +129,12 @@ core.info(`Running in ${baseDir}`)
if (getInput('tag')) {
core.info('> Tagging commit...')
if (!fetchOption)
core.warning(
'Creating a tag without fetching the repo first could result in an error when pushing to GitHub. Refer to the action README for more info about this topic.'
)
await git
.tag(matchGitArgs(getInput('tag') || ''), (err, data?) => {
if (data) setOutput('tagged', 'true')
@@ -162,6 +187,7 @@ core.info(`Running in ${baseDir}`)
if (getInput('tag')) {
core.info('> Pushing tags to repo...')
await git
.pushTags('origin', matchGitArgs(getInput('tag_push') || ''))
.then((data) => {