1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2024-11-23 01:44:51 +01:00

Add SSH user parameter (#1685)

* Add a configurable SSH user

* Update docs with param

* Indentation of readme

* formatting woes

* Update src/url-helper.ts

Co-authored-by: Josh Gross <joshmgross@github.com>

* Update action.yml

Co-authored-by: Josh Gross <joshmgross@github.com>

* Update genfiles

---------

Co-authored-by: Josh Gross <joshmgross@github.com>
This commit is contained in:
Cory Miller 2024-04-18 15:29:55 -04:00 committed by GitHub
parent cd7d8d697e
commit 1d96c772d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 21 additions and 2 deletions

View file

@ -62,6 +62,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# Default: true # Default: true
ssh-strict: '' ssh-strict: ''
# The user to use when connecting to the remote SSH host. By default 'git' is
# used.
# Default: git
ssh-user: ''
# Whether to configure the token or SSH key with the local git config # Whether to configure the token or SSH key with the local git config
# Default: true # Default: true
persist-credentials: '' persist-credentials: ''

View file

@ -821,6 +821,7 @@ async function setup(testName: string): Promise<void> {
sshKey: sshPath ? 'some ssh private key' : '', sshKey: sshPath ? 'some ssh private key' : '',
sshKnownHosts: '', sshKnownHosts: '',
sshStrict: true, sshStrict: true,
sshUser: '',
workflowOrganizationId: 123456, workflowOrganizationId: 123456,
setSafeDirectory: true, setSafeDirectory: true,
githubServerUrl: githubServerUrl githubServerUrl: githubServerUrl

View file

@ -45,6 +45,10 @@ inputs:
and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
configure additional hosts. configure additional hosts.
default: true default: true
ssh-user:
description: >
The user to use when connecting to the remote SSH host. By default 'git' is used.
default: git
persist-credentials: persist-credentials:
description: 'Whether to configure the token or SSH key with the local git config' description: 'Whether to configure the token or SSH key with the local git config'
default: true default: true

4
dist/index.js vendored
View file

@ -1798,6 +1798,7 @@ function getInputs() {
result.sshKnownHosts = core.getInput('ssh-known-hosts'); result.sshKnownHosts = core.getInput('ssh-known-hosts');
result.sshStrict = result.sshStrict =
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'; (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE';
result.sshUser = core.getInput('ssh-user');
// Persist credentials // Persist credentials
result.persistCredentials = result.persistCredentials =
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'; (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
@ -2400,7 +2401,8 @@ function getFetchUrl(settings) {
const encodedOwner = encodeURIComponent(settings.repositoryOwner); const encodedOwner = encodeURIComponent(settings.repositoryOwner);
const encodedName = encodeURIComponent(settings.repositoryName); const encodedName = encodeURIComponent(settings.repositoryName);
if (settings.sshKey) { if (settings.sshKey) {
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`; const user = settings.sshUser.length > 0 ? settings.sshUser : 'git';
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
} }
// "origin" is SCHEME://HOSTNAME[:PORT] // "origin" is SCHEME://HOSTNAME[:PORT]
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`; return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;

View file

@ -94,6 +94,11 @@ export interface IGitSourceSettings {
*/ */
sshStrict: boolean sshStrict: boolean
/**
* The SSH user to login as
*/
sshUser: string
/** /**
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands * Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
*/ */

View file

@ -143,6 +143,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.sshKnownHosts = core.getInput('ssh-known-hosts') result.sshKnownHosts = core.getInput('ssh-known-hosts')
result.sshStrict = result.sshStrict =
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE' (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'
result.sshUser = core.getInput('ssh-user')
// Persist credentials // Persist credentials
result.persistCredentials = result.persistCredentials =

View file

@ -12,7 +12,8 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
const encodedOwner = encodeURIComponent(settings.repositoryOwner) const encodedOwner = encodeURIComponent(settings.repositoryOwner)
const encodedName = encodeURIComponent(settings.repositoryName) const encodedName = encodeURIComponent(settings.repositoryName)
if (settings.sshKey) { if (settings.sshKey) {
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` const user = settings.sshUser.length > 0 ? settings.sshUser : 'git'
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
} }
// "origin" is SCHEME://HOSTNAME[:PORT] // "origin" is SCHEME://HOSTNAME[:PORT]