Skip to content

feat: add fetch input #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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