Skip to content

Commit

Permalink
Merge pull request MrSquaare#4 from MrSquaare/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSquaare authored Oct 30, 2020
2 parents 4383fc3 + c3b9871 commit 8ed91aa
Show file tree
Hide file tree
Showing 36 changed files with 495 additions and 440 deletions.
4 changes: 4 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
exclude_paths:
- 'lib/**'
- 'node_modules/**'
5 changes: 5 additions & 0 deletions .dcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore all
**

# Except
!src/
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ssh-setup-action
Setup SSH

![Pull Request](https://github.com/MrSquaare/ssh-setup-action/workflows/Pull%20Request/badge.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8c87d5e7a3c14640a874b228fbeb95a7)](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)
![Dependabot](https://badgen.net/dependabot/MrSquaare/ssh-setup-action/?icon=dependabot)
![Release](https://badgen.net/github/release/MrSquaare/ssh-setup-action?icon=github)
![Dependabot](https://badgen.net/github/dependabot/MrSquaare/ssh-setup-action?icon=github)
[![Codacy](https://app.codacy.com/project/badge/Grade/88adcccc19804fe6969e053d690a2b1d)](https://www.codacy.com/gh/MrSquaare/ssh-setup-action/dashboard)

## Usage

Expand Down Expand Up @@ -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
```
```
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ inputs:
required: false
runs:
using: "node12"
main: "dist/index.js"
main: "lib/index.js"
89 changes: 0 additions & 89 deletions dist/index.js

This file was deleted.

108 changes: 108 additions & 0 deletions lib/index.js
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()));
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions node_modules/@actions/core/lib/core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ed91aa

Please sign in to comment.