mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
implement
This commit is contained in:
parent
9ce25420b4
commit
75f4435545
3 changed files with 52 additions and 12 deletions
3
.github/workflows/verify-on-ubuntu.yml
vendored
3
.github/workflows/verify-on-ubuntu.yml
vendored
|
@ -275,9 +275,6 @@ jobs:
|
||||||
uses: ./.
|
uses: ./.
|
||||||
with:
|
with:
|
||||||
key: ${{ secrets.SSH_KEY_PEM }}
|
key: ${{ secrets.SSH_KEY_PEM }}
|
||||||
known_hosts: ${{ secrets.KNOWN_HOSTS }}
|
|
||||||
no_known_hosts: true
|
no_known_hosts: true
|
||||||
- name: print created files
|
- name: print created files
|
||||||
run: ls -l ~/.ssh
|
run: ls -l ~/.ssh
|
||||||
- name: git clone through SSH
|
|
||||||
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
|
|
||||||
|
|
27
lib/index.js
27
lib/index.js
|
@ -428,18 +428,16 @@ const core = __importStar(__nccwpck_require__(186));
|
||||||
function main() {
|
function main() {
|
||||||
try {
|
try {
|
||||||
// parameters
|
// parameters
|
||||||
|
const noKnownHosts = string2boolean(core.getInput("no_known_hosts"));
|
||||||
const key = core.getInput("key", {
|
const key = core.getInput("key", {
|
||||||
required: true,
|
required: true,
|
||||||
});
|
});
|
||||||
const name = core.getInput("name");
|
const name = core.getInput("name");
|
||||||
const knownHosts = core.getInput("known_hosts", {
|
const knownHosts = core.getInput("known_hosts", {
|
||||||
required: true,
|
required: !noKnownHosts, // optional if no_known_hosts is true
|
||||||
});
|
});
|
||||||
const config = core.getInput("config");
|
const config = core.getInput("config");
|
||||||
const ifKeyExists = core.getInput("if_key_exists");
|
const ifKeyExists = core.getInput("if_key_exists");
|
||||||
// test
|
|
||||||
const noKnownHosts = core.getInput("no_known_hosts");
|
|
||||||
console.log(noKnownHosts);
|
|
||||||
// create ".ssh" directory
|
// create ".ssh" directory
|
||||||
const home = getHomeDirectory();
|
const home = getHomeDirectory();
|
||||||
const dirName = path_1.default.resolve(home, ".ssh");
|
const dirName = path_1.default.resolve(home, ".ssh");
|
||||||
|
@ -487,6 +485,27 @@ function main() {
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* convert string to boolean
|
||||||
|
* @param value string value
|
||||||
|
* @returns boolean value
|
||||||
|
*/
|
||||||
|
function string2boolean(value) {
|
||||||
|
// true if "true" / "yes" / "on"
|
||||||
|
switch (value.trim().toLowerCase()) {
|
||||||
|
case "true":
|
||||||
|
case "yes":
|
||||||
|
case "on":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// true if number and non-zero
|
||||||
|
const numberValue = Number(value);
|
||||||
|
if (!isNaN(numberValue) && numberValue !== 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// false otherwise
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* get home directory
|
* get home directory
|
||||||
* @returns home directory
|
* @returns home directory
|
||||||
|
|
34
src/main.ts
34
src/main.ts
|
@ -18,20 +18,17 @@ function main(): void
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// parameters
|
// parameters
|
||||||
|
const noKnownHosts = string2boolean(core.getInput("no_known_hosts"));
|
||||||
const key = core.getInput("key", {
|
const key = core.getInput("key", {
|
||||||
required: true,
|
required: true,
|
||||||
});
|
});
|
||||||
const name = core.getInput("name");
|
const name = core.getInput("name");
|
||||||
const knownHosts = core.getInput("known_hosts", {
|
const knownHosts = core.getInput("known_hosts", {
|
||||||
required: true,
|
required: !noKnownHosts, // optional if no_known_hosts is true
|
||||||
});
|
});
|
||||||
const config = core.getInput("config");
|
const config = core.getInput("config");
|
||||||
const ifKeyExists = core.getInput("if_key_exists");
|
const ifKeyExists = core.getInput("if_key_exists");
|
||||||
|
|
||||||
// test
|
|
||||||
const noKnownHosts = core.getInput("no_known_hosts");
|
|
||||||
console.log(noKnownHosts);
|
|
||||||
|
|
||||||
// create ".ssh" directory
|
// create ".ssh" directory
|
||||||
const home = getHomeDirectory();
|
const home = getHomeDirectory();
|
||||||
const dirName = path.resolve(home, ".ssh");
|
const dirName = path.resolve(home, ".ssh");
|
||||||
|
@ -86,6 +83,33 @@ function main(): void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert string to boolean
|
||||||
|
* @param value string value
|
||||||
|
* @returns boolean value
|
||||||
|
*/
|
||||||
|
function string2boolean(value: string): boolean
|
||||||
|
{
|
||||||
|
// true if "true" / "yes" / "on"
|
||||||
|
switch(value.trim().toLowerCase())
|
||||||
|
{
|
||||||
|
case "true":
|
||||||
|
case "yes":
|
||||||
|
case "on":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// true if number and non-zero
|
||||||
|
const numberValue = Number(value);
|
||||||
|
if(!isNaN(numberValue) && numberValue !== 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// false otherwise
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get home directory
|
* get home directory
|
||||||
* @returns home directory
|
* @returns home directory
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue