diff --git a/dist/index.js b/dist/index.js index 3f288c7..047ca93 100644 --- a/dist/index.js +++ b/dist/index.js @@ -366,7 +366,7 @@ try { console.log('Configuring deployment key(s)'); child_process.execFileSync(sshAddCmd, ['-L']).toString().trim().split(/\r?\n/).forEach(function(key) { - const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i); + const parts = key.match(/\b([\w.]+)[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)$/i); if (!parts) { if (logPublicKey) { @@ -376,16 +376,17 @@ try { } const sha256 = crypto.createHash('sha256').update(key).digest('hex'); - const ownerAndRepo = parts[1].replace(/\.git$/, ''); + const githubHost = parts[1]; + const ownerAndRepo = parts[2].replace(/\.git$/, ''); fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' }); - child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://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(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "https://${githubHost}/${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "git@${githubHost}:${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "ssh://git@${githubHost}/${ownerAndRepo}"`); - const sshConfig = `\nHost key-${sha256}.github.com\n` - + ` HostName github.com\n` + const sshConfig = `\nHost key-${sha256}.${githubHost}\n` + + ` HostName ${githubHost}\n` + ` IdentityFile ${homeSsh}/key-${sha256}\n` + ` IdentitiesOnly yes\n`; diff --git a/index.js b/index.js index d28a764..4bfe1dd 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ try { console.log('Configuring deployment key(s)'); child_process.execFileSync(sshAddCmd, ['-L']).toString().trim().split(/\r?\n/).forEach(function(key) { - const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i); + const parts = key.match(/\b([\w.]+)[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)$/i); if (!parts) { if (logPublicKey) { @@ -56,16 +56,17 @@ try { } const sha256 = crypto.createHash('sha256').update(key).digest('hex'); - const ownerAndRepo = parts[1].replace(/\.git$/, ''); + const githubHost = parts[1]; + const ownerAndRepo = parts[2].replace(/\.git$/, ''); fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' }); - child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://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(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "https://${githubHost}/${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "git@${githubHost}:${ownerAndRepo}"`); + child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${githubHost}:${ownerAndRepo}".insteadOf "ssh://git@${githubHost}/${ownerAndRepo}"`); - const sshConfig = `\nHost key-${sha256}.github.com\n` - + ` HostName github.com\n` + const sshConfig = `\nHost key-${sha256}.${githubHost}\n` + + ` HostName ${githubHost}\n` + ` IdentityFile ${homeSsh}/key-${sha256}\n` + ` IdentitiesOnly yes\n`;