mirror of
https://github.com/actions/checkout.git
synced 2025-09-11 20:05:50 +08:00
Compare commits
7 Commits
v4.2.2
...
a072fe2d48
Author | SHA1 | Date | |
---|---|---|---|
|
a072fe2d48 | ||
|
85e6279cec | ||
|
009b9ae9e4 | ||
|
cbb722410c | ||
|
3b9b8c884f | ||
|
55ad59dfaa | ||
|
dedef103f1 |
39
README.md
39
README.md
@@ -143,6 +143,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 +212,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 +226,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)
|
||||
|
||||
@@ -288,6 +289,40 @@ jobs:
|
||||
```
|
||||
*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 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
|
||||
|
||||
# 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)
|
||||
|
@@ -314,7 +314,7 @@ class GitCommandManager {
|
||||
line = line.trim()
|
||||
if (line.startsWith('ref:') || line.endsWith('HEAD')) {
|
||||
return line
|
||||
.substr('ref:'.length, line.length - 'ref:'.length - 'HEAD'.length)
|
||||
.slice('ref:'.length, line.length - 'HEAD'.length)
|
||||
.trim()
|
||||
}
|
||||
}
|
||||
|
@@ -64,11 +64,11 @@ export async function prepareExistingDirectory(
|
||||
if (ref) {
|
||||
ref = ref.startsWith('refs/') ? ref : `refs/heads/${ref}`
|
||||
if (ref.startsWith('refs/heads/')) {
|
||||
const upperName1 = ref.toUpperCase().substr('REFS/HEADS/'.length)
|
||||
const upperName1 = ref.toUpperCase().slice('REFS/HEADS/'.length)
|
||||
const upperName1Slash = `${upperName1}/`
|
||||
branches = await git.branchList(true)
|
||||
for (const branch of branches) {
|
||||
const upperName2 = branch.substr('origin/'.length).toUpperCase()
|
||||
const upperName2 = branch.slice('origin/'.length).toUpperCase()
|
||||
const upperName2Slash = `${upperName2}/`
|
||||
if (
|
||||
upperName1.startsWith(upperName2Slash) ||
|
||||
|
@@ -43,7 +43,7 @@ function updateUsage(
|
||||
const newReadme: string[] = []
|
||||
|
||||
// Append the beginning
|
||||
newReadme.push(originalReadme.substr(0, startTokenIndex + startToken.length))
|
||||
newReadme.push(originalReadme.slice(0, startTokenIndex + startToken.length))
|
||||
|
||||
// Build the new usage section
|
||||
newReadme.push('```yaml', `- uses: ${actionReference}`, ' with:')
|
||||
@@ -68,9 +68,9 @@ function updateUsage(
|
||||
// Longer than width? Find a space to break apart
|
||||
let segment: string = description
|
||||
if (description.length > width) {
|
||||
segment = description.substr(0, width + 1)
|
||||
segment = description.slice(0, width + 1)
|
||||
while (!segment.endsWith(' ') && !segment.endsWith('\n') && segment) {
|
||||
segment = segment.substr(0, segment.length - 1)
|
||||
segment = segment.slice(0, -1)
|
||||
}
|
||||
|
||||
// Trimmed too much?
|
||||
@@ -84,14 +84,14 @@ function updateUsage(
|
||||
// Check for newline
|
||||
const newlineIndex = segment.indexOf('\n')
|
||||
if (newlineIndex >= 0) {
|
||||
segment = segment.substr(0, newlineIndex + 1)
|
||||
segment = segment.slice(0, newlineIndex + 1)
|
||||
}
|
||||
|
||||
// Append segment
|
||||
newReadme.push(` # ${segment}`.trimRight())
|
||||
|
||||
// Remaining
|
||||
description = description.substr(segment.length)
|
||||
description = description.slice(segment.length)
|
||||
}
|
||||
|
||||
if (input.default !== undefined) {
|
||||
@@ -113,7 +113,7 @@ function updateUsage(
|
||||
newReadme.push('```')
|
||||
|
||||
// Append the end
|
||||
newReadme.push(originalReadme.substr(endTokenIndex))
|
||||
newReadme.push(originalReadme.slice(endTokenIndex))
|
||||
|
||||
// Write the new README
|
||||
fs.writeFileSync(readmePath, newReadme.join(os.EOL))
|
||||
|
@@ -282,6 +282,6 @@ function select(obj: any, path: string): any {
|
||||
return obj[path]
|
||||
}
|
||||
|
||||
const key = path.substr(0, i)
|
||||
return select(obj[key], path.substr(i + 1))
|
||||
const key = path.slice(0, i)
|
||||
return select(obj[key], path.slice(i + 1))
|
||||
}
|
||||
|
Reference in New Issue
Block a user