mirror of
https://github.com/webfactory/ssh-agent.git
synced 2025-04-24 06:52:13 +00:00
Improve variable names, again
This commit is contained in:
parent
2c1c285334
commit
3f34cd0ca9
5 changed files with 41 additions and 50 deletions
|
@ -1,11 +1,11 @@
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const { execFileSync } = require('child_process');
|
const { execFileSync } = require('child_process');
|
||||||
const { sshAgentPath } = require('./paths.js');
|
const { sshAgentCmd } = require('./paths.js');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Kill the started SSH agent
|
// Kill the started SSH agent
|
||||||
console.log('Stopping SSH agent');
|
console.log('Stopping SSH agent');
|
||||||
execFileSync(sshAgentPath, ['-k'], { stdio: 'inherit' });
|
execFileSync(sshAgentCmd, ['-k'], { stdio: 'inherit' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
console.log('Error stopping the SSH agent, proceeding anyway');
|
console.log('Error stopping the SSH agent, proceeding anyway');
|
||||||
|
|
21
dist/cleanup.js
vendored
21
dist/cleanup.js
vendored
|
@ -599,12 +599,12 @@ exports.debug = debug; // for test
|
||||||
|
|
||||||
const core = __webpack_require__(470);
|
const core = __webpack_require__(470);
|
||||||
const { execFileSync } = __webpack_require__(129);
|
const { execFileSync } = __webpack_require__(129);
|
||||||
const { sshAgentPath } = __webpack_require__(972);
|
const { sshAgentCmd } = __webpack_require__(972);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Kill the started SSH agent
|
// Kill the started SSH agent
|
||||||
console.log('Stopping SSH agent');
|
console.log('Stopping SSH agent');
|
||||||
execFileSync(sshAgentPath, ['-k'], { stdio: 'inherit' });
|
execFileSync(sshAgentCmd, ['-k'], { stdio: 'inherit' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
console.log('Error stopping the SSH agent, proceeding anyway');
|
console.log('Error stopping the SSH agent, proceeding anyway');
|
||||||
|
@ -2824,24 +2824,21 @@ exports.default = _default;
|
||||||
const os = __webpack_require__(87);
|
const os = __webpack_require__(87);
|
||||||
|
|
||||||
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
||||||
|
|
||||||
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
|
// 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
|
// Action runs, where $HOME is different from the pwent
|
||||||
homePath: os.userInfo().homedir,
|
homePath: os.userInfo().homedir,
|
||||||
sshAgentPath: 'ssh-agent',
|
sshAgentCmd: 'ssh-agent',
|
||||||
sshAddPath: 'ssh-add',
|
sshAddCmd: 'ssh-add',
|
||||||
gitPath: 'git'
|
gitCmd: 'git'
|
||||||
|
|
||||||
} : {
|
} : {
|
||||||
|
// Assuming GitHub hosted `windows-*` runners for now
|
||||||
homePath: os.homedir(),
|
homePath: os.homedir(),
|
||||||
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
||||||
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
||||||
gitPath: 'c://progra~1//git//usr//bin//git.exe'
|
gitCmd: 'c://progra~1//git//usr//bin//git.exe'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ })
|
/***/ })
|
||||||
|
|
||||||
/******/ });
|
/******/ });
|
33
dist/index.js
vendored
33
dist/index.js
vendored
|
@ -322,7 +322,7 @@ const core = __webpack_require__(470);
|
||||||
const child_process = __webpack_require__(129);
|
const child_process = __webpack_require__(129);
|
||||||
const fs = __webpack_require__(747);
|
const fs = __webpack_require__(747);
|
||||||
const crypto = __webpack_require__(417);
|
const crypto = __webpack_require__(417);
|
||||||
const { homePath, sshAgentPath, sshAddPath, gitPath } = __webpack_require__(972);
|
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = __webpack_require__(972);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const privateKey = core.getInput('ssh-private-key');
|
const privateKey = core.getInput('ssh-private-key');
|
||||||
|
@ -348,7 +348,7 @@ try {
|
||||||
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];
|
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];
|
||||||
|
|
||||||
// Extract auth socket path and agent pid and set them as job variables
|
// Extract auth socket path and agent pid and set them as job variables
|
||||||
child_process.execFileSync(sshAgentPath, sshAgentArgs).toString().split("\n").forEach(function(line) {
|
child_process.execFileSync(sshAgentCmd, sshAgentArgs).toString().split("\n").forEach(function(line) {
|
||||||
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
|
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
|
||||||
|
|
||||||
if (matches && matches.length > 0) {
|
if (matches && matches.length > 0) {
|
||||||
|
@ -361,16 +361,16 @@ try {
|
||||||
console.log("Adding private key(s) to agent");
|
console.log("Adding private key(s) to agent");
|
||||||
|
|
||||||
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||||
child_process.execFileSync(sshAddPath, ['-'], { input: key.trim() + "\n" });
|
child_process.execFileSync(sshAddCmd, ['-'], { input: key.trim() + "\n" });
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Key(s) added:");
|
console.log("Key(s) added:");
|
||||||
|
|
||||||
child_process.execFileSync(sshAddPath, ['-l'], { stdio: 'inherit' });
|
child_process.execFileSync(sshAddCmd, ['-l'], { stdio: 'inherit' });
|
||||||
|
|
||||||
console.log('Configuring deployment key(s)');
|
console.log('Configuring deployment key(s)');
|
||||||
|
|
||||||
child_process.execFileSync(sshAddPath, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
|
child_process.execFileSync(sshAddCmd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
|
||||||
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
||||||
|
|
||||||
if (!parts) {
|
if (!parts) {
|
||||||
|
@ -384,9 +384,9 @@ try {
|
||||||
|
|
||||||
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
||||||
|
|
||||||
child_process.execSync(`${gitPath} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
|
||||||
|
|
||||||
const sshConfig = `\nHost key-${sha256}.github.com\n`
|
const sshConfig = `\nHost key-${sha256}.github.com\n`
|
||||||
+ ` HostName github.com\n`
|
+ ` HostName github.com\n`
|
||||||
|
@ -2901,24 +2901,21 @@ exports.default = _default;
|
||||||
const os = __webpack_require__(87);
|
const os = __webpack_require__(87);
|
||||||
|
|
||||||
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
||||||
|
|
||||||
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
|
// 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
|
// Action runs, where $HOME is different from the pwent
|
||||||
homePath: os.userInfo().homedir,
|
homePath: os.userInfo().homedir,
|
||||||
sshAgentPath: 'ssh-agent',
|
sshAgentCmd: 'ssh-agent',
|
||||||
sshAddPath: 'ssh-add',
|
sshAddCmd: 'ssh-add',
|
||||||
gitPath: 'git'
|
gitCmd: 'git'
|
||||||
|
|
||||||
} : {
|
} : {
|
||||||
|
// Assuming GitHub hosted `windows-*` runners for now
|
||||||
homePath: os.homedir(),
|
homePath: os.homedir(),
|
||||||
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
||||||
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
||||||
gitPath: 'c://progra~1//git//usr//bin//git.exe'
|
gitCmd: 'c://progra~1//git//usr//bin//git.exe'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ })
|
/***/ })
|
||||||
|
|
||||||
/******/ });
|
/******/ });
|
16
index.js
16
index.js
|
@ -2,7 +2,7 @@ const core = require('@actions/core');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { homePath, sshAgentPath, sshAddPath, gitPath } = require('./paths.js');
|
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = require('./paths.js');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const privateKey = core.getInput('ssh-private-key');
|
const privateKey = core.getInput('ssh-private-key');
|
||||||
|
@ -28,7 +28,7 @@ try {
|
||||||
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];
|
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];
|
||||||
|
|
||||||
// Extract auth socket path and agent pid and set them as job variables
|
// Extract auth socket path and agent pid and set them as job variables
|
||||||
child_process.execFileSync(sshAgentPath, sshAgentArgs).toString().split("\n").forEach(function(line) {
|
child_process.execFileSync(sshAgentCmd, sshAgentArgs).toString().split("\n").forEach(function(line) {
|
||||||
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
|
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
|
||||||
|
|
||||||
if (matches && matches.length > 0) {
|
if (matches && matches.length > 0) {
|
||||||
|
@ -41,16 +41,16 @@ try {
|
||||||
console.log("Adding private key(s) to agent");
|
console.log("Adding private key(s) to agent");
|
||||||
|
|
||||||
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||||
child_process.execFileSync(sshAddPath, ['-'], { input: key.trim() + "\n" });
|
child_process.execFileSync(sshAddCmd, ['-'], { input: key.trim() + "\n" });
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Key(s) added:");
|
console.log("Key(s) added:");
|
||||||
|
|
||||||
child_process.execFileSync(sshAddPath, ['-l'], { stdio: 'inherit' });
|
child_process.execFileSync(sshAddCmd, ['-l'], { stdio: 'inherit' });
|
||||||
|
|
||||||
console.log('Configuring deployment key(s)');
|
console.log('Configuring deployment key(s)');
|
||||||
|
|
||||||
child_process.execFileSync(sshAddPath, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
|
child_process.execFileSync(sshAddCmd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
|
||||||
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
||||||
|
|
||||||
if (!parts) {
|
if (!parts) {
|
||||||
|
@ -64,9 +64,9 @@ try {
|
||||||
|
|
||||||
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
||||||
|
|
||||||
child_process.execSync(`${gitPath} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
|
||||||
|
|
||||||
const sshConfig = `\nHost key-${sha256}.github.com\n`
|
const sshConfig = `\nHost key-${sha256}.github.com\n`
|
||||||
+ ` HostName github.com\n`
|
+ ` HostName github.com\n`
|
||||||
|
|
17
paths.js
17
paths.js
|
@ -1,19 +1,16 @@
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
module.exports = (process.env['OS'] != 'Windows_NT') ? {
|
||||||
|
|
||||||
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
|
// 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
|
// Action runs, where $HOME is different from the pwent
|
||||||
homePath: os.userInfo().homedir,
|
homePath: os.userInfo().homedir,
|
||||||
sshAgentPath: 'ssh-agent',
|
sshAgentCmd: 'ssh-agent',
|
||||||
sshAddPath: 'ssh-add',
|
sshAddCmd: 'ssh-add',
|
||||||
gitPath: 'git'
|
gitCmd: 'git'
|
||||||
|
|
||||||
} : {
|
} : {
|
||||||
|
// Assuming GitHub hosted `windows-*` runners for now
|
||||||
homePath: os.homedir(),
|
homePath: os.homedir(),
|
||||||
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
sshAgentCmd: 'c://progra~1//git//usr//bin//ssh-agent.exe',
|
||||||
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
sshAddCmd: 'c://progra~1//git//usr//bin//ssh-add.exe',
|
||||||
gitPath: 'c://progra~1//git//usr//bin//git.exe'
|
gitCmd: 'c://progra~1//git//usr//bin//git.exe'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue