Skip to content

Commit 022dd69

Browse files
committed
feat(git config): Set default user.name and user.email in git config
1 parent cbb7224 commit 022dd69

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

Diff for: README.md

+13-17
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
131131
132132
# Scenarios
133133
134-
- [Fetch only the root files](#Fetch-only-the-root-files)
135-
- [Fetch only the root files and `.github` and `src` folder](#Fetch-only-the-root-files-and-github-and-src-folder)
136-
- [Fetch only a single file](#Fetch-only-a-single-file)
137-
- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
138-
- [Checkout a different branch](#Checkout-a-different-branch)
139-
- [Checkout HEAD^](#Checkout-HEAD)
140-
- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side)
141-
- [Checkout multiple repos (nested)](#Checkout-multiple-repos-nested)
142-
- [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
143-
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
144-
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
145-
- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token)
146-
- [Push a commit to a PR using the built-in token](#Push-a-commit-to-a-PR-using-the-built-in-token)
134+
- [Fetch only the root files](#fetch-only-the-root-files)
135+
- [Fetch only the root files and `.github` and `src` folder](#fetch-only-the-root-files-and-github-and-src-folder)
136+
- [Fetch only a single file](#fetch-only-a-single-file)
137+
- [Fetch all history for all tags and branches](#fetch-all-history-for-all-tags-and-branches)
138+
- [Checkout a different branch](#checkout-a-different-branch)
139+
- [Checkout HEAD^](#checkout-head)
140+
- [Checkout multiple repos (side by side)](#checkout-multiple-repos-side-by-side)
141+
- [Checkout multiple repos (nested)](#checkout-multiple-repos-nested)
142+
- [Checkout multiple repos (private)](#checkout-multiple-repos-private)
143+
- [Checkout pull request HEAD commit instead of merge commit](#checkout-pull-request-head-commit-instead-of-merge-commit)
144+
- [Checkout pull request on closed event](#checkout-pull-request-on-closed-event)
145+
- [Push a commit using the built-in token](#push-a-commit-using-the-built-in-token)
146+
- [Push a commit to a PR using the built-in token](#push-a-commit-to-a-pr-using-the-built-in-token)
147147

148148
## Fetch only the root files
149149

@@ -281,8 +281,6 @@ jobs:
281281
- run: |
282282
date > generated.txt
283283
# Note: the following account information will not work on GHES
284-
git config user.name "github-actions[bot]"
285-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
286284
git add .
287285
git commit -m "generated"
288286
git push
@@ -305,8 +303,6 @@ jobs:
305303
- run: |
306304
date > generated.txt
307305
# Note: the following account information will not work on GHES
308-
git config user.name "github-actions[bot]"
309-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
310306
git add .
311307
git commit -m "generated"
312308
git push

Diff for: action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ inputs:
2222
2323
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
2424
default: ${{ github.token }}
25+
configure-user:
26+
description: >
27+
Whether to configure user.name and user.email in the local git config.
28+
This is required to push a commit from a Github Action Workflow.
29+
Set to `false` to disable the config.
30+
default: true
2531
ssh-key:
2632
description: >
2733
SSH key used to fetch the repository. The SSH key is configured with the local

Diff for: src/git-source-provider.ts

+8
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
274274
settings.commit,
275275
settings.githubServerUrl
276276
)
277+
if (settings.configureUser) {
278+
if (!await git.configExists('user.name', true)) {
279+
await git.config('user.name', 'github-action[bot]', true)
280+
}
281+
if (!await git.configExists('user.email', true)) {
282+
await git.config('user.email', '41898282+github-actions[bot]@users.noreply.github.com', true)
283+
}
284+
}
277285
} finally {
278286
// Remove auth
279287
if (authHelper) {

Diff for: src/git-source-settings.ts

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export interface IGitSourceSettings {
7979
*/
8080
authToken: string
8181

82+
/**
83+
* Indicates whether to set a default user name and email in the local git config
84+
*/
85+
configureUser: boolean
86+
8287
/**
8388
* The SSH key to configure
8489
*/

Diff for: src/input-helper.ts

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
138138
// Auth token
139139
result.authToken = core.getInput('token', {required: true})
140140

141+
// Configure user
142+
result.configureUser =
143+
(core.getInput('configure-user') || 'true').toUpperCase() === 'TRUE'
144+
141145
// SSH
142146
result.sshKey = core.getInput('ssh-key')
143147
result.sshKnownHosts = core.getInput('ssh-known-hosts')

0 commit comments

Comments
 (0)