Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to override the commands for git, ssh-agent, and ssh-add #154

Merged
merged 4 commits into from Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -82,6 +82,9 @@ The following inputs can be used to control the action's behavior:
* `ssh-private-key`: Required. Use this to provide the key(s) to load as GitHub Actions secrets.
* `ssh-auth-sock`: Can be used to control where the SSH agent socket will be placed. Ultimately affects the `$SSH_AUTH_SOCK` environment variable.
* `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.
* `ssh-agent-cmd`: Optional. Use this to specify a custom location for the `ssh-agent` binary.
* `ssh-add-cmd`: Optional. Use this to specify a custom location for the `ssh-add` binary.
* `git-cmd`: Optional. Use this to specify a custom location for the `git` binary.

## Exported variables

Expand Down
9 changes: 9 additions & 0 deletions action.yml
Expand Up @@ -10,6 +10,15 @@ inputs:
description: 'Whether or not to log public key fingerprints'
required: false
default: true
ssh-agent-cmd:
description: 'ssh-agent command'
required: false
ssh-add-cmd:
description: 'ssh-add command'
required: false
git-cmd:
description: 'git command'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
12 changes: 6 additions & 6 deletions dist/cleanup.js
Expand Up @@ -2827,15 +2827,15 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
// Action runs, where $HOME is different from the pwent
homePath: os.userInfo().homedir,
sshAgentCmd: 'ssh-agent',
sshAddCmd: 'ssh-add',
gitCmd: 'git'
sshAgentCmdDefault: 'ssh-agent',
sshAddCmdDefault: 'ssh-add',
gitCmdDefault: 'git'
} : {
// Assuming GitHub hosted `windows-*` runners for now
homePath: os.homedir(),
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmd: 'c://progra~1//git//bin//git.exe'
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
};


Expand Down
22 changes: 15 additions & 7 deletions dist/index.js
Expand Up @@ -322,12 +322,20 @@ const core = __webpack_require__(470);
const child_process = __webpack_require__(129);
const fs = __webpack_require__(747);
const crypto = __webpack_require__(417);
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = __webpack_require__(972);
const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = __webpack_require__(972);

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

const sshAgentCmdInput = core.getInput('ssh-agent-cmd');
const sshAddCmdInput = core.getInput('ssh-add-cmd');
const gitCmdInput = core.getInput('git-cmd');

const sshAgentCmd = sshAgentCmdInput ? sshAgentCmdInput : sshAgentCmdDefault
const sshAddCmd = sshAddCmdInput ? sshAddCmdInput : sshAddCmdDefault
const gitCmd = gitCmdInput ? gitCmdInput : gitCmdDefault

if (!privateKey) {
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.");

Expand Down Expand Up @@ -2906,15 +2914,15 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
// Action runs, where $HOME is different from the pwent
homePath: os.userInfo().homedir,
sshAgentCmd: 'ssh-agent',
sshAddCmd: 'ssh-add',
gitCmd: 'git'
sshAgentCmdDefault: 'ssh-agent',
sshAddCmdDefault: 'ssh-add',
gitCmdDefault: 'git'
} : {
// Assuming GitHub hosted `windows-*` runners for now
homePath: os.homedir(),
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmd: 'c://progra~1//git//bin//git.exe'
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
};


Expand Down
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -2,12 +2,20 @@ const core = require('@actions/core');
const child_process = require('child_process');
const fs = require('fs');
const crypto = require('crypto');
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = require('./paths.js');
const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = require('./paths.js');

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

const sshAgentCmdInput = core.getInput('ssh-agent-cmd');
const sshAddCmdInput = core.getInput('ssh-add-cmd');
const gitCmdInput = core.getInput('git-cmd');

const sshAgentCmd = sshAgentCmdInput ? sshAgentCmdInput : sshAgentCmdDefault;
const sshAddCmd = sshAddCmdInput ? sshAddCmdInput : sshAddCmdDefault;
const gitCmd = gitCmdInput ? gitCmdInput : gitCmdDefault;

if (!privateKey) {
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.");

Expand Down
12 changes: 6 additions & 6 deletions paths.js
Expand Up @@ -4,13 +4,13 @@ module.exports = (process.env['OS'] != 'Windows_NT') ? {
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
// Action runs, where $HOME is different from the pwent
homePath: os.userInfo().homedir,
sshAgentCmd: 'ssh-agent',
sshAddCmd: 'ssh-add',
gitCmd: 'git'
sshAgentCmdDefault: 'ssh-agent',
sshAddCmdDefault: 'ssh-add',
gitCmdDefault: 'git'
} : {
// Assuming GitHub hosted `windows-*` runners for now
homePath: os.homedir(),
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmd: 'c://progra~1//git//bin//git.exe'
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitCmdDefault: 'c://progra~1//git//bin//git.exe'
};