mirror of
https://github.com/actions/checkout.git
synced 2024-11-14 14:08:07 +00:00
Compare commits
3 Commits
490dc54db7
...
68f18281f7
Author | SHA1 | Date | |
---|---|---|---|
|
68f18281f7 | ||
|
b684943689 | ||
|
65f77605c0 |
34
.github/workflows/test.yml
vendored
34
.github/workflows/test.yml
vendored
@ -295,3 +295,37 @@ jobs:
|
||||
uses: actions/checkout@v4.1.6
|
||||
with:
|
||||
path: localClone
|
||||
|
||||
test-output:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Clone this repo
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.6
|
||||
|
||||
# Basic checkout using git
|
||||
- name: Checkout basic
|
||||
id: checkout
|
||||
uses: ./
|
||||
with:
|
||||
ref: test-data/v2/basic
|
||||
|
||||
# Verify output
|
||||
- name: Verify output
|
||||
run: |
|
||||
echo "Commit: ${{ steps.checkout.outputs.commit }}"
|
||||
echo "Ref: ${{ steps.checkout.outputs.ref }}"
|
||||
|
||||
if [ "${{ steps.checkout.outputs.ref }}" != "test-data/v2/basic" ]; then
|
||||
echo "Expected ref to be test-data/v2/basic"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${{ steps.checkout.outputs.commit }}" != "82f71901cf8c021332310dcc8cdba84c4193ff5d" ]; then
|
||||
echo "Expected commit to be 82f71901cf8c021332310dcc8cdba84c4193ff5d"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# needed to make checkout post cleanup succeed
|
||||
- name: Fix Checkout
|
||||
uses: actions/checkout@v4.1.6
|
||||
|
@ -103,6 +103,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
# Default: true
|
||||
show-progress: ''
|
||||
|
||||
# Path to a local bare git [reference repository to minimize network
|
||||
# usage](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---reference-if-ableltrepositorygt).
|
||||
# If the directory doesn't exists this option will ignore it and log a message.
|
||||
reference: ''
|
||||
|
||||
# Whether to download Git-LFS files
|
||||
# Default: false
|
||||
lfs: ''
|
||||
|
@ -763,6 +763,7 @@ async function setup(testName: string): Promise<void> {
|
||||
lfsInstall: jest.fn(),
|
||||
log1: jest.fn(),
|
||||
remoteAdd: jest.fn(),
|
||||
referenceAdd: jest.fn(),
|
||||
removeEnvironmentVariable: jest.fn((name: string) => delete git.env[name]),
|
||||
revParse: jest.fn(),
|
||||
setEnvironmentVariable: jest.fn((name: string, value: string) => {
|
||||
@ -824,7 +825,8 @@ async function setup(testName: string): Promise<void> {
|
||||
sshUser: '',
|
||||
workflowOrganizationId: 123456,
|
||||
setSafeDirectory: true,
|
||||
githubServerUrl: githubServerUrl
|
||||
githubServerUrl: githubServerUrl,
|
||||
reference: '/some/path'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,6 +478,7 @@ async function setup(testName: string): Promise<void> {
|
||||
lfsInstall: jest.fn(),
|
||||
log1: jest.fn(),
|
||||
remoteAdd: jest.fn(),
|
||||
referenceAdd: jest.fn(),
|
||||
removeEnvironmentVariable: jest.fn(),
|
||||
revParse: jest.fn(),
|
||||
setEnvironmentVariable: jest.fn(),
|
||||
|
@ -91,6 +91,7 @@ describe('input-helper tests', () => {
|
||||
expect(settings.repositoryOwner).toBe('some-owner')
|
||||
expect(settings.repositoryPath).toBe(gitHubWorkspace)
|
||||
expect(settings.setSafeDirectory).toBe(true)
|
||||
expect(settings.reference).toBe(undefined)
|
||||
})
|
||||
|
||||
it('qualifies ref', async () => {
|
||||
|
11
action.yml
11
action.yml
@ -80,6 +80,12 @@ inputs:
|
||||
show-progress:
|
||||
description: 'Whether to show progress status output when fetching.'
|
||||
default: true
|
||||
reference:
|
||||
required: false
|
||||
description: >
|
||||
Path to a local bare git [reference repository to minimize network usage](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---reference-if-ableltrepositorygt).
|
||||
|
||||
If the directory doesn't exists this option will ignore it and log a message.
|
||||
lfs:
|
||||
description: 'Whether to download Git-LFS files'
|
||||
default: false
|
||||
@ -98,6 +104,11 @@ inputs:
|
||||
github-server-url:
|
||||
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
|
||||
required: false
|
||||
outputs:
|
||||
ref:
|
||||
description: 'The branch, tag or SHA that was checked out'
|
||||
commit:
|
||||
description: 'The commit SHA that was checked out'
|
||||
runs:
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
|
24
dist/index.js
vendored
24
dist/index.js
vendored
@ -750,6 +750,13 @@ class GitCommandManager {
|
||||
yield this.execGit(['remote', 'add', remoteName, remoteUrl]);
|
||||
});
|
||||
}
|
||||
referenceAdd(alternateObjects) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const alternatePath = path.join(this.workingDirectory, '.git/objects/info/alternates');
|
||||
core.info(`Adding a git alternate to reference repo at ${alternateObjects}`);
|
||||
yield fs.promises.writeFile(alternatePath, `${alternateObjects}\n`);
|
||||
});
|
||||
}
|
||||
removeEnvironmentVariable(name) {
|
||||
delete this.gitEnv[name];
|
||||
}
|
||||
@ -1241,6 +1248,17 @@ function getSource(settings) {
|
||||
yield git.init();
|
||||
yield git.remoteAdd('origin', repositoryUrl);
|
||||
core.endGroup();
|
||||
if (settings.reference !== undefined) {
|
||||
const alternateObjects = path.join(settings.reference, '/objects');
|
||||
if (fsHelper.directoryExistsSync(alternateObjects, false)) {
|
||||
core.startGroup('Adding a reference repository');
|
||||
yield git.referenceAdd(alternateObjects);
|
||||
core.endGroup();
|
||||
}
|
||||
else {
|
||||
core.warning(`Reference repository was specified, but directory ${alternateObjects} does not exists`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Disable automatic garbage collection
|
||||
core.startGroup('Disabling automatic garbage collection');
|
||||
@ -1355,7 +1373,8 @@ function getSource(settings) {
|
||||
// Get commit information
|
||||
const commitInfo = yield git.log1();
|
||||
// Log commit sha
|
||||
yield git.log1("--format='%H'");
|
||||
const commitSHA = yield git.log1('--format=%H');
|
||||
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);
|
||||
}
|
||||
@ -1835,6 +1854,8 @@ function getInputs() {
|
||||
// Determine the GitHub URL that the repository is being hosted from
|
||||
result.githubServerUrl = core.getInput('github-server-url');
|
||||
core.debug(`GitHub Host URL = ${result.githubServerUrl}`);
|
||||
result.reference = core.getInput('reference');
|
||||
core.debug(`Reference repository = ${result.reference}`);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@ -1897,6 +1918,7 @@ function run() {
|
||||
coreCommand.issueCommand('add-matcher', {}, path.join(__dirname, 'problem-matcher.json'));
|
||||
// Get sources
|
||||
yield gitSourceProvider.getSource(sourceSettings);
|
||||
core.setOutput('ref', sourceSettings.ref);
|
||||
}
|
||||
finally {
|
||||
// Unregister problem matcher
|
||||
|
@ -48,6 +48,7 @@ export interface IGitCommandManager {
|
||||
lfsInstall(): Promise<void>
|
||||
log1(format?: string): Promise<string>
|
||||
remoteAdd(remoteName: string, remoteUrl: string): Promise<void>
|
||||
referenceAdd(reference: string): Promise<void>
|
||||
removeEnvironmentVariable(name: string): void
|
||||
revParse(ref: string): Promise<string>
|
||||
setEnvironmentVariable(name: string, value: string): void
|
||||
@ -364,6 +365,15 @@ class GitCommandManager {
|
||||
await this.execGit(['remote', 'add', remoteName, remoteUrl])
|
||||
}
|
||||
|
||||
async referenceAdd(alternateObjects: string): Promise<void> {
|
||||
const alternatePath = path.join(
|
||||
this.workingDirectory,
|
||||
'.git/objects/info/alternates'
|
||||
)
|
||||
core.info(`Adding a git alternate to reference repo at ${alternateObjects}`)
|
||||
await fs.promises.writeFile(alternatePath, `${alternateObjects}\n`)
|
||||
}
|
||||
|
||||
removeEnvironmentVariable(name: string): void {
|
||||
delete this.gitEnv[name]
|
||||
}
|
||||
|
@ -113,6 +113,18 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||
await git.init()
|
||||
await git.remoteAdd('origin', repositoryUrl)
|
||||
core.endGroup()
|
||||
|
||||
if (settings.reference !== undefined) {
|
||||
const alternateObjects = path.join(settings.reference, '/objects')
|
||||
|
||||
if (fsHelper.directoryExistsSync(alternateObjects, false)) {
|
||||
core.startGroup('Adding a reference repository')
|
||||
await git.referenceAdd(alternateObjects)
|
||||
core.endGroup()
|
||||
} else {
|
||||
core.warning(`Reference repository was specified, but directory ${alternateObjects} does not exists`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Disable automatic garbage collection
|
||||
@ -261,7 +273,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||
const commitInfo = await git.log1()
|
||||
|
||||
// Log commit sha
|
||||
await git.log1("--format='%H'")
|
||||
const commitSHA = await git.log1('--format=%H')
|
||||
core.setOutput('commit', commitSHA.trim())
|
||||
|
||||
// Check for incorrect pull request merge commit
|
||||
await refHelper.checkCommitInfo(
|
||||
|
@ -49,6 +49,11 @@ export interface IGitSourceSettings {
|
||||
*/
|
||||
fetchDepth: number
|
||||
|
||||
/**
|
||||
* The local reference repository
|
||||
*/
|
||||
reference: string | undefined
|
||||
|
||||
/**
|
||||
* Fetch tags, even if fetchDepth > 0 (default: false)
|
||||
*/
|
||||
@ -59,6 +64,11 @@ export interface IGitSourceSettings {
|
||||
*/
|
||||
showProgress: boolean
|
||||
|
||||
/**
|
||||
* The local reference repository
|
||||
*/
|
||||
reference: string | undefined
|
||||
|
||||
/**
|
||||
* Indicates whether to fetch LFS objects
|
||||
*/
|
||||
|
@ -161,5 +161,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
result.githubServerUrl = core.getInput('github-server-url')
|
||||
core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
|
||||
|
||||
result.reference = core.getInput('reference')
|
||||
core.debug(`Reference repository = ${result.reference}`)
|
||||
|
||||
return result
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ async function run(): Promise<void> {
|
||||
|
||||
// Get sources
|
||||
await gitSourceProvider.getSource(sourceSettings)
|
||||
core.setOutput('ref', sourceSettings.ref)
|
||||
} finally {
|
||||
// Unregister problem matcher
|
||||
coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')
|
||||
|
Loading…
Reference in New Issue
Block a user