mirror of
https://github.com/actions/checkout.git
synced 2025-06-08 18:42:39 +08:00
Compare commits
12 Commits
b130e474f1
...
46a5d5630d
Author | SHA1 | Date | |
---|---|---|---|
|
46a5d5630d | ||
|
11bd71901b | ||
|
e3d2460bbb | ||
|
0865c4bfce | ||
|
1be0f9404c | ||
|
a52fa92dc9 | ||
|
491fae084d | ||
|
3a6c8fb5e6 | ||
|
267ca9cee1 | ||
|
8a241b5b4d | ||
|
67b5caa109 | ||
|
650ceb06a8 |
@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## v4.2.2
|
||||
* `url-helper.ts` now leverages well-known environment variables by @jww3 in https://github.com/actions/checkout/pull/1941
|
||||
* Expand unit test coverage for `isGhes` by @jww3 in https://github.com/actions/checkout/pull/1946
|
||||
|
||||
## v4.2.1
|
||||
* Check out other refs/* by commit if provided, fall back to ref by @orhantoy in https://github.com/actions/checkout/pull/1924
|
||||
|
||||
|
@ -29,6 +29,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
# Otherwise, uses the default branch.
|
||||
ref: ''
|
||||
|
||||
# The commit SHA to checkout. Used when ref is not specified or is ambiguous. This
|
||||
# can be used as a replacement for ref, or alongside it to checkout a specific
|
||||
# commit of the ref.
|
||||
commit: ''
|
||||
|
||||
# Personal access token (PAT) used to fetch the repository. The PAT is configured
|
||||
# with the local git config, which enables your scripts to run authenticated git
|
||||
# commands. The post-job step removes the PAT.
|
||||
|
@ -144,4 +144,30 @@ describe('input-helper tests', () => {
|
||||
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||
expect(settings.workflowOrganizationId).toBe(123456)
|
||||
})
|
||||
|
||||
it('accepts ref and commit', async () => {
|
||||
inputs.ref = 'refs/pull/123/merge'
|
||||
inputs.commit = '0123456789012345678901234567890123456789'
|
||||
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||
expect(settings).toBeTruthy()
|
||||
expect(settings.ref).toBeTruthy()
|
||||
expect(settings.ref).toStrictEqual('refs/pull/123/merge')
|
||||
expect(settings.commit).toBeTruthy()
|
||||
expect(settings.commit).toStrictEqual(
|
||||
'0123456789012345678901234567890123456789'
|
||||
)
|
||||
})
|
||||
|
||||
it('ref fallbacks to commit if ref is empty but commit is specified', async () => {
|
||||
inputs.ref = ''
|
||||
inputs.commit = '0123456789012345678901234567890123456789'
|
||||
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||
expect(settings).toBeTruthy()
|
||||
expect(settings.ref).toBeFalsy()
|
||||
expect(settings.ref).toStrictEqual('')
|
||||
expect(settings.commit).toBeTruthy()
|
||||
expect(settings.commit).toStrictEqual(
|
||||
'0123456789012345678901234567890123456789'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -24,13 +24,50 @@ describe('getServerUrl tests', () => {
|
||||
})
|
||||
|
||||
describe('isGhes tests', () => {
|
||||
const pristineEnv = process.env
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules()
|
||||
process.env = {...pristineEnv}
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
process.env = pristineEnv
|
||||
})
|
||||
|
||||
it('basics', async () => {
|
||||
delete process.env['GITHUB_SERVER_URL']
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
expect(urlHelper.isGhes('https://github.com')).toBeFalsy()
|
||||
expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy()
|
||||
expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy()
|
||||
expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => {
|
||||
delete process.env['GITHUB_SERVER_URL']
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com'
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com'
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost'
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com'
|
||||
expect(urlHelper.isGhes()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getServerApiUrl tests', () => {
|
||||
|
@ -9,6 +9,11 @@ inputs:
|
||||
The branch, tag or SHA to checkout. When checking out the repository that
|
||||
triggered a workflow, this defaults to the reference or SHA for that
|
||||
event. Otherwise, uses the default branch.
|
||||
commit:
|
||||
description: >
|
||||
The commit SHA to checkout. Used when ref is not specified or is ambiguous.
|
||||
This can be used as a replacement for ref, or alongside it to checkout a
|
||||
specific commit of the ref.
|
||||
token:
|
||||
description: >
|
||||
Personal access token (PAT) used to fetch the repository. The PAT is configured
|
||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -1744,7 +1744,11 @@ function getInputs() {
|
||||
const isWorkflowRepository = qualifiedRepository.toUpperCase() ===
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase();
|
||||
// Source branch, source version
|
||||
result.ref = core.getInput('ref');
|
||||
result.commit = core.getInput('commit');
|
||||
if (result.commit && !result.commit.match(/^[0-9a-fA-F]{40}$/)) {
|
||||
throw new Error(`The commit SHA '${result.commit}' is not a valid SHA.`);
|
||||
}
|
||||
result.ref = core.getInput('ref') || result.commit;
|
||||
if (!result.ref) {
|
||||
if (isWorkflowRepository) {
|
||||
result.ref = github.context.ref;
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "checkout",
|
||||
"version": "4.2.1",
|
||||
"version": "4.2.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "checkout",
|
||||
"version": "4.2.1",
|
||||
"version": "4.2.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "checkout",
|
||||
"version": "4.2.1",
|
||||
"version": "4.2.2",
|
||||
"description": "checkout action",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
|
@ -57,7 +57,12 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase()
|
||||
|
||||
// Source branch, source version
|
||||
result.ref = core.getInput('ref')
|
||||
result.commit = core.getInput('commit')
|
||||
if (result.commit && !result.commit.match(/^[0-9a-fA-F]{40}$/)) {
|
||||
throw new Error(`The commit SHA '${result.commit}' is not a valid SHA.`)
|
||||
}
|
||||
|
||||
result.ref = core.getInput('ref') || result.commit
|
||||
if (!result.ref) {
|
||||
if (isWorkflowRepository) {
|
||||
result.ref = github.context.ref
|
||||
|
Loading…
x
Reference in New Issue
Block a user