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:
13
README.md
13
README.md
@@ -54,6 +54,11 @@ Add a step like this to your workflow:
|
|||||||
# Default: github_actor
|
# Default: github_actor
|
||||||
default_author: github_actor
|
default_author: github_actor
|
||||||
|
|
||||||
|
# Arguments for the git fetch command. If set to false, the action won't fetch the repo.
|
||||||
|
# For more info as to why fetching is usually recommended, please see the "Performance on large repos" FAQ.
|
||||||
|
# Default: --tags --force
|
||||||
|
fetch: false
|
||||||
|
|
||||||
# The message for the commit.
|
# The message for the commit.
|
||||||
# Default: 'Commit from GitHub Actions (name of the workflow)'
|
# Default: 'Commit from GitHub Actions (name of the workflow)'
|
||||||
message: 'Your commit message'
|
message: 'Your commit message'
|
||||||
@@ -200,6 +205,14 @@ Some users reported that they were getting an error:
|
|||||||
|
|
||||||
If you're getting this error and you're using `actions/checkout@v1`, try upgrading to `actions/checkout@v2`. If you're still having problems after upgrading, feel free to open an issue. Issue ref: [#146](https://github.com/EndBug/add-and-commit/issues/146)
|
If you're getting this error and you're using `actions/checkout@v1`, try upgrading to `actions/checkout@v2`. If you're still having problems after upgrading, feel free to open an issue. Issue ref: [#146](https://github.com/EndBug/add-and-commit/issues/146)
|
||||||
|
|
||||||
|
### Performance on large repos
|
||||||
|
|
||||||
|
By default, the action will fetch the repository before starting to work on it: this ensures that it can see the already existing refs.
|
||||||
|
|
||||||
|
When working with a repository that has a lot of branches and tags, fetching it can take a long time. If the fetch step is taking too much time, you can decide to skip it by setting the `fetch` input to `false`: this will prevent the action from running `git fetch` altogether.
|
||||||
|
|
||||||
|
Please note that you have to set up your workflow accordingly: not fetching the repo can impact branch and tag creation within the action, and for this reason it's recommended to disable it only if necessary. Issue ref: [#386](https://github.com/EndBug/add-and-commit/issues/386)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### Different author/committer configurations
|
### Different author/committer configurations
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ inputs:
|
|||||||
description: How the action should fill missing author name or email.
|
description: How the action should fill missing author name or email.
|
||||||
required: false
|
required: false
|
||||||
default: 'github_actor'
|
default: 'github_actor'
|
||||||
|
fetch:
|
||||||
|
description: Arguments for the git fetch command (if 'false', the action won't fetch the repo)
|
||||||
|
required: false
|
||||||
|
default: --tags --force
|
||||||
message:
|
message:
|
||||||
description: The message for the commit
|
description: The message for the commit
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
4
lib/index.js
generated
4
lib/index.js
generated
File diff suppressed because one or more lines are too long
15
src/io.ts
15
src/io.ts
@@ -10,6 +10,7 @@ interface InputTypes {
|
|||||||
committer_email: string
|
committer_email: string
|
||||||
cwd: string
|
cwd: string
|
||||||
default_author: 'github_actor' | 'user_info' | 'github_actions'
|
default_author: 'github_actor' | 'user_info' | 'github_actions'
|
||||||
|
fetch: string
|
||||||
message: string
|
message: string
|
||||||
new_branch: string | undefined
|
new_branch: string | undefined
|
||||||
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
|
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
|
||||||
@@ -124,6 +125,20 @@ export async function checkInputs() {
|
|||||||
)
|
)
|
||||||
// #endregion
|
// #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
|
// #region author_name, author_email
|
||||||
let name, email
|
let name, email
|
||||||
switch (getInput('default_author')) {
|
switch (getInput('default_author')) {
|
||||||
|
|||||||
28
src/main.ts
28
src/main.ts
@@ -55,10 +55,29 @@ core.info(`Running in ${baseDir}`)
|
|||||||
JSON.stringify((await git.listConfig()).all, null, 2)
|
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')
|
const targetBranch = getInput('new_branch')
|
||||||
if (targetBranch) {
|
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
|
await git
|
||||||
.checkout(targetBranch)
|
.checkout(targetBranch)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -110,6 +129,12 @@ core.info(`Running in ${baseDir}`)
|
|||||||
|
|
||||||
if (getInput('tag')) {
|
if (getInput('tag')) {
|
||||||
core.info('> Tagging commit...')
|
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
|
await git
|
||||||
.tag(matchGitArgs(getInput('tag') || ''), (err, data?) => {
|
.tag(matchGitArgs(getInput('tag') || ''), (err, data?) => {
|
||||||
if (data) setOutput('tagged', 'true')
|
if (data) setOutput('tagged', 'true')
|
||||||
@@ -162,6 +187,7 @@ core.info(`Running in ${baseDir}`)
|
|||||||
|
|
||||||
if (getInput('tag')) {
|
if (getInput('tag')) {
|
||||||
core.info('> Pushing tags to repo...')
|
core.info('> Pushing tags to repo...')
|
||||||
|
|
||||||
await git
|
await git
|
||||||
.pushTags('origin', matchGitArgs(getInput('tag_push') || ''))
|
.pushTags('origin', matchGitArgs(getInput('tag_push') || ''))
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user