mirror of
https://github.com/actions/checkout.git
synced 2024-12-25 10:33:04 +07:00
feat(git config): Set default user.name and user.email in git config
This commit is contained in:
parent
cbb722410c
commit
f3b199b7ed
@ -281,8 +281,6 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
date > generated.txt
|
date > generated.txt
|
||||||
# Note: the following account information will not work on GHES
|
# Note: the following account information will not work on GHES
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
||||||
git add .
|
git add .
|
||||||
git commit -m "generated"
|
git commit -m "generated"
|
||||||
git push
|
git push
|
||||||
@ -305,8 +303,6 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
date > generated.txt
|
date > generated.txt
|
||||||
# Note: the following account information will not work on GHES
|
# Note: the following account information will not work on GHES
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
||||||
git add .
|
git add .
|
||||||
git commit -m "generated"
|
git commit -m "generated"
|
||||||
git push
|
git push
|
||||||
|
@ -22,6 +22,12 @@ inputs:
|
|||||||
|
|
||||||
[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)
|
[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)
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
configure-user:
|
||||||
|
description: >
|
||||||
|
Whether to configure user.name and user.email in the local git config.
|
||||||
|
This is required to push a commit from a Github Action Workflow.
|
||||||
|
Set to `false` to disable the config.
|
||||||
|
default: true
|
||||||
ssh-key:
|
ssh-key:
|
||||||
description: >
|
description: >
|
||||||
SSH key used to fetch the repository. The SSH key is configured with the local
|
SSH key used to fetch the repository. The SSH key is configured with the local
|
||||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -1813,6 +1813,9 @@ function getInputs() {
|
|||||||
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
||||||
// Auth token
|
// Auth token
|
||||||
result.authToken = core.getInput('token', { required: true });
|
result.authToken = core.getInput('token', { required: true });
|
||||||
|
// Configure user
|
||||||
|
result.configureUser =
|
||||||
|
(core.getInput('configure-user') || 'true').toUpperCase() === 'TRUE'
|
||||||
// SSH
|
// SSH
|
||||||
result.sshKey = core.getInput('ssh-key');
|
result.sshKey = core.getInput('ssh-key');
|
||||||
result.sshKnownHosts = core.getInput('ssh-known-hosts');
|
result.sshKnownHosts = core.getInput('ssh-known-hosts');
|
||||||
|
@ -274,6 +274,14 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||||||
settings.commit,
|
settings.commit,
|
||||||
settings.githubServerUrl
|
settings.githubServerUrl
|
||||||
)
|
)
|
||||||
|
if (settings.configureUser) {
|
||||||
|
if (!await git.configExists('user.name', true)) {
|
||||||
|
await git.config('user.name', 'github-action[bot]', true)
|
||||||
|
}
|
||||||
|
if (!await git.configExists('user.email', true)) {
|
||||||
|
await git.config('user.email', '41898282+github-actions[bot]@users.noreply.github.com', true)
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (authHelper) {
|
if (authHelper) {
|
||||||
|
@ -79,6 +79,11 @@ export interface IGitSourceSettings {
|
|||||||
*/
|
*/
|
||||||
authToken: string
|
authToken: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether to set a default user name and email in the local git config
|
||||||
|
*/
|
||||||
|
configureUser: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SSH key to configure
|
* The SSH key to configure
|
||||||
*/
|
*/
|
||||||
|
@ -138,6 +138,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||||||
// Auth token
|
// Auth token
|
||||||
result.authToken = core.getInput('token', {required: true})
|
result.authToken = core.getInput('token', {required: true})
|
||||||
|
|
||||||
|
// Configure user
|
||||||
|
result.configureUser =
|
||||||
|
(core.getInput('configure-user') || 'true').toUpperCase() === 'TRUE'
|
||||||
|
|
||||||
// SSH
|
// SSH
|
||||||
result.sshKey = core.getInput('ssh-key')
|
result.sshKey = core.getInput('ssh-key')
|
||||||
result.sshKnownHosts = core.getInput('ssh-known-hosts')
|
result.sshKnownHosts = core.getInput('ssh-known-hosts')
|
||||||
|
Loading…
Reference in New Issue
Block a user