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

[BUGFIX] Provide gitPath for Windows to avoid failures on windows-2022 (GitHub-hosted runner) #137

Merged
merged 4 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions cleanup.js
@@ -1,11 +1,11 @@
const core = require('@actions/core');
const { execFileSync } = require('child_process');
const { sshAgent } = require('./paths.js');
const { sshAgentPath } = require('./paths.js');

try {
// Kill the started SSH agent
console.log('Stopping SSH agent');
execFileSync(sshAgent, ['-k'], { stdio: 'inherit' });
execFileSync(sshAgentPath, ['-k'], { stdio: 'inherit' });
} catch (error) {
console.log(error.message);
console.log('Error stopping the SSH agent, proceeding anyway');
Expand Down
19 changes: 10 additions & 9 deletions dist/cleanup.js
Expand Up @@ -599,12 +599,12 @@ exports.debug = debug; // for test

const core = __webpack_require__(470);
const { execFileSync } = __webpack_require__(129);
const { sshAgent } = __webpack_require__(972);
const { sshAgentPath } = __webpack_require__(972);

try {
// Kill the started SSH agent
console.log('Stopping SSH agent');
execFileSync(sshAgent, ['-k'], { stdio: 'inherit' });
execFileSync(sshAgentPath, ['-k'], { stdio: 'inherit' });
} catch (error) {
console.log(error.message);
console.log('Error stopping the SSH agent, proceeding anyway');
Expand Down Expand Up @@ -2827,16 +2827,17 @@ 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
home: os.userInfo().homedir,
sshAgent: 'ssh-agent',
sshAdd: 'ssh-add'
homePath: os.userInfo().homedir,
sshAgentPath: 'ssh-agent',
sshAddPath: 'ssh-add',
gitPath: 'git'

} : {

home: os.homedir(),
sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe'

homePath: os.homedir(),
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitPath: 'c://progra~1//git//usr//bin//git.exe'
Copy link
Member

@mpdude mpdude Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ochococo Now that I take a step back, what would you think about having homePath, but sshAgentCmd (or ...Command) and the same for other items that refer to binaries?

I can make the change for you if you agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would then argue this is not a command but rather a path to command (or executable if you will).
Bike-shedding obviously, not a strong objection from me, UTY

};


Expand Down
33 changes: 17 additions & 16 deletions dist/index.js
Expand Up @@ -322,7 +322,7 @@ const core = __webpack_require__(470);
const child_process = __webpack_require__(129);
const fs = __webpack_require__(747);
const crypto = __webpack_require__(417);
const { home, sshAgent, sshAdd } = __webpack_require__(972);
const { homePath, sshAgentPath, sshAddPath, gitPath } = __webpack_require__(972);

try {
const privateKey = core.getInput('ssh-private-key');
Expand All @@ -333,7 +333,7 @@ try {
return;
}

const homeSsh = home + '/.ssh';
const homeSsh = homePath + '/.ssh';

console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);

Expand All @@ -348,7 +348,7 @@ try {
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];

// Extract auth socket path and agent pid and set them as job variables
child_process.execFileSync(sshAgent, sshAgentArgs).toString().split("\n").forEach(function(line) {
child_process.execFileSync(sshAgentPath, sshAgentArgs).toString().split("\n").forEach(function(line) {
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);

if (matches && matches.length > 0) {
Expand All @@ -361,16 +361,16 @@ try {
console.log("Adding private key(s) to agent");

privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
child_process.execFileSync(sshAdd, ['-'], { input: key.trim() + "\n" });
child_process.execFileSync(sshAddPath, ['-'], { input: key.trim() + "\n" });
});

console.log("Key(s) added:");

child_process.execFileSync(sshAdd, ['-l'], { stdio: 'inherit' });
child_process.execFileSync(sshAddPath, ['-l'], { stdio: 'inherit' });

console.log('Configuring deployment key(s)');

child_process.execFileSync(sshAdd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
child_process.execFileSync(sshAddPath, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);

if (!parts) {
Expand All @@ -384,9 +384,9 @@ try {

fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });

child_process.execSync(`git config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
child_process.execSync(`${gitPath} 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(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);

const sshConfig = `\nHost key-${sha256}.github.com\n`
+ ` HostName github.com\n`
Expand Down Expand Up @@ -2904,16 +2904,17 @@ 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
home: os.userInfo().homedir,
sshAgent: 'ssh-agent',
sshAdd: 'ssh-add'
homePath: os.userInfo().homedir,
sshAgentPath: 'ssh-agent',
sshAddPath: 'ssh-add',
gitPath: 'git'

} : {

home: os.homedir(),
sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe'

homePath: os.homedir(),
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitPath: 'c://progra~1//git//usr//bin//git.exe'
};


Expand Down
18 changes: 9 additions & 9 deletions index.js
Expand Up @@ -2,7 +2,7 @@ const core = require('@actions/core');
const child_process = require('child_process');
const fs = require('fs');
const crypto = require('crypto');
const { home, sshAgent, sshAdd } = require('./paths.js');
const { homePath, sshAgentPath, sshAddPath, gitPath } = require('./paths.js');

try {
const privateKey = core.getInput('ssh-private-key');
Expand All @@ -13,7 +13,7 @@ try {
return;
}

const homeSsh = home + '/.ssh';
const homeSsh = homePath + '/.ssh';

console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);

Expand All @@ -28,7 +28,7 @@ try {
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];

// Extract auth socket path and agent pid and set them as job variables
child_process.execFileSync(sshAgent, sshAgentArgs).toString().split("\n").forEach(function(line) {
child_process.execFileSync(sshAgentPath, sshAgentArgs).toString().split("\n").forEach(function(line) {
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);

if (matches && matches.length > 0) {
Expand All @@ -41,16 +41,16 @@ try {
console.log("Adding private key(s) to agent");

privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
child_process.execFileSync(sshAdd, ['-'], { input: key.trim() + "\n" });
child_process.execFileSync(sshAddPath, ['-'], { input: key.trim() + "\n" });
});

console.log("Key(s) added:");

child_process.execFileSync(sshAdd, ['-l'], { stdio: 'inherit' });
child_process.execFileSync(sshAddPath, ['-l'], { stdio: 'inherit' });

console.log('Configuring deployment key(s)');

child_process.execFileSync(sshAdd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
child_process.execFileSync(sshAddPath, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);

if (!parts) {
Expand All @@ -64,9 +64,9 @@ try {

fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });

child_process.execSync(`git config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
child_process.execSync(`${gitPath} 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(`${gitPath} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);

const sshConfig = `\nHost key-${sha256}.github.com\n`
+ ` HostName github.com\n`
Expand Down
15 changes: 8 additions & 7 deletions paths.js
Expand Up @@ -4,15 +4,16 @@ 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
home: os.userInfo().homedir,
sshAgent: 'ssh-agent',
sshAdd: 'ssh-add'
homePath: os.userInfo().homedir,
sshAgentPath: 'ssh-agent',
sshAddPath: 'ssh-add',
gitPath: 'git'

} : {

home: os.homedir(),
sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe'

homePath: os.homedir(),
sshAgentPath: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAddPath: 'c://progra~1//git//usr//bin//ssh-add.exe',
gitPath: 'c://progra~1//git//usr//bin//git.exe'
};