mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
* add lint tools (#61)
This commit is contained in:
parent
ab2b5fa346
commit
a4ff38c616
8 changed files with 2417 additions and 359 deletions
89
lib/main.js
89
lib/main.js
|
@ -1,89 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
/**
|
||||
* main function
|
||||
*/
|
||||
function main() {
|
||||
try {
|
||||
const files = [
|
||||
{
|
||||
name: core.getInput("name"),
|
||||
contents: core.getInput("private-key", {
|
||||
required: true,
|
||||
}),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "ax",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: prependLf(core.getInput("known-hosts")),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "config",
|
||||
contents: prependLf(core.getInput("config")),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
];
|
||||
// create ".ssh" directory
|
||||
const home = getHomeDirectory();
|
||||
const dirName = path.resolve(home, ".ssh");
|
||||
fs.mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
// create files
|
||||
for (const file of files) {
|
||||
const fileName = path.join(dirName, file.name);
|
||||
fs.writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch (err) {
|
||||
core.setFailed(err.message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory
|
||||
*/
|
||||
function getHomeDirectory() {
|
||||
const homeEnv = process.platform == "win32" ? "USERPROFILE" : "HOME";
|
||||
const home = process.env[homeEnv];
|
||||
if (home === undefined) {
|
||||
throw Error(`${homeEnv} is not defined`);
|
||||
}
|
||||
return home;
|
||||
}
|
||||
/**
|
||||
* prepend LF to value if not empty
|
||||
* @param value the value to prepend LF
|
||||
* @returns prepended value
|
||||
*/
|
||||
function prependLf(value) {
|
||||
if (value.length === 0) {
|
||||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
return `\n${value}`;
|
||||
}
|
||||
main();
|
||||
//# sourceMappingURL=main.js.map
|
Loading…
Add table
Add a link
Reference in a new issue