0
1
Fork 0

Compare commits

...

9 Commits

Author SHA1 Message Date
Marco Accorinti 4cd8c93553
Merge branch 'actions:main' into feature/customizable-working-dir 2023-12-18 18:14:02 +01:00
Marco Accorinti 9335342b9e Merge branch 'main' into feature/customizable-working-dir 2023-09-23 19:47:14 +02:00
Marco Accorinti 53a4183dea change: remove path.sep, add unit tests, dist
Remove path.sep during comparison with repositoryPath
(did not take in account root folders)
Updated and added more unit tests
Updated dist/index.js
2023-09-20 21:02:10 +02:00
Marco Accorinti faa95350fe update: README.md with new options, descriptions 2023-09-20 21:00:50 +02:00
Marco Accorinti b9dc833d47 remove(git-source-settings.ts): workingDirectory option
Not needed (working-directory option is used internally)
2023-09-20 21:00:03 +02:00
Marco Accorinti ed925880d3 fix(action.yml): path description
Add working-directory
2023-09-20 20:59:18 +02:00
Marco Accorinti a0ec92ce0c fix input name (workingDirectory -> working-directory) 2023-09-19 18:35:24 +02:00
Marco Accorinti c51e56cd7a update: action.yml
Add working-directory input parameter
2023-09-19 18:30:16 +02:00
Marco Accorinti a66a86e636 Add workingDirectory option
Let user override $GITHUB_WORKSPACE as default working directory

Defaults to undefined, the original behaviour is maintained
2023-09-17 20:45:12 +02:00
6 changed files with 1348 additions and 1320 deletions

View File

@ -66,7 +66,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# Default: true
persist-credentials: ''
# Relative path under $GITHUB_WORKSPACE to place the repository
# Relative path under $GITHUB_WORKSPACE/working-directory to place the repository
path: ''
# Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching
@ -121,6 +121,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# running from unless specified. Example URLs are https://github.com or
# https://my-ghes-server.example.com
github-server-url: ''
# Provide the working directory for the git commands to execute into, defaults to
# $GITHUB_WORKSPACE
working-directory: ''
```
<!-- end usage -->

View File

@ -821,7 +821,7 @@ async function setup(testName: string): Promise<void> {
sshStrict: true,
workflowOrganizationId: 123456,
setSafeDirectory: true,
githubServerUrl: githubServerUrl
githubServerUrl: githubServerUrl,
}
}

View File

@ -144,4 +144,25 @@ describe('input-helper tests', () => {
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.workflowOrganizationId).toBe(123456)
})
it('sets a different working directory', async() => {
inputs['working-directory'] = '/home/user/test'
inputs['path'] = 'path/to/repo'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/home/user/test/path/to/repo'))
})
it('sets a working directory on root', async() => {
inputs['working-directory'] = '/'
inputs['path'] = 'path/to/repo'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/path/to/repo'))
})
it('sets a working directory on root and repository path is set to empty', async() => {
inputs['working-directory'] = '/'
inputs['path'] = ''
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/'))
})
})

View File

@ -49,7 +49,7 @@ inputs:
description: 'Whether to configure the token or SSH key with the local git config'
default: true
path:
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
description: 'Relative path under $GITHUB_WORKSPACE/working-directory to place the repository'
clean:
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
default: true
@ -94,6 +94,9 @@ 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
working-directory:
description: Provide the working directory for the git commands to execute into, defaults to $GITHUB_WORKSPACE
required: false
runs:
using: node20
main: dist/index.js

2614
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -8,14 +8,14 @@ import {IGitSourceSettings} from './git-source-settings'
export async function getInputs(): Promise<IGitSourceSettings> {
const result = ({} as unknown) as IGitSourceSettings
// GitHub workspace
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
if (!githubWorkspacePath) {
throw new Error('GITHUB_WORKSPACE not defined')
// Working directory
let workingDirectory = core.getInput('working-directory') || process.env['GITHUB_WORKSPACE']
if (!workingDirectory) {
throw new Error('working dir not defined')
}
githubWorkspacePath = path.resolve(githubWorkspacePath)
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
fsHelper.directoryExistsSync(githubWorkspacePath, true)
workingDirectory = path.resolve(workingDirectory)
core.debug(`working directory = '${workingDirectory}'`)
fsHelper.directoryExistsSync(workingDirectory, true)
// Qualified repository
const qualifiedRepository =
@ -38,16 +38,16 @@ export async function getInputs(): Promise<IGitSourceSettings> {
// Repository path
result.repositoryPath = core.getInput('path') || '.'
result.repositoryPath = path.resolve(
githubWorkspacePath,
workingDirectory,
result.repositoryPath
)
if (
!(result.repositoryPath + path.sep).startsWith(
githubWorkspacePath + path.sep
workingDirectory
)
) {
throw new Error(
`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`
`Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'`
)
}