Skip to content

Commit f7edeca

Browse files
authored
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
1 parent 68e252f commit f7edeca

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

Diff for: README.md

+13
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Add a step like this to your workflow:
5454
# Default: github_actor
5555
default_author: github_actor
5656

57+
# Arguments for the git fetch command. If set to false, the action won't fetch the repo.
58+
# For more info as to why fetching is usually recommended, please see the "Performance on large repos" FAQ.
59+
# Default: --tags --force
60+
fetch: false
61+
5762
# The message for the commit.
5863
# Default: 'Commit from GitHub Actions (name of the workflow)'
5964
message: 'Your commit message'
@@ -200,6 +205,14 @@ Some users reported that they were getting an error:
200205

201206
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)
202207

208+
### Performance on large repos
209+
210+
By default, the action will fetch the repository before starting to work on it: this ensures that it can see the already existing refs.
211+
212+
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.
213+
214+
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)
215+
203216
## Examples
204217

205218
### Different author/committer configurations

Diff for: action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ inputs:
2929
description: How the action should fill missing author name or email.
3030
required: false
3131
default: 'github_actor'
32+
fetch:
33+
description: Arguments for the git fetch command (if 'false', the action won't fetch the repo)
34+
required: false
35+
default: --tags --force
3236
message:
3337
description: The message for the commit
3438
required: false

Diff for: lib/index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/io.ts

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface InputTypes {
1010
committer_email: string
1111
cwd: string
1212
default_author: 'github_actor' | 'user_info' | 'github_actions'
13+
fetch: string
1314
message: string
1415
new_branch: string | undefined
1516
pathspec_error_handling: 'ignore' | 'exitImmediately' | 'exitAtEnd'
@@ -124,6 +125,20 @@ export async function checkInputs() {
124125
)
125126
// #endregion
126127

128+
// #region fetch
129+
if (getInput('fetch')) {
130+
let value: string | boolean
131+
132+
try {
133+
value = getInput('fetch', true)
134+
} catch {
135+
value = getInput('fetch')
136+
}
137+
138+
core.debug(`Currrent fetch option: '${value}' (parsed as ${typeof value})`)
139+
}
140+
// #endregion
141+
127142
// #region author_name, author_email
128143
let name, email
129144
switch (getInput('default_author')) {

Diff for: src/main.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,29 @@ core.info(`Running in ${baseDir}`)
5555
JSON.stringify((await git.listConfig()).all, null, 2)
5656
)
5757

58-
await git.fetch(['--tags', '--force'], log)
58+
let fetchOption: string | boolean
59+
try {
60+
fetchOption = getInput('fetch', true)
61+
} catch {
62+
fetchOption = getInput('fetch')
63+
}
64+
if (fetchOption) {
65+
core.info('> Fetching repo...')
66+
await git.fetch(
67+
matchGitArgs(fetchOption === true ? '' : fetchOption),
68+
log
69+
)
70+
} else core.info('> Not fetching repo.')
5971

6072
const targetBranch = getInput('new_branch')
6173
if (targetBranch) {
74+
core.info('> Checking-out branch...')
75+
76+
if (!fetchOption)
77+
core.warning(
78+
'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.'
79+
)
80+
6281
await git
6382
.checkout(targetBranch)
6483
.then(() => {
@@ -110,6 +129,12 @@ core.info(`Running in ${baseDir}`)
110129

111130
if (getInput('tag')) {
112131
core.info('> Tagging commit...')
132+
133+
if (!fetchOption)
134+
core.warning(
135+
'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.'
136+
)
137+
113138
await git
114139
.tag(matchGitArgs(getInput('tag') || ''), (err, data?) => {
115140
if (data) setOutput('tagged', 'true')
@@ -162,6 +187,7 @@ core.info(`Running in ${baseDir}`)
162187

163188
if (getInput('tag')) {
164189
core.info('> Pushing tags to repo...')
190+
165191
await git
166192
.pushTags('origin', matchGitArgs(getInput('tag_push') || ''))
167193
.then((data) => {

0 commit comments

Comments
 (0)