mirror of
https://github.com/webfactory/ssh-agent.git
synced 2024-12-25 16:29:36 +00:00
Exit with a helpful error message when the secret has not been configured
This commit is contained in:
parent
6cf6299d23
commit
c6eb7ee1d8
3 changed files with 26 additions and 2 deletions
|
@ -12,3 +12,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
* Multiple SSH keys can now be provided (#14, closes #7). Thanks to
|
||||
@webknjaz and @bradmartin for support and tests.
|
||||
|
||||
* Catch empty ssh-private-key input values and exit with a helpful
|
||||
error message right away.
|
||||
|
|
13
dist/index.js
vendored
13
dist/index.js
vendored
|
@ -58,9 +58,18 @@ const child_process = __webpack_require__(129);
|
|||
const fs = __webpack_require__(747);
|
||||
|
||||
try {
|
||||
|
||||
const home = process.env['HOME'];
|
||||
const homeSsh = home + '/.ssh';
|
||||
|
||||
const privateKey = core.getInput('ssh-private-key').trim();
|
||||
|
||||
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.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
|
||||
fs.mkdirSync(homeSsh, { recursive: true});
|
||||
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n');
|
||||
|
@ -72,11 +81,13 @@ try {
|
|||
core.exportVariable('SSH_AUTH_SOCK', authSock);
|
||||
|
||||
console.log("Adding private key to agent");
|
||||
core.getInput('ssh-private-key').split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||
child_process.execSync('ssh-add -', { input: key.trim() + "\n" });
|
||||
});
|
||||
|
||||
console.log("Keys added:");
|
||||
child_process.execSync('ssh-add -l', { stdio: 'inherit' });
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
13
index.js
13
index.js
|
@ -3,9 +3,18 @@ const child_process = require('child_process');
|
|||
const fs = require('fs');
|
||||
|
||||
try {
|
||||
|
||||
const home = process.env['HOME'];
|
||||
const homeSsh = home + '/.ssh';
|
||||
|
||||
const privateKey = core.getInput('ssh-private-key').trim();
|
||||
|
||||
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.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
|
||||
fs.mkdirSync(homeSsh, { recursive: true});
|
||||
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n');
|
||||
|
@ -17,11 +26,13 @@ try {
|
|||
core.exportVariable('SSH_AUTH_SOCK', authSock);
|
||||
|
||||
console.log("Adding private key to agent");
|
||||
core.getInput('ssh-private-key').split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||
child_process.execSync('ssh-add -', { input: key.trim() + "\n" });
|
||||
});
|
||||
|
||||
console.log("Keys added:");
|
||||
child_process.execSync('ssh-add -l', { stdio: 'inherit' });
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue