mirror of
https://github.com/webfactory/ssh-agent.git
synced 2025-06-28 05:33:45 +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
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…
Add table
Add a link
Reference in a new issue