Skip to content

Commit

Permalink
🦄🗯️ added ssh build with linting (#121) 🦄🗯️
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy authored Nov 22, 2023
1 parent 11f2ce2 commit 2cfdbf7
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 93 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ssh-agent-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build ssh-agent

on:
push:
paths:
- .github/workflows/ssh-agent-build.yaml
- ssh-agent/**
pull_request:
paths:
- .github/workflows/ssh-agent-build.yaml
- ssh-agent/**

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install Node.js dependencies
run: |
pushd ssh-agent/
npm install
npm i -g @vercel/ncc
popd
- name: Run linters
uses: wearerequired/lint-action@v2
with:
continue_on_error: false
eslint_dir: ssh-agent/
eslint_auto_fix: false
eslint: true
prettier_dir: ssh-agent/
prettier_auto_fix: false
prettier: true

- name: Compile Node.js dependencies
run: |
pushd ssh-agent/
npm run compile
popd
1 change: 1 addition & 0 deletions ssh-agent/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
11 changes: 11 additions & 0 deletions ssh-agent/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
env:
node: true
commonjs: true
es2021: true
extends:
- eslint:recommended
- prettier
overrides: []
parserOptions:
ecmaVersion: latest
rules: {}
4 changes: 4 additions & 0 deletions ssh-agent/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
README.md
action.yml
.eslintrc.yml
1 change: 1 addition & 0 deletions ssh-agent/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
112 changes: 65 additions & 47 deletions ssh-agent/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2840,55 +2840,73 @@ module.exports = require("util");
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const core = __nccwpck_require__(855)
const proc = __nccwpck_require__(81)
const fs = __nccwpck_require__(147)
const core = __nccwpck_require__(855);
const proc = __nccwpck_require__(81);
const fs = __nccwpck_require__(147);

function run() {
try {
if (!fs.existsSync(`${process.env["HOME"]}/.ssh`)) {
fs.mkdirSync(`${process.env["HOME"]}/.ssh`, { recursive: true });
}

try {
if(!fs.existsSync(`${process.env['HOME']}/.ssh`)) {
fs.mkdirSync(`${process.env['HOME']}/.ssh`, {recursive: true})
}
console.log("Building known hosts")
proc.execSync(
`ssh-keyscan -p ${core.getInput('ssh_port')} ${core.getInput('domain')} >> ${process.env['HOME']}/.ssh/known_hosts`,
{
stdio: [null, null, null],
timeout: 20000
}
)
console.log("Finished building known hosts!")
console.log("Starting ssh-agent")
sshOutput = proc.execFileSync(`ssh-agent`, ["-a", core.getInput('ssh_auth_sock')])
sshOutput.toString().split("\n").forEach((line) => {
var regexp = /=(.*); /g;
if (line.includes("SSH_AUTH_SOCK")) {
const sock = regexp.exec(line)[1];
core.exportVariable("SSH_AUTH_SOCK", sock)
console.log(`Agent socket is ${sock}`)
}
if (line.includes("SSH_AGENT_PID")) {
const pid = regexp.exec(line)[1]
core.exportVariable("SSH_AGENT_PID", pid)
console.log(`Agent PID is ${pid}`)
}
})
console.log("Exported agent variables")
console.log("Started ssh-agent!")
console.log("Adding identity")
proc.execSync(
"ssh-add -",
{
stdio: [null, null, null],
input: core.getInput("private_key").trim() + "\n"
}
)
console.log("Added identity!")
console.log("ssh-agent is ready to use")
} catch (error) {
console.log("Encountered an error:")
console.log(error.message)
process.exit(1)
console.log("Building known hosts");

proc.execSync(
`ssh-keyscan -p ${core.getInput("ssh_port")} ${core.getInput(
"domain"
)} >> ${process.env["HOME"]}/.ssh/known_hosts`,
{
stdio: [null, null, null],
timeout: 20000,
}
);

console.log("Finished building known hosts!");
console.log("Starting ssh-agent");

var sshOutput = proc.execFileSync(`ssh-agent`, [
"-a",
core.getInput("ssh_auth_sock"),
]);

sshOutput
.toString()
.split("\n")
.forEach((line) => {
var regexp = /=(.*); /g;
if (line.includes("SSH_AUTH_SOCK")) {
const sock = regexp.exec(line)[1];
core.exportVariable("SSH_AUTH_SOCK", sock);
console.log(`Agent socket is ${sock}`);
}

if (line.includes("SSH_AGENT_PID")) {
const pid = regexp.exec(line)[1];
core.exportVariable("SSH_AGENT_PID", pid);
console.log(`Agent PID is ${pid}`);
}
});

console.log("Exported agent variables");
console.log("Started ssh-agent!");
console.log("Adding identity");

proc.execSync("ssh-add -", {
stdio: [null, null, null],
input: core.getInput("private_key").trim() + "\n",
});

console.log("Added identity!");
console.log("ssh-agent is ready to use");
} catch (error) {
console.log("Encountered an error:");
console.log(error.message);
process.exit(1);
}
}

run();
})();

module.exports = __webpack_exports__;
Expand Down
110 changes: 64 additions & 46 deletions ssh-agent/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,67 @@
const core = require('@actions/core')
const proc = require('child_process')
const fs = require('fs')
const core = require("@actions/core");
const proc = require("child_process");
const fs = require("fs");

try {
if(!fs.existsSync(`${process.env['HOME']}/.ssh`)) {
fs.mkdirSync(`${process.env['HOME']}/.ssh`, {recursive: true})
}
console.log("Building known hosts")
proc.execSync(
`ssh-keyscan -p ${core.getInput('ssh_port')} ${core.getInput('domain')} >> ${process.env['HOME']}/.ssh/known_hosts`,
{
stdio: [null, null, null],
timeout: 20000
}
)
console.log("Finished building known hosts!")
console.log("Starting ssh-agent")
sshOutput = proc.execFileSync(`ssh-agent`, ["-a", core.getInput('ssh_auth_sock')])
sshOutput.toString().split("\n").forEach((line) => {
var regexp = /=(.*); /g;
if (line.includes("SSH_AUTH_SOCK")) {
const sock = regexp.exec(line)[1];
core.exportVariable("SSH_AUTH_SOCK", sock)
console.log(`Agent socket is ${sock}`)
}
if (line.includes("SSH_AGENT_PID")) {
const pid = regexp.exec(line)[1]
core.exportVariable("SSH_AGENT_PID", pid)
console.log(`Agent PID is ${pid}`)
function run() {
try {
if (!fs.existsSync(`${process.env["HOME"]}/.ssh`)) {
fs.mkdirSync(`${process.env["HOME"]}/.ssh`, { recursive: true });
}
})
console.log("Exported agent variables")
console.log("Started ssh-agent!")
console.log("Adding identity")
proc.execSync(
"ssh-add -",
{

console.log("Building known hosts");

proc.execSync(
`ssh-keyscan -p ${core.getInput("ssh_port")} ${core.getInput(
"domain"
)} >> ${process.env["HOME"]}/.ssh/known_hosts`,
{
stdio: [null, null, null],
timeout: 20000,
}
);

console.log("Finished building known hosts!");
console.log("Starting ssh-agent");

var sshOutput = proc.execFileSync(`ssh-agent`, [
"-a",
core.getInput("ssh_auth_sock"),
]);

sshOutput
.toString()
.split("\n")
.forEach((line) => {
var regexp = /=(.*); /g;
if (line.includes("SSH_AUTH_SOCK")) {
const sock = regexp.exec(line)[1];
core.exportVariable("SSH_AUTH_SOCK", sock);
console.log(`Agent socket is ${sock}`);
}

if (line.includes("SSH_AGENT_PID")) {
const pid = regexp.exec(line)[1];
core.exportVariable("SSH_AGENT_PID", pid);
console.log(`Agent PID is ${pid}`);
}
});

console.log("Exported agent variables");
console.log("Started ssh-agent!");
console.log("Adding identity");

proc.execSync("ssh-add -", {
stdio: [null, null, null],
input: core.getInput("private_key").trim() + "\n"
}
)
console.log("Added identity!")
console.log("ssh-agent is ready to use")
} catch (error) {
console.log("Encountered an error:")
console.log(error.message)
process.exit(1)
}
input: core.getInput("private_key").trim() + "\n",
});

console.log("Added identity!");
console.log("ssh-agent is ready to use");
} catch (error) {
console.log("Encountered an error:");
console.log(error.message);
process.exit(1);
}
}

run();
6 changes: 6 additions & 0 deletions ssh-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.10.0"
},
"devDependencies": {
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"ncc": "^0.3.6",
"prettier": "^2.8.4"
}
}

0 comments on commit 2cfdbf7

Please sign in to comment.