Skip to content

Commit 6f828cc

Browse files
authored
Allow the user to override the commands for git, ssh-agent, and ssh-add (#154)
On my self-hosted Windows runners, the `git`, `ssh-agent`, and `ssh-add` commands are not located in the locations that are currently hard-coded in `paths.js`. With this PR, I am able to get this action to work on my runners as follows: ```yaml - uses: webfactory/ssh-agent@... with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} git-cmd: git ssh-agent-cmd: ssh-agent ssh-add-cmd: ssh-add ```
1 parent 209e2d7 commit 6f828cc

File tree

6 files changed

+48
-20
lines changed

6 files changed

+48
-20
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ The following inputs can be used to control the action's behavior:
8282
* `ssh-private-key`: Required. Use this to provide the key(s) to load as GitHub Actions secrets.
8383
* `ssh-auth-sock`: Can be used to control where the SSH agent socket will be placed. Ultimately affects the `$SSH_AUTH_SOCK` environment variable.
8484
* `log-public-key`: Set this to `false` if you want to suppress logging of _public_ key information. To simplify debugging and since it contains public key information only, this is turned on by default.
85+
* `ssh-agent-cmd`: Optional. Use this to specify a custom location for the `ssh-agent` binary.
86+
* `ssh-add-cmd`: Optional. Use this to specify a custom location for the `ssh-add` binary.
87+
* `git-cmd`: Optional. Use this to specify a custom location for the `git` binary.
8588

8689
## Exported variables
8790

action.yml

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ inputs:
1010
description: 'Whether or not to log public key fingerprints'
1111
required: false
1212
default: true
13+
ssh-agent-cmd:
14+
description: 'ssh-agent command'
15+
required: false
16+
ssh-add-cmd:
17+
description: 'ssh-add command'
18+
required: false
19+
git-cmd:
20+
description: 'git command'
21+
required: false
1322
runs:
1423
using: 'node16'
1524
main: 'dist/index.js'

dist/cleanup.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2827,15 +2827,15 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
28272827
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
28282828
// Action runs, where $HOME is different from the pwent
28292829
homePath: os.userInfo().homedir,
2830-
sshAgentCmd: 'ssh-agent',
2831-
sshAddCmd: 'ssh-add',
2832-
gitCmd: 'git'
2830+
sshAgentCmdDefault: 'ssh-agent',
2831+
sshAddCmdDefault: 'ssh-add',
2832+
gitCmdDefault: 'git'
28332833
} : {
28342834
// Assuming GitHub hosted `windows-*` runners for now
28352835
homePath: os.homedir(),
2836-
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
2837-
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
2838-
gitCmd: 'c://progra~1//git//bin//git.exe'
2836+
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
2837+
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
2838+
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
28392839
};
28402840

28412841

dist/index.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,20 @@ const core = __webpack_require__(470);
322322
const child_process = __webpack_require__(129);
323323
const fs = __webpack_require__(747);
324324
const crypto = __webpack_require__(417);
325-
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = __webpack_require__(972);
325+
const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = __webpack_require__(972);
326326

327327
try {
328328
const privateKey = core.getInput('ssh-private-key');
329329
const logPublicKey = core.getBooleanInput('log-public-key', {default: true});
330330

331+
const sshAgentCmdInput = core.getInput('ssh-agent-cmd');
332+
const sshAddCmdInput = core.getInput('ssh-add-cmd');
333+
const gitCmdInput = core.getInput('git-cmd');
334+
335+
const sshAgentCmd = sshAgentCmdInput ? sshAgentCmdInput : sshAgentCmdDefault
336+
const sshAddCmd = sshAddCmdInput ? sshAddCmdInput : sshAddCmdDefault
337+
const gitCmd = gitCmdInput ? gitCmdInput : gitCmdDefault
338+
331339
if (!privateKey) {
332340
core.setFailed("The ssh-private-key argument is empty. Maybe the secret has not been configured, or you are using a wrong secret name in your workflow file.");
333341

@@ -2906,15 +2914,15 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
29062914
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
29072915
// Action runs, where $HOME is different from the pwent
29082916
homePath: os.userInfo().homedir,
2909-
sshAgentCmd: 'ssh-agent',
2910-
sshAddCmd: 'ssh-add',
2911-
gitCmd: 'git'
2917+
sshAgentCmdDefault: 'ssh-agent',
2918+
sshAddCmdDefault: 'ssh-add',
2919+
gitCmdDefault: 'git'
29122920
} : {
29132921
// Assuming GitHub hosted `windows-*` runners for now
29142922
homePath: os.homedir(),
2915-
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
2916-
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
2917-
gitCmd: 'c://progra~1//git//bin//git.exe'
2923+
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
2924+
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
2925+
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
29182926
};
29192927

29202928

index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ const core = require('@actions/core');
22
const child_process = require('child_process');
33
const fs = require('fs');
44
const crypto = require('crypto');
5-
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = require('./paths.js');
5+
const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = require('./paths.js');
66

77
try {
88
const privateKey = core.getInput('ssh-private-key');
99
const logPublicKey = core.getBooleanInput('log-public-key', {default: true});
1010

11+
const sshAgentCmdInput = core.getInput('ssh-agent-cmd');
12+
const sshAddCmdInput = core.getInput('ssh-add-cmd');
13+
const gitCmdInput = core.getInput('git-cmd');
14+
15+
const sshAgentCmd = sshAgentCmdInput ? sshAgentCmdInput : sshAgentCmdDefault;
16+
const sshAddCmd = sshAddCmdInput ? sshAddCmdInput : sshAddCmdDefault;
17+
const gitCmd = gitCmdInput ? gitCmdInput : gitCmdDefault;
18+
1119
if (!privateKey) {
1220
core.setFailed("The ssh-private-key argument is empty. Maybe the secret has not been configured, or you are using a wrong secret name in your workflow file.");
1321

paths.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
44
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
55
// Action runs, where $HOME is different from the pwent
66
homePath: os.userInfo().homedir,
7-
sshAgentCmd: 'ssh-agent',
8-
sshAddCmd: 'ssh-add',
9-
gitCmd: 'git'
7+
sshAgentCmdDefault: 'ssh-agent',
8+
sshAddCmdDefault: 'ssh-add',
9+
gitCmdDefault: 'git'
1010
} : {
1111
// Assuming GitHub hosted `windows-*` runners for now
1212
homePath: os.homedir(),
13-
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
14-
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
15-
gitCmd: 'c://progra~1//git//bin//git.exe'
13+
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
14+
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
15+
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
1616
};

0 commit comments

Comments
 (0)