mirror of
https://github.com/actions/checkout.git
synced 2026-03-07 08:51:46 +08:00
Compare commits
6 Commits
e82203d42e
...
381b035b47
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
381b035b47 | ||
|
|
8e8c483db8 | ||
|
|
033fa0dc0b | ||
|
|
ab5d862ce8 | ||
|
|
5fba9eb899 | ||
|
|
f3b199b7ed |
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@ -165,6 +165,22 @@ jobs:
|
||||
- name: Verify submodules recursive
|
||||
run: __test__/verify-submodules-recursive.sh
|
||||
|
||||
# Worktree credentials
|
||||
- name: Checkout for worktree test
|
||||
uses: ./
|
||||
with:
|
||||
path: worktree-test
|
||||
- name: Verify worktree credentials
|
||||
shell: bash
|
||||
run: __test__/verify-worktree.sh worktree-test worktree-branch
|
||||
|
||||
# Worktree credentials in container step
|
||||
- name: Verify worktree credentials in container step
|
||||
if: runner.os == 'Linux'
|
||||
uses: docker://bitnami/git:latest
|
||||
with:
|
||||
args: bash __test__/verify-worktree.sh worktree-test container-worktree-branch
|
||||
|
||||
# Basic checkout using REST API
|
||||
- name: Remove basic
|
||||
if: runner.os != 'windows'
|
||||
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,19 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## V6.0.0
|
||||
## v6.0.0
|
||||
* Persist creds to a separate file by @ericsciple in https://github.com/actions/checkout/pull/2286
|
||||
* Update README to include Node.js 24 support details and requirements by @salmanmkc in https://github.com/actions/checkout/pull/2248
|
||||
|
||||
## V5.0.1
|
||||
## v5.0.1
|
||||
* Port v6 cleanup to v5 by @ericsciple in https://github.com/actions/checkout/pull/2301
|
||||
|
||||
## V5.0.0
|
||||
## v5.0.0
|
||||
* Update actions checkout to use node 24 by @salmanmkc in https://github.com/actions/checkout/pull/2226
|
||||
|
||||
## V4.3.1
|
||||
## v4.3.1
|
||||
* Port v6 cleanup to v4 by @ericsciple in https://github.com/actions/checkout/pull/2305
|
||||
|
||||
## V4.3.0
|
||||
## v4.3.0
|
||||
* docs: update README.md by @motss in https://github.com/actions/checkout/pull/1971
|
||||
* Add internal repos for checking out multiple repositories by @mouismail in https://github.com/actions/checkout/pull/1977
|
||||
* Documentation update - add recommended permissions to Readme by @benwells in https://github.com/actions/checkout/pull/2043
|
||||
|
||||
15
README.md
15
README.md
@ -4,8 +4,9 @@
|
||||
|
||||
## What's new
|
||||
|
||||
- Updated `persist-credentials` to store the credentials under `$RUNNER_TEMP` instead of directly in the local git config.
|
||||
- This requires a minimum Actions Runner version of [v2.329.0](https://github.com/actions/runner/releases/tag/v2.329.0) to access the persisted credentials for [Docker container action](https://docs.github.com/en/actions/tutorials/use-containerized-services/create-a-docker-container-action) scenarios.
|
||||
- Improved credential security: `persist-credentials` now stores credentials in a separate file under `$RUNNER_TEMP` instead of directly in `.git/config`
|
||||
- No workflow changes required — `git fetch`, `git push`, etc. continue to work automatically
|
||||
- Running authenticated git commands from a [Docker container action](https://docs.github.com/actions/sharing-automations/creating-actions/creating-a-docker-container-action) requires Actions Runner [v2.329.0](https://github.com/actions/runner/releases/tag/v2.329.0) or later
|
||||
|
||||
# Checkout v5
|
||||
|
||||
@ -74,6 +75,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-user: ''
|
||||
|
||||
# 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
|
||||
# post-job step removes the SSH key.
|
||||
@ -323,8 +330,6 @@ 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
|
||||
@ -347,8 +352,6 @@ 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
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as gitAuthHelper from '../lib/git-auth-helper'
|
||||
import * as gitAuthHelper from '../src/git-auth-helper'
|
||||
import * as io from '@actions/io'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as stateHelper from '../lib/state-helper'
|
||||
import {IGitCommandManager} from '../lib/git-command-manager'
|
||||
import {IGitSourceSettings} from '../lib/git-source-settings'
|
||||
import * as stateHelper from '../src/state-helper'
|
||||
import {IGitCommandManager} from '../src/git-command-manager'
|
||||
import {IGitSourceSettings} from '../src/git-source-settings'
|
||||
|
||||
const isWindows = process.platform === 'win32'
|
||||
const testWorkspace = path.join(__dirname, '_temp', 'git-auth-helper')
|
||||
@ -1173,7 +1173,8 @@ async function setup(testName: string): Promise<void> {
|
||||
sshUser: '',
|
||||
workflowOrganizationId: 123456,
|
||||
setSafeDirectory: true,
|
||||
githubServerUrl: githubServerUrl
|
||||
githubServerUrl: githubServerUrl,
|
||||
gitUser: 'github-action[bot]'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as exec from '@actions/exec'
|
||||
import * as fshelper from '../lib/fs-helper'
|
||||
import * as commandManager from '../lib/git-command-manager'
|
||||
import * as fshelper from '../src/fs-helper'
|
||||
import * as commandManager from '../src/git-command-manager'
|
||||
|
||||
let git: commandManager.IGitCommandManager
|
||||
let mockExec = jest.fn()
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as gitDirectoryHelper from '../lib/git-directory-helper'
|
||||
import * as gitDirectoryHelper from '../src/git-directory-helper'
|
||||
import * as io from '@actions/io'
|
||||
import * as path from 'path'
|
||||
import {IGitCommandManager} from '../lib/git-command-manager'
|
||||
import {IGitCommandManager} from '../src/git-command-manager'
|
||||
|
||||
const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
|
||||
let repositoryPath: string
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fsHelper from '../lib/fs-helper'
|
||||
import * as fsHelper from '../src/fs-helper'
|
||||
import * as github from '@actions/github'
|
||||
import * as inputHelper from '../lib/input-helper'
|
||||
import * as inputHelper from '../src/input-helper'
|
||||
import * as path from 'path'
|
||||
import * as workflowContextHelper from '../lib/workflow-context-helper'
|
||||
import {IGitSourceSettings} from '../lib/git-source-settings'
|
||||
import * as workflowContextHelper from '../src/workflow-context-helper'
|
||||
import {IGitSourceSettings} from '../src/git-source-settings'
|
||||
|
||||
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
|
||||
const gitHubWorkspace = path.resolve('/checkout-tests/workspace')
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import * as refHelper from '../lib/ref-helper'
|
||||
import {IGitCommandManager} from '../lib/git-command-manager'
|
||||
import * as refHelper from '../src/ref-helper'
|
||||
import {IGitCommandManager} from '../src/git-command-manager'
|
||||
|
||||
const commit = '1234567890123456789012345678901234567890'
|
||||
let git: IGitCommandManager
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import * as core from '@actions/core'
|
||||
import {RetryHelper} from '../lib/retry-helper'
|
||||
import {RetryHelper} from '../src/retry-helper'
|
||||
|
||||
let info: string[]
|
||||
let retryHelper: any
|
||||
|
||||
51
__test__/verify-worktree.sh
Executable file
51
__test__/verify-worktree.sh
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Verify worktree credentials
|
||||
# This test verifies that git credentials work in worktrees created after checkout
|
||||
# Usage: verify-worktree.sh <checkout-path> <worktree-name>
|
||||
|
||||
CHECKOUT_PATH="$1"
|
||||
WORKTREE_NAME="$2"
|
||||
|
||||
if [ -z "$CHECKOUT_PATH" ] || [ -z "$WORKTREE_NAME" ]; then
|
||||
echo "Usage: verify-worktree.sh <checkout-path> <worktree-name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$CHECKOUT_PATH"
|
||||
|
||||
# Add safe directory for container environments
|
||||
git config --global --add safe.directory "*" 2>/dev/null || true
|
||||
|
||||
# Show the includeIf configuration
|
||||
echo "Git config includeIf entries:"
|
||||
git config --list --show-origin | grep -i include || true
|
||||
|
||||
# Create the worktree
|
||||
echo "Creating worktree..."
|
||||
git worktree add "../$WORKTREE_NAME" HEAD --detach
|
||||
|
||||
# Change to worktree directory
|
||||
cd "../$WORKTREE_NAME"
|
||||
|
||||
# Verify we're in a worktree
|
||||
echo "Verifying worktree gitdir:"
|
||||
cat .git
|
||||
|
||||
# Verify credentials are available in worktree by checking extraheader is configured
|
||||
echo "Checking credentials in worktree..."
|
||||
if git config --list --show-origin | grep -q "extraheader"; then
|
||||
echo "Credentials are configured in worktree"
|
||||
else
|
||||
echo "ERROR: Credentials are NOT configured in worktree"
|
||||
echo "Full git config:"
|
||||
git config --list --show-origin
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify fetch works in the worktree
|
||||
echo "Fetching in worktree..."
|
||||
git fetch origin
|
||||
|
||||
echo "Worktree credentials test passed!"
|
||||
@ -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
|
||||
|
||||
27
dist/index.js
vendored
27
dist/index.js
vendored
@ -412,6 +412,9 @@ class GitAuthHelper {
|
||||
// Configure host includeIf
|
||||
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`;
|
||||
yield this.git.config(hostIncludeKey, credentialsConfigPath);
|
||||
// Configure host includeIf for worktrees
|
||||
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`;
|
||||
yield this.git.config(hostWorktreeIncludeKey, credentialsConfigPath);
|
||||
// Container git directory
|
||||
const workingDirectory = this.git.getWorkingDirectory();
|
||||
const githubWorkspace = process.env['GITHUB_WORKSPACE'];
|
||||
@ -424,6 +427,9 @@ class GitAuthHelper {
|
||||
// Configure container includeIf
|
||||
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`;
|
||||
yield this.git.config(containerIncludeKey, containerCredentialsPath);
|
||||
// Configure container includeIf for worktrees
|
||||
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`;
|
||||
yield this.git.config(containerWorktreeIncludeKey, containerCredentialsPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1593,6 +1599,15 @@ function getSource(settings) {
|
||||
core.setOutput('commit', commitSHA.trim());
|
||||
// Check for incorrect pull request merge commit
|
||||
yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.githubServerUrl);
|
||||
if (settings.gitUser) {
|
||||
if (!(yield git.configExists('user.name', true))) {
|
||||
yield git.config('user.name', settings.gitUser, true);
|
||||
}
|
||||
if (!(yield git.configExists('user.email', true))) {
|
||||
const userId = yield githubApiHelper.getUserId(settings.gitUser, settings.authToken, settings.githubServerUrl);
|
||||
yield git.config('user.email', `${userId}+${settings.gitUser}@users.noreply.github.com`, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// Remove auth
|
||||
@ -1782,6 +1797,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.downloadRepository = downloadRepository;
|
||||
exports.getDefaultBranch = getDefaultBranch;
|
||||
exports.getUserId = getUserId;
|
||||
const assert = __importStar(__nccwpck_require__(9491));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
@ -1899,6 +1915,15 @@ function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
|
||||
return Buffer.from(response.data); // response.data is ArrayBuffer
|
||||
});
|
||||
}
|
||||
function getUserId(username, authToken, baseUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
|
||||
});
|
||||
const user = yield octokit.rest.users.getByUsername({ username, });
|
||||
return user.data.id;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
@ -2049,6 +2074,8 @@ function getInputs() {
|
||||
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
||||
// 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');
|
||||
|
||||
@ -374,6 +374,10 @@ class GitAuthHelper {
|
||||
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`
|
||||
await this.git.config(hostIncludeKey, credentialsConfigPath)
|
||||
|
||||
// Configure host includeIf for worktrees
|
||||
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`
|
||||
await this.git.config(hostWorktreeIncludeKey, credentialsConfigPath)
|
||||
|
||||
// Container git directory
|
||||
const workingDirectory = this.git.getWorkingDirectory()
|
||||
const githubWorkspace = process.env['GITHUB_WORKSPACE']
|
||||
@ -395,6 +399,13 @@ class GitAuthHelper {
|
||||
// Configure container includeIf
|
||||
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`
|
||||
await this.git.config(containerIncludeKey, containerCredentialsPath)
|
||||
|
||||
// Configure container includeIf for worktrees
|
||||
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`
|
||||
await this.git.config(
|
||||
containerWorktreeIncludeKey,
|
||||
containerCredentialsPath
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -274,6 +274,23 @@ 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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user