-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
exclude_paths: | ||
- 'lib/**' | ||
- 'node_modules/**' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Ignore all | ||
** | ||
|
||
# Except | ||
!src/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,4 @@ jobs: | |
- name: Clone GitLab repository | ||
run: | | ||
rm -rf private-repository | ||
git clone [email protected]:MrSquaare/private-repository.git | ||
git clone [email protected]:MrSquaare/private-repository.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# ssh-setup-action | ||
Setup SSH | ||
|
||
 | ||
[](https://www.codacy.com/manual/MrSquaare/ssh-setup-action?utm_source=github.com&utm_medium=referral&utm_content=MrSquaare/ssh-setup-action&utm_campaign=Badge_Grade) | ||
 | ||
 | ||
 | ||
[](https://www.codacy.com/gh/MrSquaare/ssh-setup-action/dashboard) | ||
|
||
## Usage | ||
|
||
|
@@ -75,4 +75,4 @@ jobs: | |
run: git clone [email protected]:username/repository.git | ||
- name: Clone GitLab repository | ||
run: git clone [email protected]:username/repository.git | ||
``` | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ inputs: | |
required: false | ||
runs: | ||
using: "node12" | ||
main: "dist/index.js" | ||
main: "lib/index.js" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
"use strict"; | ||
/* eslint-disable no-console */ | ||
/* eslint-disable security/detect-non-literal-fs-filename */ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = require("@actions/core"); | ||
const exec = require("@actions/exec"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const defaultHomePath = "/home/runner"; | ||
class SSHAgent { | ||
constructor(pid, socket) { | ||
this.pid = pid; | ||
this.socket = socket; | ||
} | ||
} | ||
function initializeSSH() { | ||
const homePath = process.env.HOME || defaultHomePath; | ||
const sshPath = path.join(homePath, ".ssh"); | ||
if (!fs.existsSync(sshPath)) { | ||
fs.mkdirSync(sshPath, { mode: 0o700 }); | ||
} | ||
return sshPath; | ||
} | ||
function initializeSSHAgent() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let sshAgentOutput = String(); | ||
const sshAgentOptions = { | ||
silent: true, | ||
listeners: { | ||
stdout: (data) => { | ||
sshAgentOutput = data.toString(); | ||
}, | ||
}, | ||
}; | ||
yield exec.exec("ssh-agent", ["-s"], sshAgentOptions); | ||
const pidMatch = sshAgentOutput.match("SSH_AGENT_PID=(.*?);"); | ||
const socketMatch = sshAgentOutput.match("SSH_AUTH_SOCK=(.*?);"); | ||
return { | ||
pid: pidMatch ? pidMatch[1] : null, | ||
socket: socketMatch ? socketMatch[1] : null, | ||
}; | ||
}); | ||
} | ||
function addKnownHost(sshPath, host) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const knownHostsPath = path.join(sshPath, "known_hosts"); | ||
let sshKeyScanOutput = String(); | ||
const sshKeyScanOptions = { | ||
silent: true, | ||
listeners: { | ||
stdout: (data) => { | ||
sshKeyScanOutput = data.toString(); | ||
}, | ||
}, | ||
}; | ||
yield exec.exec("ssh-keyscan", [host], sshKeyScanOptions); | ||
fs.writeFileSync(knownHostsPath, sshKeyScanOutput, { | ||
mode: 0o644, | ||
flag: "a+", | ||
}); | ||
}); | ||
} | ||
function createPrivateKey(sshPath, name, key) { | ||
const privateKeyPath = path.join(sshPath, name); | ||
fs.writeFileSync(privateKeyPath, key, { | ||
mode: 0o600, | ||
flag: "w", | ||
}); | ||
} | ||
function addPrivateKey(sshPath, name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const privateKeyPath = path.join(sshPath, name); | ||
const sshAddOptions = { | ||
silent: true, | ||
}; | ||
yield exec.exec("ssh-add", [privateKeyPath], sshAddOptions); | ||
}); | ||
} | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sshPath = yield initializeSSH(); | ||
core.exportVariable("SSH_PATH", sshPath); | ||
console.log("SSH initialized."); | ||
const sshAgent = yield initializeSSHAgent(); | ||
core.exportVariable("SSH_AGENT_PID", sshAgent.pid); | ||
core.exportVariable("SSH_AUTH_SOCK", sshAgent.socket); | ||
console.log("SSH agent initialized."); | ||
const host = core.getInput("host"); | ||
yield addKnownHost(sshPath, host); | ||
console.log("Host added to known hosts."); | ||
const privateKey = core.getInput("private-key") + "\n"; | ||
const privateKeyName = core.getInput("private-key-name"); | ||
yield createPrivateKey(sshPath, privateKeyName, privateKey); | ||
console.log("Private key file created."); | ||
yield addPrivateKey(sshPath, privateKeyName); | ||
console.log("Private key added to agent."); | ||
}); | ||
} | ||
run().catch((e) => core.setFailed(e.toString())); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.