mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
use module files (#252)
* use module * detect files to be restore automatically * use esbuild * drop ncc * add comments * refactor
This commit is contained in:
parent
31d4b8b483
commit
6948892be9
11 changed files with 775 additions and 3346 deletions
|
@ -27,5 +27,5 @@ inputs:
|
|||
default: "fail"
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "lib/index.js"
|
||||
post: "lib/index.js"
|
||||
main: "./dist/main.js"
|
||||
post: "./dist/post.js"
|
||||
|
|
14
dist/main.js
vendored
Normal file
14
dist/main.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
dist/main.js.map
vendored
Normal file
7
dist/main.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
9
dist/post.js
vendored
Normal file
9
dist/post.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
dist/post.js.map
vendored
Normal file
7
dist/post.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3165
lib/index.js
3165
lib/index.js
File diff suppressed because it is too large
Load diff
590
package-lock.json
generated
590
package-lock.json
generated
|
@ -13,7 +13,7 @@
|
|||
"@types/node": "18.15.7",
|
||||
"@typescript-eslint/eslint-plugin": "5.56.0",
|
||||
"@typescript-eslint/parser": "5.56.0",
|
||||
"@vercel/ncc": "0.36.1",
|
||||
"esbuild": "0.19.4",
|
||||
"eslint": "8.36.0",
|
||||
"markdownlint-cli": "0.33.0",
|
||||
"npm-check-updates": "16.8.0",
|
||||
|
@ -55,6 +55,358 @@
|
|||
"node": ">=0.1.90"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.4.tgz",
|
||||
"integrity": "sha512-uBIbiYMeSsy2U0XQoOGVVcpIktjLMEKa7ryz2RLr7L/vTnANNEsPVAh4xOv7ondGz6ac1zVb0F8Jx20rQikffQ==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-mRsi2vJsk4Bx/AFsNBqOH2fqedxn5L/moT58xgg51DjX1la64Z3Npicut2VbhvDFO26qjWtPMsVxCd80YTFVeg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-4iPufZ1TMOD3oBlGFqHXBpa3KFT46aLl6Vy7gwed0ZSYgHaZ/mihbYb4t7Z9etjkC9Al3ZYIoOaHrU60gcMy7g==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-Lviw8EzxsVQKpbS+rSt6/6zjn9ashUZ7Tbuvc2YENgRl0yZTktGlachZ9KMJUsVjZEGFVu336kl5lBgDN6PmpA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-YHbSFlLgDwglFn0lAO3Zsdrife9jcQXQhgRp77YiTDja23FrC2uwnhXMNkAucthsf+Psr7sTwYEryxz6FPAVqw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-vz59ijyrTG22Hshaj620e5yhs2dU1WJy723ofc+KUgxVCM6zxQESmWdMuVmUzxtGqtj5heHyB44PjV/HKsEmuQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-3sRbQ6W5kAiVQRBWREGJNd1YE7OgzS0AmOGjDmX/qZZecq8NFlQsQH0IfXjjmD0XtUYqr64e0EKNFjMUlPL3Cw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.4.tgz",
|
||||
"integrity": "sha512-z/4ArqOo9EImzTi4b6Vq+pthLnepFzJ92BnofU1jgNlcVb+UqynVFdoXMCFreTK7FdhqAzH0vmdwW5373Hm9pg==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-ZWmWORaPbsPwmyu7eIEATFlaqm0QGt+joRE9sKcnVUG3oBbr/KYdNE2TnkzdQwX6EDRdg/x8Q4EZQTXoClUqqA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ia32": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.4.tgz",
|
||||
"integrity": "sha512-EGc4vYM7i1GRUIMqRZNCTzJh25MHePYsnQfKDexD8uPTCm9mK56NIL04LUfX2aaJ+C9vyEp2fJ7jbqFEYgO9lQ==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-loong64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.4.tgz",
|
||||
"integrity": "sha512-WVhIKO26kmm8lPmNrUikxSpXcgd6HDog0cx12BUfA2PkmURHSgx9G6vA19lrlQOMw+UjMZ+l3PpbtzffCxFDRg==",
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-mips64el": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.4.tgz",
|
||||
"integrity": "sha512-keYY+Hlj5w86hNp5JJPuZNbvW4jql7c1eXdBUHIJGTeN/+0QFutU3GrS+c27L+NTmzi73yhtojHk+lr2+502Mw==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ppc64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.4.tgz",
|
||||
"integrity": "sha512-tQ92n0WMXyEsCH4m32S21fND8VxNiVazUbU4IUGVXQpWiaAxOBvtOtbEt3cXIV3GEBydYsY8pyeRMJx9kn3rvw==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-riscv64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.4.tgz",
|
||||
"integrity": "sha512-tRRBey6fG9tqGH6V75xH3lFPpj9E8BH+N+zjSUCnFOX93kEzqS0WdyJHkta/mmJHn7MBaa++9P4ARiU4ykjhig==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-s390x": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.4.tgz",
|
||||
"integrity": "sha512-152aLpQqKZYhThiJ+uAM4PcuLCAOxDsCekIbnGzPKVBRUDlgaaAfaUl5NYkB1hgY6WN4sPkejxKlANgVcGl9Qg==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-Mi4aNA3rz1BNFtB7aGadMD0MavmzuuXNTaYL6/uiYIs08U7YMPETpgNn5oue3ICr+inKwItOwSsJDYkrE9ekVg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-9+Wxx1i5N/CYo505CTT7T+ix4lVzEdz0uCoYGxM5JDVlP2YdDC1Bdz+Khv6IbqmisT0Si928eAxbmGkcbiuM/A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"netbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-MFsHleM5/rWRW9EivFssop+OulYVUoVcqkyOkjiynKBCGBj9Lihl7kh9IzrreDyXa4sNkquei5/DTP4uCk25xw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/sunos-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-6Xq8SpK46yLvrGxjp6HftkDwPP49puU4OF0hEL4dTxqCbfx09LyrbUj/D7tmIRMj5D5FCUPksBbxyQhp8tmHzw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"sunos"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-PkIl7Jq4mP6ke7QKwyg4fD4Xvn8PXisagV/+HntWoDEdmerB2LTukRZg728Yd1Fj+LuEX75t/hKXE2Ppk8Hh1w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-ia32": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.4.tgz",
|
||||
"integrity": "sha512-ga676Hnvw7/ycdKB53qPusvsKdwrWzEyJ+AtItHGoARszIqvjffTwaaW3b2L6l90i7MO9i+dlAW415INuRhSGg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-HP0GDNla1T3ZL8Ko/SHAS2GgtjOg+VmWnnYLhuTksr++EnduYB0f3Y2LzHsUwb2iQ13JGoY6G3R8h6Du/WG6uA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint-community/eslint-utils": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
|
||||
|
@ -653,15 +1005,6 @@
|
|||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@vercel/ncc": {
|
||||
"version": "0.36.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz",
|
||||
"integrity": "sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"ncc": "dist/ncc/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
|
@ -1617,6 +1960,43 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.4.tgz",
|
||||
"integrity": "sha512-x7jL0tbRRpv4QUyuDMjONtWFciygUxWaUM1kMX2zWxI0X2YWOt7MSA0g4UdeSiHM8fcYVzpQhKYOycZwxTdZkA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@esbuild/android-arm": "0.19.4",
|
||||
"@esbuild/android-arm64": "0.19.4",
|
||||
"@esbuild/android-x64": "0.19.4",
|
||||
"@esbuild/darwin-arm64": "0.19.4",
|
||||
"@esbuild/darwin-x64": "0.19.4",
|
||||
"@esbuild/freebsd-arm64": "0.19.4",
|
||||
"@esbuild/freebsd-x64": "0.19.4",
|
||||
"@esbuild/linux-arm": "0.19.4",
|
||||
"@esbuild/linux-arm64": "0.19.4",
|
||||
"@esbuild/linux-ia32": "0.19.4",
|
||||
"@esbuild/linux-loong64": "0.19.4",
|
||||
"@esbuild/linux-mips64el": "0.19.4",
|
||||
"@esbuild/linux-ppc64": "0.19.4",
|
||||
"@esbuild/linux-riscv64": "0.19.4",
|
||||
"@esbuild/linux-s390x": "0.19.4",
|
||||
"@esbuild/linux-x64": "0.19.4",
|
||||
"@esbuild/netbsd-x64": "0.19.4",
|
||||
"@esbuild/openbsd-x64": "0.19.4",
|
||||
"@esbuild/sunos-x64": "0.19.4",
|
||||
"@esbuild/win32-arm64": "0.19.4",
|
||||
"@esbuild/win32-ia32": "0.19.4",
|
||||
"@esbuild/win32-x64": "0.19.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
|
||||
|
@ -6247,6 +6627,160 @@
|
|||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/android-arm": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.4.tgz",
|
||||
"integrity": "sha512-uBIbiYMeSsy2U0XQoOGVVcpIktjLMEKa7ryz2RLr7L/vTnANNEsPVAh4xOv7ondGz6ac1zVb0F8Jx20rQikffQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/android-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-mRsi2vJsk4Bx/AFsNBqOH2fqedxn5L/moT58xgg51DjX1la64Z3Npicut2VbhvDFO26qjWtPMsVxCd80YTFVeg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/android-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-4iPufZ1TMOD3oBlGFqHXBpa3KFT46aLl6Vy7gwed0ZSYgHaZ/mihbYb4t7Z9etjkC9Al3ZYIoOaHrU60gcMy7g==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/darwin-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-Lviw8EzxsVQKpbS+rSt6/6zjn9ashUZ7Tbuvc2YENgRl0yZTktGlachZ9KMJUsVjZEGFVu336kl5lBgDN6PmpA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/darwin-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-YHbSFlLgDwglFn0lAO3Zsdrife9jcQXQhgRp77YiTDja23FrC2uwnhXMNkAucthsf+Psr7sTwYEryxz6FPAVqw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/freebsd-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-vz59ijyrTG22Hshaj620e5yhs2dU1WJy723ofc+KUgxVCM6zxQESmWdMuVmUzxtGqtj5heHyB44PjV/HKsEmuQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/freebsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-3sRbQ6W5kAiVQRBWREGJNd1YE7OgzS0AmOGjDmX/qZZecq8NFlQsQH0IfXjjmD0XtUYqr64e0EKNFjMUlPL3Cw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-arm": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.4.tgz",
|
||||
"integrity": "sha512-z/4ArqOo9EImzTi4b6Vq+pthLnepFzJ92BnofU1jgNlcVb+UqynVFdoXMCFreTK7FdhqAzH0vmdwW5373Hm9pg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-ZWmWORaPbsPwmyu7eIEATFlaqm0QGt+joRE9sKcnVUG3oBbr/KYdNE2TnkzdQwX6EDRdg/x8Q4EZQTXoClUqqA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-ia32": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.4.tgz",
|
||||
"integrity": "sha512-EGc4vYM7i1GRUIMqRZNCTzJh25MHePYsnQfKDexD8uPTCm9mK56NIL04LUfX2aaJ+C9vyEp2fJ7jbqFEYgO9lQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-loong64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.4.tgz",
|
||||
"integrity": "sha512-WVhIKO26kmm8lPmNrUikxSpXcgd6HDog0cx12BUfA2PkmURHSgx9G6vA19lrlQOMw+UjMZ+l3PpbtzffCxFDRg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-mips64el": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.4.tgz",
|
||||
"integrity": "sha512-keYY+Hlj5w86hNp5JJPuZNbvW4jql7c1eXdBUHIJGTeN/+0QFutU3GrS+c27L+NTmzi73yhtojHk+lr2+502Mw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-ppc64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.4.tgz",
|
||||
"integrity": "sha512-tQ92n0WMXyEsCH4m32S21fND8VxNiVazUbU4IUGVXQpWiaAxOBvtOtbEt3cXIV3GEBydYsY8pyeRMJx9kn3rvw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-riscv64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.4.tgz",
|
||||
"integrity": "sha512-tRRBey6fG9tqGH6V75xH3lFPpj9E8BH+N+zjSUCnFOX93kEzqS0WdyJHkta/mmJHn7MBaa++9P4ARiU4ykjhig==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-s390x": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.4.tgz",
|
||||
"integrity": "sha512-152aLpQqKZYhThiJ+uAM4PcuLCAOxDsCekIbnGzPKVBRUDlgaaAfaUl5NYkB1hgY6WN4sPkejxKlANgVcGl9Qg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/linux-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-Mi4aNA3rz1BNFtB7aGadMD0MavmzuuXNTaYL6/uiYIs08U7YMPETpgNn5oue3ICr+inKwItOwSsJDYkrE9ekVg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/netbsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-9+Wxx1i5N/CYo505CTT7T+ix4lVzEdz0uCoYGxM5JDVlP2YdDC1Bdz+Khv6IbqmisT0Si928eAxbmGkcbiuM/A==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/openbsd-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-MFsHleM5/rWRW9EivFssop+OulYVUoVcqkyOkjiynKBCGBj9Lihl7kh9IzrreDyXa4sNkquei5/DTP4uCk25xw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/sunos-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-6Xq8SpK46yLvrGxjp6HftkDwPP49puU4OF0hEL4dTxqCbfx09LyrbUj/D7tmIRMj5D5FCUPksBbxyQhp8tmHzw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/win32-arm64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.4.tgz",
|
||||
"integrity": "sha512-PkIl7Jq4mP6ke7QKwyg4fD4Xvn8PXisagV/+HntWoDEdmerB2LTukRZg728Yd1Fj+LuEX75t/hKXE2Ppk8Hh1w==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/win32-ia32": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.4.tgz",
|
||||
"integrity": "sha512-ga676Hnvw7/ycdKB53qPusvsKdwrWzEyJ+AtItHGoARszIqvjffTwaaW3b2L6l90i7MO9i+dlAW415INuRhSGg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@esbuild/win32-x64": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.4.tgz",
|
||||
"integrity": "sha512-HP0GDNla1T3ZL8Ko/SHAS2GgtjOg+VmWnnYLhuTksr++EnduYB0f3Y2LzHsUwb2iQ13JGoY6G3R8h6Du/WG6uA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@eslint-community/eslint-utils": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
|
||||
|
@ -6651,12 +7185,6 @@
|
|||
"eslint-visitor-keys": "^3.3.0"
|
||||
}
|
||||
},
|
||||
"@vercel/ncc": {
|
||||
"version": "0.36.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz",
|
||||
"integrity": "sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==",
|
||||
"dev": true
|
||||
},
|
||||
"abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
|
@ -7368,6 +7896,36 @@
|
|||
"is-symbol": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"esbuild": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.4.tgz",
|
||||
"integrity": "sha512-x7jL0tbRRpv4QUyuDMjONtWFciygUxWaUM1kMX2zWxI0X2YWOt7MSA0g4UdeSiHM8fcYVzpQhKYOycZwxTdZkA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@esbuild/android-arm": "0.19.4",
|
||||
"@esbuild/android-arm64": "0.19.4",
|
||||
"@esbuild/android-x64": "0.19.4",
|
||||
"@esbuild/darwin-arm64": "0.19.4",
|
||||
"@esbuild/darwin-x64": "0.19.4",
|
||||
"@esbuild/freebsd-arm64": "0.19.4",
|
||||
"@esbuild/freebsd-x64": "0.19.4",
|
||||
"@esbuild/linux-arm": "0.19.4",
|
||||
"@esbuild/linux-arm64": "0.19.4",
|
||||
"@esbuild/linux-ia32": "0.19.4",
|
||||
"@esbuild/linux-loong64": "0.19.4",
|
||||
"@esbuild/linux-mips64el": "0.19.4",
|
||||
"@esbuild/linux-ppc64": "0.19.4",
|
||||
"@esbuild/linux-riscv64": "0.19.4",
|
||||
"@esbuild/linux-s390x": "0.19.4",
|
||||
"@esbuild/linux-x64": "0.19.4",
|
||||
"@esbuild/netbsd-x64": "0.19.4",
|
||||
"@esbuild/openbsd-x64": "0.19.4",
|
||||
"@esbuild/sunos-x64": "0.19.4",
|
||||
"@esbuild/win32-arm64": "0.19.4",
|
||||
"@esbuild/win32-ia32": "0.19.4",
|
||||
"@esbuild/win32-x64": "0.19.4"
|
||||
}
|
||||
},
|
||||
"escalade": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
"version": "2.5.1",
|
||||
"private": true,
|
||||
"description": "Install SSH key in .ssh",
|
||||
"main": "lib/index.js",
|
||||
"main": "./dist/main.js",
|
||||
"engines": {
|
||||
"node": ">=8.0.0",
|
||||
"npm": ">=5.7.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build src/main.ts -o lib",
|
||||
"build": "esbuild ./src/main.ts ./src/post.ts --bundle --platform=node --minify --sourcemap --outdir=./dist",
|
||||
"check-updates": "ncu",
|
||||
"lint": "run-p lint:*",
|
||||
"lint:ts": "eslint ./src --ext .ts",
|
||||
"lint:es": "eslint ./src --ext .ts",
|
||||
"lint:ts": "tsc --noEmit ./src/main.ts ./src/post.ts",
|
||||
"lint:md": "markdownlint . --ignore node_modules --ignore examples",
|
||||
"lint:yaml": "yamllint **/{,.}*.{yml,yaml} --ignore=node_modules/**",
|
||||
"verify": "run-p lint"
|
||||
|
@ -35,7 +36,7 @@
|
|||
"@types/node": "18.15.7",
|
||||
"@typescript-eslint/eslint-plugin": "5.56.0",
|
||||
"@typescript-eslint/parser": "5.56.0",
|
||||
"@vercel/ncc": "0.36.1",
|
||||
"esbuild": "0.19.4",
|
||||
"eslint": "8.36.0",
|
||||
"markdownlint-cli": "0.33.0",
|
||||
"npm-check-updates": "16.8.0",
|
||||
|
|
72
src/common.ts
Normal file
72
src/common.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
/** state name of backup suffix */
|
||||
const STATE_BACKUP_SUFFIX = "backup-suffix";
|
||||
|
||||
/**
|
||||
* create backup suffix name
|
||||
* @param dirName directory to back up
|
||||
* @returns backup suffix
|
||||
*/
|
||||
export function createBackupSuffix(dirName: string): string {
|
||||
if (!fs.existsSync(dirName)) {
|
||||
// do nothing if directory does not exist
|
||||
return "";
|
||||
}
|
||||
|
||||
const backupSuffix = `.bak-${Date.now()}`;
|
||||
core.saveState(STATE_BACKUP_SUFFIX, backupSuffix);
|
||||
return backupSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* get backup suffix name
|
||||
* @returns backup suffix (if not, empty string)
|
||||
*/
|
||||
export function getBackupSuffix(): string {
|
||||
return core.getState(STATE_BACKUP_SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* get SSH directory
|
||||
* @returns SSH directory name
|
||||
*/
|
||||
export function getSshDirectory(): string {
|
||||
return path.resolve(getHomeDirectory(), ".ssh");
|
||||
}
|
||||
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory name
|
||||
*/
|
||||
function getHomeDirectory(): string {
|
||||
const homeEnv = getHomeEnv();
|
||||
const home = process.env[homeEnv];
|
||||
if (home === undefined) {
|
||||
throw Error(`${homeEnv} is not defined`);
|
||||
}
|
||||
|
||||
if (home === "/github/home") {
|
||||
// Docker container
|
||||
return "/root";
|
||||
}
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
/**
|
||||
* get HOME environment name
|
||||
* @returns HOME environment name
|
||||
*/
|
||||
function getHomeEnv(): string {
|
||||
if (process.platform === "win32") {
|
||||
// Windows
|
||||
return "USERPROFILE";
|
||||
}
|
||||
|
||||
// macOS / Linux
|
||||
return "HOME";
|
||||
}
|
178
src/main.ts
178
src/main.ts
|
@ -1,17 +1,23 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as common from "./common";
|
||||
|
||||
/** file creation info */
|
||||
interface FileInfo {
|
||||
/** file name */
|
||||
name: string;
|
||||
/** file contents */
|
||||
contents: string;
|
||||
/** creation options */
|
||||
options: fs.WriteFileOptions;
|
||||
mustNotExist: boolean; // file must not exist when creating
|
||||
/** file must not exist when creating */
|
||||
mustNotExist: boolean;
|
||||
}
|
||||
|
||||
const STATE_BACKUP_SUFFIX = "backup-suffix";
|
||||
|
||||
/** default known_hosts */
|
||||
const KNOWN_HOSTS = [
|
||||
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=",
|
||||
];
|
||||
|
@ -27,36 +33,7 @@ try {
|
|||
/**
|
||||
* main function
|
||||
*/
|
||||
function main(): void {
|
||||
if (!isPost()) {
|
||||
setup();
|
||||
setPost();
|
||||
} else {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* is post process?
|
||||
* @returns Yes/No
|
||||
*/
|
||||
function isPost(): boolean {
|
||||
return Boolean(core.getState("isPost"));
|
||||
}
|
||||
|
||||
/**
|
||||
* update post state
|
||||
*/
|
||||
function setPost(): void {
|
||||
core.saveState("isPost", "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* setup function
|
||||
*/
|
||||
function setup(): void {
|
||||
const backupSuffix = generateBackupSuffix();
|
||||
|
||||
export function main(): void {
|
||||
// parameters
|
||||
const key = core.getInput("key", {
|
||||
required: true,
|
||||
|
@ -69,7 +46,12 @@ function setup(): void {
|
|||
const ifKeyExists = core.getInput("if_key_exists");
|
||||
|
||||
// create ".ssh" directory
|
||||
const sshDirName = createSshDirectory();
|
||||
const sshDirName = common.getSshDirectory();
|
||||
const backupSuffix = common.createBackupSuffix(sshDirName);
|
||||
fs.mkdirSync(sshDirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
|
||||
// files to be created
|
||||
const files: FileInfo[] = [
|
||||
|
@ -119,41 +101,10 @@ function setup(): void {
|
|||
|
||||
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
||||
if (backedUpFileNames.length > 0) {
|
||||
console.log(`Following files are backed up in suffix "${backupSuffix}"; ${backedUpFileNames.join(", ")}.`);
|
||||
console.log(`Following files are backed up in suffix "${backupSuffix}"; ${backedUpFileNames.join(", ")}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cleanup function
|
||||
*/
|
||||
function cleanup(): void {
|
||||
const backupSuffix = core.getState(STATE_BACKUP_SUFFIX);
|
||||
if (backupSuffix === "") {
|
||||
// remove ".ssh" directory if suffix is not set
|
||||
const sshDirName = removeSshDirectory();
|
||||
|
||||
console.log(`SSH key in ${sshDirName} has been removed successfully.`);
|
||||
} else {
|
||||
restore(backupSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate backup suffix name
|
||||
* @returns backup suffix
|
||||
*/
|
||||
function generateBackupSuffix(): string {
|
||||
const dirName = getSshDirectory();
|
||||
if (!fs.existsSync(dirName)) {
|
||||
// do nothing if .ssh does not exist
|
||||
return "";
|
||||
}
|
||||
|
||||
const backupSuffix = `.bak-${Date.now()}`;
|
||||
core.saveState(STATE_BACKUP_SUFFIX, backupSuffix);
|
||||
return backupSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* back up file
|
||||
* @param fileName file to back up
|
||||
|
@ -179,97 +130,6 @@ function backup(fileName: string, backupSuffix: string, removeOrig: boolean): bo
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* restore files
|
||||
* @param backupSuffix suffix of backup directory
|
||||
*/
|
||||
function restore(backupSuffix: string): void {
|
||||
const dirName = getSshDirectory();
|
||||
const keyFileName = core.getInput("name");
|
||||
|
||||
const restoredFileNames: string[] = [];
|
||||
for (const fileName of ["known_hosts", "config", keyFileName]) {
|
||||
const pathNameOrg = path.join(dirName, fileName);
|
||||
const pathNameBak = `${pathNameOrg}${backupSuffix}`;
|
||||
|
||||
if (!fs.existsSync(pathNameBak)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fs.rmSync(pathNameOrg);
|
||||
fs.renameSync(pathNameBak, pathNameOrg);
|
||||
restoredFileNames.push(fileName);
|
||||
}
|
||||
console.log(`Following files in suffix "${backupSuffix}" are restored; ${restoredFileNames.join(", ")}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* create ".ssh" directory
|
||||
* @returns directory name
|
||||
*/
|
||||
function createSshDirectory(): string {
|
||||
const dirName = getSshDirectory();
|
||||
fs.mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove ".ssh" directory
|
||||
* @returns removed directory name
|
||||
*/
|
||||
function removeSshDirectory(): string {
|
||||
const dirName = getSshDirectory();
|
||||
fs.rmSync(dirName, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* get SSH directory
|
||||
* @returns SSH directory name
|
||||
*/
|
||||
function getSshDirectory(): string {
|
||||
return path.resolve(getHomeDirectory(), ".ssh");
|
||||
}
|
||||
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory name
|
||||
*/
|
||||
function getHomeDirectory(): string {
|
||||
const homeEnv = getHomeEnv();
|
||||
const home = process.env[homeEnv];
|
||||
if (home === undefined) {
|
||||
throw Error(`${homeEnv} is not defined`);
|
||||
}
|
||||
|
||||
if (home === "/github/home") {
|
||||
// Docker container
|
||||
return "/root";
|
||||
}
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
/**
|
||||
* get HOME environment name
|
||||
* @returns HOME environment name
|
||||
*/
|
||||
function getHomeEnv(): string {
|
||||
if (process.platform === "win32") {
|
||||
// Windows
|
||||
return "USERPROFILE";
|
||||
}
|
||||
|
||||
// macOS / Linux
|
||||
return "HOME";
|
||||
}
|
||||
|
||||
/**
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to insert LF
|
||||
|
|
66
src/post.ts
Normal file
66
src/post.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as common from "./common";
|
||||
|
||||
try {
|
||||
post();
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
core.setFailed(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cleanup function
|
||||
*/
|
||||
export function post(): void {
|
||||
const backupSuffix = common.getBackupSuffix();
|
||||
if (backupSuffix === "") {
|
||||
// remove ".ssh" directory if suffix is not set
|
||||
removeSshDirectory();
|
||||
} else {
|
||||
// restore files from backup suffix
|
||||
restore(backupSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove ".ssh" directory
|
||||
*/
|
||||
function removeSshDirectory(): void {
|
||||
const dirName = common.getSshDirectory();
|
||||
fs.rmSync(dirName, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
|
||||
console.log(`SSH key in ${dirName} has been removed successfully.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* restore files from backups
|
||||
* @param backupSuffix suffix of backup directory
|
||||
*/
|
||||
function restore(backupSuffix: string): void {
|
||||
const dirName = common.getSshDirectory();
|
||||
const restoredFileNames: string[] = [];
|
||||
const entries = fs.readdirSync(dirName)
|
||||
.filter((entry) => {
|
||||
// skip if not a backed-up file
|
||||
return entry.endsWith(backupSuffix);
|
||||
});
|
||||
|
||||
for (const entry of entries) {
|
||||
const entryOrg = entry.substring(0, entry.length - backupSuffix.length);
|
||||
const pathNameOrg = path.join(dirName, entryOrg);
|
||||
const pathNameBak = path.join(dirName, entry);
|
||||
|
||||
fs.rmSync(pathNameOrg);
|
||||
fs.renameSync(pathNameBak, pathNameOrg);
|
||||
restoredFileNames.push(entryOrg);
|
||||
}
|
||||
console.log(`Following files in suffix "${backupSuffix}" are restored; ${restoredFileNames.join(", ")}`);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue