mirror of
https://github.com/actions/checkout.git
synced 2026-02-12 22:14:52 +08:00
Compare commits
7 Commits
v4.2.2
...
fed14465db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fed14465db | ||
|
|
5fba9eb899 | ||
|
|
85e6279cec | ||
|
|
009b9ae9e4 | ||
|
|
f3b199b7ed | ||
|
|
cbb722410c | ||
|
|
3b9b8c884f |
45
README.md
45
README.md
@@ -40,6 +40,12 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
#
|
||||
# Default: ${{ github.token }}
|
||||
token: ''
|
||||
|
||||
# Github slug used to configure local user.name and user.email for git.
|
||||
# This is required to push a commit from a Github Action Workflow
|
||||
# Set to '' to disable this configuration
|
||||
# Default: "github-action[bot]
|
||||
git-config: ''
|
||||
|
||||
# SSH key used to fetch the repository. The SSH key is configured with the local
|
||||
# git config, which enables your scripts to run authenticated git commands. The
|
||||
@@ -143,6 +149,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
|
||||
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
|
||||
- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token)
|
||||
- [Push a commit to a PR using the built-in token](#Push-a-commit-to-a-PR-using-the-built-in-token)
|
||||
|
||||
## Fetch only the root files
|
||||
|
||||
@@ -211,7 +218,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
repository: my-org/my-tools
|
||||
path: my-tools
|
||||
```
|
||||
> - If your secondary repository is private you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
|
||||
> - If your secondary repository is private or internal you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
|
||||
|
||||
## Checkout multiple repos (nested)
|
||||
|
||||
@@ -225,7 +232,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
repository: my-org/my-tools
|
||||
path: my-tools
|
||||
```
|
||||
> - If your secondary repository is private you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
|
||||
> - If your secondary repository is private or internal you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
|
||||
|
||||
## Checkout multiple repos (private)
|
||||
|
||||
@@ -280,14 +287,44 @@ jobs:
|
||||
- run: |
|
||||
date > generated.txt
|
||||
# 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 commit -m "generated"
|
||||
git push
|
||||
```
|
||||
*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D
|
||||
|
||||
## Push a commit to a PR using the built-in token
|
||||
|
||||
In a pull request trigger, `ref` is required as GitHub Actions checks out in detached HEAD mode, meaning it doesn’t check out your branch by default.
|
||||
|
||||
```yaml
|
||||
on: pull_request
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
- run: |
|
||||
date > generated.txt
|
||||
# Note: the following account information will not work on GHES
|
||||
git add .
|
||||
git commit -m "generated"
|
||||
git push
|
||||
```
|
||||
|
||||
*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D
|
||||
|
||||
# Recommended permissions
|
||||
|
||||
When using the `checkout` action in your GitHub Actions workflow, it is recommended to set the following `GITHUB_TOKEN` permissions to ensure proper functionality, unless alternative auth is provided via the `token` or `ssh-key` inputs:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
contents: read
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||
|
||||
@@ -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)
|
||||
default: ${{ github.token }}
|
||||
git-user:
|
||||
description: >
|
||||
Github slug used to configure local user.name and user.email for git.
|
||||
This is required to push a commit from a Github Action Workflow.
|
||||
Set to '' to disable this configuration.
|
||||
default: "github-action[bot]"
|
||||
ssh-key:
|
||||
description: >
|
||||
SSH key used to fetch the repository. The SSH key is configured with the local
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
@@ -1813,6 +1813,8 @@ function getInputs() {
|
||||
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
||||
// Auth token
|
||||
result.authToken = core.getInput('token', { required: true });
|
||||
// Configure user
|
||||
result.gitUser = (core.getInput('git-user') || 'github-action[bot]')
|
||||
// SSH
|
||||
result.sshKey = core.getInput('ssh-key');
|
||||
result.sshKnownHosts = core.getInput('ssh-known-hosts');
|
||||
|
||||
@@ -274,6 +274,16 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||
settings.commit,
|
||||
settings.githubServerUrl
|
||||
)
|
||||
if (settings.gitUser) {
|
||||
if (!await git.configExists('user.name', true)) {
|
||||
await git.config('user.name', settings.gitUser, true)
|
||||
}
|
||||
if (!await git.configExists('user.email', true)) {
|
||||
|
||||
const userId = await githubApiHelper.getUserId(settings.gitUser, settings.authToken, settings.githubServerUrl);
|
||||
await git.config('user.email', `${userId}+${settings.gitUser}@users.noreply.github.com`, true)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Remove auth
|
||||
if (authHelper) {
|
||||
|
||||
@@ -79,6 +79,11 @@ export interface IGitSourceSettings {
|
||||
*/
|
||||
authToken: string
|
||||
|
||||
/**
|
||||
* A github user slug to set a default user name and email in the local git config
|
||||
*/
|
||||
gitUser: string
|
||||
|
||||
/**
|
||||
* The SSH key to configure
|
||||
*/
|
||||
|
||||
@@ -143,3 +143,15 @@ async function downloadArchive(
|
||||
})
|
||||
return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer
|
||||
}
|
||||
|
||||
export async function getUserId(
|
||||
username: string,
|
||||
authToken: string,
|
||||
baseUrl?: string
|
||||
): Promise<number> {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
})
|
||||
const user = await octokit.rest.users.getByUsername({username,});
|
||||
return user.data.id
|
||||
}
|
||||
|
||||
@@ -138,6 +138,9 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
// Auth token
|
||||
result.authToken = core.getInput('token', {required: true})
|
||||
|
||||
// Git user
|
||||
result.gitUser = core.getInput('git-user') || 'github-action[bot]'
|
||||
|
||||
// SSH
|
||||
result.sshKey = core.getInput('ssh-key')
|
||||
result.sshKnownHosts = core.getInput('ssh-known-hosts')
|
||||
|
||||
Reference in New Issue
Block a user