Skip to content
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

Set default user.name and user.email #584

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

jablko
Copy link

@jablko jablko commented Sep 15, 2021

This PR sets up a default user.name and user.email for scripting git commit. Users can continue to configure their own values as now, this PR just affords the option not to.

Shouldn't affect existing users: If users git config --global user.{name,email} before actions/checkout, this will respect existing values. If they git config --global after actions/checkout they'll overwrite these defaults. If they git config --local (before or after), those values take precedence.

Fixes #13, although the issue proposed defaulting to the author/user from the event that triggered the action.

Also discussed in #158, although the PR doesn't propose defaults.

Configuring user.{name,email}/scripting git commit is documented in the README.md. The relevant text of ADR 0153 reads:

Note:

  • Users scripting git commit may need to set the username and email. The service does not provide any reasonable default value. Users can add git config user.name <NAME> and git config user.email <EMAIL>. We will document this guidance.

Default user.name

I used $GITHUB_WORKFLOW for the default user.name because it's the most helpful value to have in there? Other proposals include the current README.md value ("github-actions") and the author/user from the event that triggered the action.

Here's how $GITHUB_WORKFLOW looks in GitHub's UI -- however I'm equally happy if a different default is implemented: Screenshot from 2021-09-10 10-55-25

Default user.email

I went with the current README.md value ("[email protected]"), however @JojOatXGME lays out the options.

@wheelerlaw
Copy link

+1 for using github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> as the name and email. That will make it so it shows up nicely in the GitHub UI.

Comment on lines +223 to +226
await git.config('user.name', github.context.workflow, true)
}
if (!await git.configExists('user.email', true)) {
await git.config('user.email', '[email protected]', true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a bot account for GitHub Actions. It seems like it's a decent default.

checkout/README.md

Lines 283 to 284 in 692973e

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

Suggested change
await git.config('user.name', github.context.workflow, true)
}
if (!await git.configExists('user.email', true)) {
await git.config('user.email', 'github-actions@github.com', true)
await git.config('user.name', 'github-actions[bot]', true)
}
if (!await git.configExists('user.email', true)) {
await git.config('user.email', '41898282+github-actions[bot]@users.noreply.github.com', true)

@qoomon
Copy link

qoomon commented Aug 2, 2024

Maybe it make sense to add user as an action input and choose who should be set as user e.g. bot, actor, committer or even manually

I've created a handy action for that use case. Feel free to have look at https://github.com/qoomon/actions--setup-git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set git user and email
5 participants