Updating the action to have a choice for how user is looked up on linux
This commit is contained in:
parent
53715f806b
commit
815a336fc0
8 changed files with 133 additions and 69 deletions
18
index.js
18
index.js
|
@ -2,10 +2,14 @@ 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 getPaths = require('./paths.js');
|
||||
|
||||
|
||||
try {
|
||||
const privateKey = core.getInput('ssh-private-key');
|
||||
const linuxUseHomedir = core.getInput('linux-use-homedir');
|
||||
|
||||
const { home, sshAgent, sshAdd } = getPaths(linuxUseHomedir);
|
||||
|
||||
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.");
|
||||
|
@ -28,7 +32,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(sshAgent, sshAgentArgs).toString().split("\n").forEach(function (line) {
|
||||
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
|
||||
|
||||
if (matches && matches.length > 0) {
|
||||
|
@ -40,7 +44,7 @@ try {
|
|||
|
||||
console.log("Adding private key(s) to agent");
|
||||
|
||||
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
|
||||
privateKey.split(/(?=-----BEGIN)/).forEach(function (key) {
|
||||
child_process.execFileSync(sshAdd, ['-'], { input: key.trim() + "\n" });
|
||||
});
|
||||
|
||||
|
@ -50,7 +54,7 @@ try {
|
|||
|
||||
console.log('Configuring deployment key(s)');
|
||||
|
||||
child_process.execFileSync(sshAdd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
|
||||
child_process.execFileSync(sshAdd, ['-L']).toString().split(/\r?\n/).forEach(function (key) {
|
||||
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
||||
|
||||
if (!parts) {
|
||||
|
@ -69,9 +73,9 @@ try {
|
|||
child_process.execSync(`git 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`
|
||||
+ ` IdentityFile ${homeSsh}/key-${sha256}\n`
|
||||
+ ` IdentitiesOnly yes\n`;
|
||||
+ ` HostName github.com\n`
|
||||
+ ` IdentityFile ${homeSsh}/key-${sha256}\n`
|
||||
+ ` IdentitiesOnly yes\n`;
|
||||
|
||||
fs.appendFileSync(`${homeSsh}/config`, sshConfig);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue