Skip to content

Commit

Permalink
feat: add fetch input (actions#423)
Browse files Browse the repository at this point in the history
* chore: add additional log notes

* feat: add `fetch` input

Ref actions#386

* fix: add warnings about not fetching

* docs: `fetch` input & large repos FAQ

* chore: fix typo
  • Loading branch information
EndBug committed Aug 22, 2022
1 parent 68e252f commit f7edeca
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,11 @@ Add a step like this to your workflow:
# Default: 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.
# Default: 'Commit from GitHub Actions (name of the workflow)'
message: 'Your commit message'
Expand Down Expand Up @@ -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)

### 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

### Different author/committer configurations
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -29,6 +29,10 @@ inputs:
description: How the action should fill missing author name or email.
required: false
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:
description: The message for the commit
required: false
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/io.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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')) {
Expand Down
28 changes: 27 additions & 1 deletion src/main.ts
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit f7edeca

Please sign in to comment.