1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00

Merge pull request #117 from shimataro/develop

version 2.0.0
This commit is contained in:
shimataro 2020-02-08 19:00:45 +09:00 committed by GitHub
commit 5bd2f032f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 6152 additions and 0 deletions

37
.editorconfig Normal file
View file

@ -0,0 +1,37 @@
# http://editorconfig.org/
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
root = true
# recommended settings; DO NOT CHANGE!
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
# common settings
[*]
indent_style = tab
indent_size = 4
tab_width = 4
max_line_length = off
quote_type = double
curly_bracket_next_line = true
spaces_around_operators = true
spaces_around_brackets = none
indent_brace_style = allman
# JSON/YAML
[*.{json,babelrc,code-workspace,yml,yaml}]
indent_style = space
indent_size = 2
tab_width = 2
# markdown
[*.md]
indent_style = space

305
.eslintrc.yml Normal file
View file

@ -0,0 +1,305 @@
# https://eslint.org/
env: # https://eslint.org/docs/user-guide/configuring#specifying-environments
es6: true
node: true
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
plugins:
- import
- "@typescript-eslint"
parser: "@typescript-eslint/parser"
parserOptions:
sourceType: module
project: ./tsconfig.json
rules: # https://eslint.org/docs/rules/
accessor-pairs: error
array-bracket-newline: error
array-bracket-spacing:
- error
- never
array-callback-return: error
arrow-body-style: 'off'
arrow-parens:
- error
- always
arrow-spacing:
- error
- after: true
before: true
block-scoped-var: error
block-spacing: error
brace-style:
- error
- allman
callback-return: error
capitalized-comments: 'off'
class-methods-use-this: error
comma-dangle:
- error
- always-multiline
comma-spacing:
- error
- after: true
before: false
comma-style:
- error
- last
complexity:
- error
computed-property-spacing:
- error
- never
consistent-return: 'off'
consistent-this: error
curly: error
default-case: 'off'
dot-location:
- error
- property
dot-notation:
- error
- allowKeywords: true
eol-last: error
eqeqeq: error
for-direction: error
func-call-spacing: error
func-name-matching: error
func-names:
- error
- never
func-style:
- error
- declaration
function-paren-newline: error
generator-star-spacing: error
getter-return: error
global-require: error
guard-for-in: error
handle-callback-err: error
id-blacklist: error
id-length: 'off'
id-match: error
implicit-arrow-linebreak:
- error
- below
indent:
- error
- tab
indent-legacy: 'off'
init-declarations: error
jsx-quotes: error
key-spacing: error
keyword-spacing:
- error
- overrides:
if:
after: false
for:
after: false
while:
after: false
catch:
after: false
with:
after: false
line-comment-position: 'off'
linebreak-style:
- error
- unix
lines-around-comment: 'off'
lines-around-directive: error
lines-between-class-members:
- error
- always
max-depth: error
max-len: 'off'
max-lines: 'off'
max-nested-callbacks: error
max-params: 'off'
max-statements: 'off'
max-statements-per-line: error
multiline-comment-style:
- error
- separate-lines
multiline-ternary: error
new-cap: error
new-parens: error
newline-after-var: 'off'
newline-before-return: 'off'
no-alert: error
no-array-constructor: error
no-await-in-loop: error
no-bitwise: error
no-buffer-constructor: error
no-caller: error
no-catch-shadow: error
no-confusing-arrow: error
no-continue: 'off'
no-div-regex: error
no-duplicate-imports: error
no-else-return: 'off'
no-empty-function: 'off'
no-eq-null: error
no-eval: error
no-extend-native: error
no-extra-bind: error
no-extra-label: error
no-extra-parens: error
no-floating-decimal: error
no-implicit-coercion: error
no-implicit-globals: error
no-implied-eval: error
no-inline-comments: 'off'
no-invalid-this: error
no-iterator: error
no-label-var: error
no-labels: error
no-lonely-if: error
no-loop-func: error
no-magic-numbers: 'off'
no-mixed-operators: error
no-mixed-requires: error
no-multi-assign: error
no-multi-spaces: error
no-multi-str: error
no-multiple-empty-lines:
- error
- max: 1
no-native-reassign: error
no-negated-condition: error
no-negated-in-lhs: error
no-nested-ternary: error
no-new: error
no-new-func: error
no-new-object: error
no-new-require: error
no-new-wrappers: error
no-octal-escape: error
no-param-reassign: 'off'
no-path-concat: error
no-plusplus: 'off'
no-process-env: 'off'
no-process-exit: error
no-proto: error
no-prototype-builtins: 'off'
no-restricted-globals: error
no-restricted-imports: error
no-restricted-modules: error
no-restricted-properties: error
no-restricted-syntax: error
no-return-assign: error
no-return-await: error
no-script-url: error
no-self-compare: error
no-sequences: error
no-shadow: error
no-shadow-restricted-names: error
no-spaced-func: error
no-sync: 'off'
no-tabs: 'off'
no-template-curly-in-string: error
no-ternary: error
no-throw-literal: error
no-trailing-spaces: error
no-undef-init: error
no-undefined: 'off'
no-underscore-dangle: 'off'
no-unmodified-loop-condition: error
no-unneeded-ternary: error
no-unused-expressions: error
no-use-before-define: 'off'
no-useless-call: error
no-useless-computed-key: error
no-useless-concat: error
no-useless-constructor: error
no-useless-rename: error
no-useless-return: error
no-var: error
no-void: error
no-warning-comments: error
no-whitespace-before-property: error
no-with: error
nonblock-statement-body-position: error
object-curly-newline: 'off'
object-curly-spacing:
- error
- never
object-property-newline: error
object-shorthand: 'off'
one-var: 'off'
one-var-declaration-per-line: error
operator-assignment: error
operator-linebreak: error
padded-blocks: 'off'
padding-line-between-statements: error
prefer-arrow-callback: error
prefer-const: error
prefer-destructuring: error
prefer-numeric-literals: error
prefer-promise-reject-errors: error
prefer-reflect: error
prefer-rest-params: error
prefer-spread: error
prefer-template: error
quote-props: 'off'
quotes: 'off'
radix: error
require-await: error
require-jsdoc: error
rest-spread-spacing:
- error
- never
semi: error
semi-spacing: error
semi-style:
- error
- last
sort-imports: 'off'
sort-keys: 'off'
sort-vars: error
space-before-blocks: error
space-before-function-paren: 'off'
space-in-parens:
- error
- never
space-infix-ops: error
space-unary-ops: error
spaced-comment:
- error
- always
strict: error
switch-colon-spacing: error
symbol-description: error
template-curly-spacing:
- error
- never
template-tag-spacing: error
unicode-bom:
- error
- never
valid-jsdoc:
- error
- requireParamType: false
requireReturn: false
requireReturnType: false
vars-on-top: error
wrap-iife: error
wrap-regex: error
yield-star-spacing: error
yoda:
- error
- never
# import plugin
import/extensions: 'off'
import/no-unresolved:
- error
# @typescript-eslint plugin
"@typescript-eslint/explicit-function-return-type": 'off'
"@typescript-eslint/no-use-before-define":
- error
- functions: false
"@typescript-eslint/strict-boolean-expressions": error

32
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,32 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
on: push
name: Build
jobs:
build:
name: Build on ${{ matrix.os }} / Node.js v${{ matrix.nodejs }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- Windows-latest
- macOS-latest
- Ubuntu-latest
nodejs:
- 12
fail-fast: false
steps:
- name: Turn off auto-crlf
run: git config --global core.autocrlf false
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.nodejs }}
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Verify
run: npm run verify

41
.github/workflows/verify-on-macos.yml vendored Normal file
View file

@ -0,0 +1,41 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
on: push
name: macOS
jobs:
ssh:
name: Connect to github.com
runs-on: macos-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
ssh-with-name:
name: Connect to github.com with name and config
runs-on: macos-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
name: ssh_key_name # optional
config: | # optional
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/ssh_key_name
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone github:shimataro/ssh-key-action.git tmp

41
.github/workflows/verify-on-ubuntu.yml vendored Normal file
View file

@ -0,0 +1,41 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
on: push
name: Ubuntu
jobs:
ssh:
name: Connect to github.com
runs-on: ubuntu-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
ssh-with-name:
name: Connect to github.com with name and config
runs-on: ubuntu-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
name: ssh_key_name # optional
config: | # optional
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/ssh_key_name
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone github:shimataro/ssh-key-action.git tmp

View file

@ -0,0 +1,41 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
on: push
name: Ubuntu 16.04
jobs:
ssh:
name: Connect to github.com
runs-on: ubuntu-16.04
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
ssh-with-name:
name: Connect to github.com with name and config
runs-on: ubuntu-16.04
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
name: ssh_key_name # optional
config: | # optional
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/ssh_key_name
- name: print created files
run: ls -l ~/.ssh
- name: git clone through SSH
run: git clone github:shimataro/ssh-key-action.git tmp

41
.github/workflows/verify-on-windows.yml vendored Normal file
View file

@ -0,0 +1,41 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
on: push
name: Windows
jobs:
ssh:
name: Connect to github.com
runs-on: windows-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: print created files
run: ls ~/.ssh
- name: git clone through SSH
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
ssh-with-name:
name: Connect to github.com with name and config
runs-on: windows-latest
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install SSH key
uses: ./.
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
name: ssh_key_name # optional
config: | # optional
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/ssh_key_name
- name: print created files
run: ls ~/.ssh
- name: git clone through SSH
run: git clone github:shimataro/ssh-key-action.git tmp

14
.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
# temporary files
*~
*.bak
*.log
*.swp
*.tmp
# image caches
.DS_Store
Thumbs.db
# patch/merge
*.orig
*.rej

7
.markdownlint.yml Normal file
View file

@ -0,0 +1,7 @@
MD007:
indent: 4
MD013:
line_length: 255
MD024:
siblings_only: true
MD026: false

4
.npmrc Normal file
View file

@ -0,0 +1,4 @@
#also=dev
engine-strict=true
heading="🍣"
save-prefix=""

107
CHANGELOG.md Normal file
View file

@ -0,0 +1,107 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [2.0.0] - 2020-02-08
### Changed
* rename `private-key` to `key`
* rename `known-hosts` to `known_hosts`
* make `known_hosts` required
## [1.6.5] - 2020-02-08
### Others
* update version of [Checkout](https://github.com/marketplace/actions/checkout) action
## [1.6.4] - 2020-01-27
### Fixed
* `node_modules/.bin` error (thanks [@george3447](https://github.com/george3447))
## [1.6.3] - 2020-01-27
### Others
* add Q&A
## [1.6.2] - 2020-01-25
### Others
* some updates
## [1.6.1] - 2020-01-19
### Fixed
* Some bugfixes
## [1.6.0] - 2020-01-18
### Changed
* `public-key` is no longer necessarily
## [1.5.0] - 2019/12/30
### Changed
* Append contents of `config` and `known_hosts` when called multiple times.
## [1.4.0] - 2019/12/22
### Added
* `config` option
## [1.3.0] - 2019/09/29
### Added
* `known-hosts` option
## [1.2.0] - 2019/09/22
### Fixed
* CI trigger
* example code in [README](README.md)
### Others
* Install only `dependencies` packages.
## [1.1.0] - 2019/09/19
### Others
* Support Visual Studio Code officially.
* Use GitHub Actions for build test.
## [1.0.0] - 2019/09/18
* First release.
[Unreleased]: https://github.com/shimataro/ssh-key-action/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/shimataro/ssh-key-action/compare/v1.6.5...v2.0.0
[1.6.5]: https://github.com/shimataro/ssh-key-action/compare/v1.6.4...v1.6.5
[1.6.4]: https://github.com/shimataro/ssh-key-action/compare/v1.6.3...v1.6.4
[1.6.3]: https://github.com/shimataro/ssh-key-action/compare/v1.6.2...v1.6.3
[1.6.2]: https://github.com/shimataro/ssh-key-action/compare/v1.6.1...v1.6.2
[1.6.1]: https://github.com/shimataro/ssh-key-action/compare/v1.6.0...v1.6.1
[1.6.0]: https://github.com/shimataro/ssh-key-action/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/shimataro/ssh-key-action/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/shimataro/ssh-key-action/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/shimataro/ssh-key-action/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/shimataro/ssh-key-action/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/shimataro/ssh-key-action/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/shimataro/ssh-key-action/compare/8deacc95b1ee5732107e56baa4c8aac4c386ef7e...v1.0.0

141
README.md Normal file
View file

@ -0,0 +1,141 @@
# Install SSH Key
[![Build][image-build]][link-build]
[![Windows][image-verify-windows]][link-verify-windows]
[![macOS][image-verify-macos]][link-verify-macos]
[![Ubuntu][image-verify-ubuntu]][link-verify-ubuntu]
[![Ubuntu 16.04][image-verify-ubuntu1604]][link-verify-ubuntu1604]
[![Release][image-release]][link-release]
[![License][image-license]][link-license]
[![Stars][image-stars]][link-stars]
This action installs SSH key in `~/.ssh`.
Useful for SCP, SFTP, and `rsync` over SSH in deployment script.
**Works on all [virtual environment](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources) -- Windows, macOS, Ubuntu and Ubuntu 16.04.**
## Usage
Add your SSH key to your product secrets by clicking `Settings` - `Secrets` - `Add a new secret` beforehand.
**NOTE:** OPENSSH format (key begins with `-----BEGIN OPENSSH PRIVATE KEY-----`) may not work due to OpenSSH version on VM. Please use PEM format (begins with `-----BEGIN RSA PRIVATE KEY-----`) instead.
```yaml
runs-on: ubuntu-latest
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
name: id_rsa # optional
known_hosts: ${{ secrets.KNOWN_HOSTS }}
config: ${{ secrets.CONFIG }} # ssh_config; optional
- name: rsync over ssh
run: rsync ./foo/ user@remote:bar/
```
See [Workflow syntax for GitHub Actions](https://help.github.com/en/articles/workflow-syntax-for-github-actions) for details.
### Install multiple keys
If you want to install multiple keys, call this action multiple times.
It is useful for port forwarding.
**NOTE:** When this action is called multiple times, **the contents of `known_hosts` and `config` will be appended**. `key` must be saved as different name, by using `name` option.
```yaml
runs-on: ubuntu-latest
steps:
- name: Install SSH key of bastion
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY_OF_BASTION }}
name: id_rsa-bastion
known_hosts: ${{ secrets.KNOWN_HOSTS_OF_BASTION }}
config: |
Host bastion
HostName xxx.xxx.xxx.xxx
User user-of-bastion
IdentityFile ~/.ssh/id_rsa-bastion
- name: Install SSH key of target
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY_OF_TARGET }}
name: id_rsa-target
known_hosts: ${{ secrets.KNOWN_HOSTS_OF_TARGET }} # will be appended!
config: | # will be appended!
Host target
HostName yyy.yyy.yyy.yyy
User user-of-target
IdentityFile ~/.ssh/id_rsa-target
ProxyCommand ssh -W %h:%p bastion
- name: SCP via port-forwarding
run: scp ./foo/ target:bar/
```
## Q&A
### SSH failed even though key has been installed.
Check belows:
* `Load key "/HOME/.ssh/id_rsa": invalid format`:
* OPENSSH format (key begins with `-----BEGIN OPENSSH PRIVATE KEY-----`) may not work.
* Use PEM format (begins with `-----BEGIN RSA PRIVATE KEY-----`).
* `Host key verification failed.`:
* Set `known_hosts` option correctly (use `ssh-keyscan` command).
### How do I use encrypted SSH key?
This action doesn't support encrypted key directly.
Here are some solutions:
* decrypting key beforehand: best bet, and works on any VM
* `sshpass` command: next best bet, but not supported on Windows
* `expect` command: be careful not to expose passphrase to console
* `SSH_ASKPASS` environment variable: might be troublesome
### Which one is the best way for transferring files, "direct SCP/SFTP/rsync" or "SCP/SFTP/rsync via bastion"?
I recommend **rsync via bastion**.
It has some advantages over other methods:
* "Rsync via bastion" doesn't require to update workflow files and `secrets` even if it is necessary to transfer files to multiple servers.
* Other methods require to update `known_hosts` if servers have changed.
* Rsync:
* is fastest of all.
* does **NOT** break files even if disconnected during transferring.
* can remove files that don't exist on server.
* SCP is [deprecated by OpenSSH](https://www.openssh.com/txt/release-8.0) due to outdated and inflexible protocol.
* Using bastion is more secure because:
* it is not necessarily to expose SSH port on servers to public.
* Address filtering is less effective.
* Because Azure address range is [very wide](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#ip-addresses-of-github-hosted-runners).
* And will be updated continuously.
* if security incident ―e.g., private key leaked― occurs, it's OK just to remove `authorized_keys` on bastion.
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
## Changelog
See [CHANGELOG.md](CHANGELOG.md).
[image-build]: https://github.com/shimataro/ssh-key-action/workflows/Build/badge.svg?event=push&branch=v2
[link-build]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3ABuild
[image-verify-windows]: https://github.com/shimataro/ssh-key-action/workflows/Windows/badge.svg?event=push&branch=v2
[link-verify-windows]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3AWindows
[image-verify-macos]: https://github.com/shimataro/ssh-key-action/workflows/macOS/badge.svg?event=push&branch=v2
[link-verify-macos]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3AmacOS
[image-verify-ubuntu]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu/badge.svg?event=push&branch=v2
[link-verify-ubuntu]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3AUbuntu
[image-verify-ubuntu1604]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu%2016.04/badge.svg?event=push&branch=v2
[link-verify-ubuntu1604]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Ubuntu+16.04%22
[image-release]: https://img.shields.io/github/release/shimataro/ssh-key-action.svg
[link-release]: https://github.com/shimataro/ssh-key-action/releases
[image-license]: https://img.shields.io/github/license/shimataro/ssh-key-action.svg
[link-license]: ./LICENSE
[image-stars]: https://img.shields.io/github/stars/shimataro/ssh-key-action.svg
[link-stars]: https://github.com/shimataro/ssh-key-action/stargazers

26
action.yml Normal file
View file

@ -0,0 +1,26 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: "Install SSH Key"
description: "Install SSH key in ~/.ssh"
author: "shimataro"
branding:
icon: "terminal"
color: "gray-dark"
inputs:
key:
description: "SSH private key"
required: true
name:
description: "SSH key file name (default: id_rsa)"
required: false
default: "id_rsa"
known_hosts:
description: "public keys of SSH servers"
required: true
default: ""
config:
description: "SSH config"
required: false
default: ""
runs:
using: "node12"
main: "lib/main.js"

106
lib/main.js Normal file
View file

@ -0,0 +1,106 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
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_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const core = __importStar(require("@actions/core"));
/**
* main function
*/
function main() {
try {
const files = [
{
name: core.getInput("name"),
contents: core.getInput("key", {
required: true,
}),
options: {
mode: 0o400,
flag: "ax",
},
},
{
name: "known_hosts",
contents: prependLf(core.getInput("known_hosts", {
required: true,
})),
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_1.default.resolve(home, ".ssh");
fs_1.default.mkdirSync(dirName, {
recursive: true,
mode: 0o700,
});
// create files
for (const file of files) {
const fileName = path_1.default.join(dirName, file.name);
fs_1.default.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 = getHomeEnv();
const home = process.env[homeEnv];
if (home === undefined) {
throw Error(`${homeEnv} is not defined`);
}
return home;
}
/**
* get HOME environment name
* @returns HOME environment name
*/
function getHomeEnv() {
if (process.platform === "win32") {
// Windows
return "USERPROFILE";
}
// macOS / Linux
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

1
lib/main.js.map Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,oDAAsC;AAStC;;GAEG;AACH,SAAS,IAAI;IAEZ,IACA;QACC,MAAM,KAAK,GAAe;YACzB;gBACC,IAAI,EAAE,IA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AS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KAC5B;AACF,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB;IAExB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,IAAG,IAAI,KAAK,SAAS,EACrB;QACC,MAAM,KAAK,CAAC,GAAG,OAAO,iBAAiB,CAAC,CAAC;KACzC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU;IAElB,IAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,EAC/B;QACC,UAAU;QACV,OAAO,aAAa,CAAC;KACrB;IAED,gBAAgB;IAChB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAa;IAE/B,IAAG,KAAK,CAAC,MAAM,KAAK,CAAC,EACrB;QACC,sBAAsB;QACtB,OAAO,EAAE,CAAC;KACV;IAED,OAAO,KAAK,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,IAAI,EAAE,CAAC"}

140
node_modules/@actions/core/README.md generated vendored Normal file
View file

@ -0,0 +1,140 @@
# `@actions/core`
> Core functions for setting results, logging, registering secrets and exporting variables across actions
## Usage
### Import the package
```js
// javascript
const core = require('@actions/core');
// typescript
import * as core from '@actions/core';
```
#### Inputs/Outputs
Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
```js
const myInput = core.getInput('inputName', { required: true });
core.setOutput('outputKey', 'outputVal');
```
#### Exporting variables
Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
```js
core.exportVariable('envVar', 'Val');
```
#### Setting a secret
Setting a secret registers the secret with the runner to ensure it is masked in logs.
```js
core.setSecret('myPassword');
```
#### PATH Manipulation
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
```js
core.addPath('/path/to/mytool');
```
#### Exit codes
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
```js
const core = require('@actions/core');
try {
// Do stuff
}
catch (err) {
// setFailed logs the message and sets a failing exit code
core.setFailed(`Action failed with error ${err}`);
}
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
```
#### Logging
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
```js
const core = require('@actions/core');
const myInput = core.getInput('input');
try {
core.debug('Inside try block');
if (!myInput) {
core.warning('myInput was not set');
}
// Do stuff
}
catch (err) {
core.error(`Error ${err}, action may still succeed though`);
}
```
This library can also wrap chunks of output in foldable groups.
```js
const core = require('@actions/core')
// Manually wrap output
core.startGroup('Do some function')
doSomeFunction()
core.endGroup()
// Wrap an asynchronous function call
const result = await core.group('Do something async', async () => {
const response = await doSomeHTTPRequest()
return response
})
```
#### Action state
You can use this library to save state and get state for sharing information between a given wrapper action:
**action.yml**
```yaml
name: 'Wrapper action sample'
inputs:
name:
default: 'GitHub'
runs:
using: 'node12'
main: 'main.js'
post: 'cleanup.js'
```
In action's `main.js`:
```js
const core = require('@actions/core');
core.saveState("pidToKill", 12345);
```
In action's `cleanup.js`:
```js
const core = require('@actions/core');
var pid = core.getState("pidToKill");
process.kill(pid);
```

16
node_modules/@actions/core/lib/command.d.ts generated vendored Normal file
View file

@ -0,0 +1,16 @@
interface CommandProperties {
[key: string]: string;
}
/**
* Commands
*
* Command Format:
* ::name key=value,key=value::message
*
* Examples:
* ::warning::This is the message
* ::set-env name=MY_VAR::some value
*/
export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
export declare function issue(name: string, message?: string): void;
export {};

78
node_modules/@actions/core/lib/command.js generated vendored Normal file
View file

@ -0,0 +1,78 @@
"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 os = __importStar(require("os"));
/**
* Commands
*
* Command Format:
* ::name key=value,key=value::message
*
* Examples:
* ::warning::This is the message
* ::set-env name=MY_VAR::some value
*/
function issueCommand(command, properties, message) {
const cmd = new Command(command, properties, message);
process.stdout.write(cmd.toString() + os.EOL);
}
exports.issueCommand = issueCommand;
function issue(name, message = '') {
issueCommand(name, {}, message);
}
exports.issue = issue;
const CMD_STRING = '::';
class Command {
constructor(command, properties, message) {
if (!command) {
command = 'missing.command';
}
this.command = command;
this.properties = properties;
this.message = message;
}
toString() {
let cmdStr = CMD_STRING + this.command;
if (this.properties && Object.keys(this.properties).length > 0) {
cmdStr += ' ';
let first = true;
for (const key in this.properties) {
if (this.properties.hasOwnProperty(key)) {
const val = this.properties[key];
if (val) {
if (first) {
first = false;
}
else {
cmdStr += ',';
}
cmdStr += `${key}=${escapeProperty(val)}`;
}
}
}
}
cmdStr += `${CMD_STRING}${escapeData(this.message)}`;
return cmdStr;
}
}
function escapeData(s) {
return (s || '')
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
}
function escapeProperty(s) {
return (s || '')
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
.replace(/:/g, '%3A')
.replace(/,/g, '%2C');
}
//# sourceMappingURL=command.js.map

1
node_modules/@actions/core/lib/command.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwB;AAQxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,M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I,GAAG,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;QACpD,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;SACb,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,cAAc,CAAC,CAAS;IAC/B,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;SACb,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}

112
node_modules/@actions/core/lib/core.d.ts generated vendored Normal file
View file

@ -0,0 +1,112 @@
/**
* Interface for getInput options
*/
export interface InputOptions {
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
required?: boolean;
}
/**
* The code to exit an action
*/
export declare enum ExitCode {
/**
* A code indicating that the action was successful
*/
Success = 0,
/**
* A code indicating that the action was a failure
*/
Failure = 1
}
/**
* Sets env variable for this action and future actions in the job
* @param name the name of the variable to set
* @param val the value of the variable
*/
export declare function exportVariable(name: string, val: string): void;
/**
* Registers a secret which will get masked from logs
* @param secret value of the secret
*/
export declare function setSecret(secret: string): void;
/**
* Prepends inputPath to the PATH (for this action and future actions)
* @param inputPath
*/
export declare function addPath(inputPath: string): void;
/**
* Gets the value of an input. The value is also trimmed.
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns string
*/
export declare function getInput(name: string, options?: InputOptions): string;
/**
* Sets the value of an output.
*
* @param name name of the output to set
* @param value value to store
*/
export declare function setOutput(name: string, value: string): void;
/**
* Sets the action status to failed.
* When the action exits it will be with an exit code of 1
* @param message add error issue message
*/
export declare function setFailed(message: string): void;
/**
* Writes debug message to user log
* @param message debug message
*/
export declare function debug(message: string): void;
/**
* Adds an error issue
* @param message error issue message
*/
export declare function error(message: string): void;
/**
* Adds an warning issue
* @param message warning issue message
*/
export declare function warning(message: string): void;
/**
* Writes info to log with console.log.
* @param message info message
*/
export declare function info(message: string): void;
/**
* Begin an output group.
*
* Output until the next `groupEnd` will be foldable in this group
*
* @param name The name of the output group
*/
export declare function startGroup(name: string): void;
/**
* End an output group.
*/
export declare function endGroup(): void;
/**
* Wrap an asynchronous function call in a group.
*
* Returns the same type as the function itself.
*
* @param name The name of the group
* @param fn The function to wrap in the group
*/
export declare function group<T>(name: string, fn: () => Promise<T>): Promise<T>;
/**
* Saves state for current action, the state can only be retrieved by this action's post job execution.
*
* @param name name of the state to store
* @param value value to store
*/
export declare function saveState(name: string, value: string): void;
/**
* Gets the value of an state set by this action's main execution.
*
* @param name name of the state to get
* @returns string
*/
export declare function getState(name: string): string;

202
node_modules/@actions/core/lib/core.js generated vendored Normal file
View file

@ -0,0 +1,202 @@
"use strict";
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());
});
};
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 command_1 = require("./command");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
/**
* The code to exit an action
*/
var ExitCode;
(function (ExitCode) {
/**
* A code indicating that the action was successful
*/
ExitCode[ExitCode["Success"] = 0] = "Success";
/**
* A code indicating that the action was a failure
*/
ExitCode[ExitCode["Failure"] = 1] = "Failure";
})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
//-----------------------------------------------------------------------
// Variables
//-----------------------------------------------------------------------
/**
* Sets env variable for this action and future actions in the job
* @param name the name of the variable to set
* @param val the value of the variable
*/
function exportVariable(name, val) {
process.env[name] = val;
command_1.issueCommand('set-env', { name }, val);
}
exports.exportVariable = exportVariable;
/**
* Registers a secret which will get masked from logs
* @param secret value of the secret
*/
function setSecret(secret) {
command_1.issueCommand('add-mask', {}, secret);
}
exports.setSecret = setSecret;
/**
* Prepends inputPath to the PATH (for this action and future actions)
* @param inputPath
*/
function addPath(inputPath) {
command_1.issueCommand('add-path', {}, inputPath);
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
}
exports.addPath = addPath;
/**
* Gets the value of an input. The value is also trimmed.
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns string
*/
function getInput(name, options) {
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
}
return val.trim();
}
exports.getInput = getInput;
/**
* Sets the value of an output.
*
* @param name name of the output to set
* @param value value to store
*/
function setOutput(name, value) {
command_1.issueCommand('set-output', { name }, value);
}
exports.setOutput = setOutput;
//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
/**
* Sets the action status to failed.
* When the action exits it will be with an exit code of 1
* @param message add error issue message
*/
function setFailed(message) {
process.exitCode = ExitCode.Failure;
error(message);
}
exports.setFailed = setFailed;
//-----------------------------------------------------------------------
// Logging Commands
//-----------------------------------------------------------------------
/**
* Writes debug message to user log
* @param message debug message
*/
function debug(message) {
command_1.issueCommand('debug', {}, message);
}
exports.debug = debug;
/**
* Adds an error issue
* @param message error issue message
*/
function error(message) {
command_1.issue('error', message);
}
exports.error = error;
/**
* Adds an warning issue
* @param message warning issue message
*/
function warning(message) {
command_1.issue('warning', message);
}
exports.warning = warning;
/**
* Writes info to log with console.log.
* @param message info message
*/
function info(message) {
process.stdout.write(message + os.EOL);
}
exports.info = info;
/**
* Begin an output group.
*
* Output until the next `groupEnd` will be foldable in this group
*
* @param name The name of the output group
*/
function startGroup(name) {
command_1.issue('group', name);
}
exports.startGroup = startGroup;
/**
* End an output group.
*/
function endGroup() {
command_1.issue('endgroup');
}
exports.endGroup = endGroup;
/**
* Wrap an asynchronous function call in a group.
*
* Returns the same type as the function itself.
*
* @param name The name of the group
* @param fn The function to wrap in the group
*/
function group(name, fn) {
return __awaiter(this, void 0, void 0, function* () {
startGroup(name);
let result;
try {
result = yield fn();
}
finally {
endGroup();
}
return result;
});
}
exports.group = group;
//-----------------------------------------------------------------------
// Wrapper action state
//-----------------------------------------------------------------------
/**
* Saves state for current action, the state can only be retrieved by this action's post job execution.
*
* @param name name of the state to store
* @param value value to store
*/
function saveState(name, value) {
command_1.issueCommand('save-state', { name }, value);
}
exports.saveState = saveState;
/**
* Gets the value of an state set by this action's main execution.
*
* @param name name of the state to get
* @returns string
*/
function getState(name) {
return process.env[`STATE_${name}`] || '';
}
exports.getState = getState;
//# sourceMappingURL=core.js.map

1
node_modules/@actions/core/lib/core.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAA6C;AAE7C,uCAAwB;AACxB,2CAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;G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EAAyE;AAEzE;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,sBAAY,CAAC,YAAY,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,8BAEC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACnC,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;AAC3C,CAAC;AAFD,4BAEC"}

44
node_modules/@actions/core/package.json generated vendored Normal file
View file

@ -0,0 +1,44 @@
{
"name": "@actions/core",
"version": "1.2.2",
"description": "Actions core lib",
"keywords": [
"github",
"actions",
"core"
],
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
"license": "MIT",
"main": "lib/core.js",
"types": "lib/core.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/toolkit.git",
"directory": "packages/core"
},
"scripts": {
"audit-moderate": "npm install && npm audit --audit-level=moderate",
"test": "echo \"Error: run tests from root\" && exit 1",
"tsc": "tsc"
},
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"devDependencies": {
"@types/node": "^12.0.2"
}
,"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz"
,"_integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg=="
,"_from": "@actions/core@1.2.2"
}

4087
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

48
package.json Normal file
View file

@ -0,0 +1,48 @@
{
"name": "install-ssh-key",
"version": "2.0.0",
"private": true,
"description": "Install SSH key in .ssh",
"main": "lib/main.js",
"engines": {
"node": ">=8.0.0",
"npm": ">=5.7.0"
},
"scripts": {
"build": "tsc",
"check-updates": "ncu",
"lint": "run-p lint:*",
"lint:ts": "eslint ./src --ext .ts",
"lint:md": "markdownlint . --ignore node_modules --ignore examples",
"lint:yaml": "yamllint **/{,.}*.{yml,yaml} --ignore=node_modules/**",
"verify": "run-p lint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/shimataro/ssh-key-action.git"
},
"keywords": [
"actions",
"github actions",
"rsync",
"ssh",
"ssh key"
],
"author": "shimataro",
"license": "MIT",
"dependencies": {
"@actions/core": "1.2.2"
},
"devDependencies": {
"@types/node": "13.7.0",
"@typescript-eslint/eslint-plugin": "2.19.0",
"@typescript-eslint/parser": "2.19.0",
"eslint": "6.8.0",
"eslint-plugin-import": "2.20.1",
"markdownlint-cli": "0.21.0",
"npm-check-updates": "4.0.1",
"npm-run-all": "4.1.5",
"typescript": "3.7.5",
"yaml-lint": "1.2.4"
}
}

133
scripts/create-release-branch.sh Executable file
View file

@ -0,0 +1,133 @@
#!/bin/bash
# requires following packages:
# - git; I believe it's already installed.
# - sed; GNU sed is preferred. POSIX sed may not work.
set -e
BASE_BRANCH="develop"
PACKAGE_NAME="ssh-key-action"
URL_PRODUCT="https://github.com/shimataro/${PACKAGE_NAME}"
URL_REPOSITORY="${URL_PRODUCT}.git"
URL_COMPARE="${URL_PRODUCT}/compare"
URL_RELEASE="${URL_PRODUCT}/releases/new"
COLOR_ERROR="\e[1;41m"
COLOR_SECTION="\e[1;34m"
COLOR_COMMAND_NAME="\e[1;34m"
COLOR_OPTION="\e[4;36m"
COLOR_COMMAND="\e[4m"
COLOR_FILE="\e[1;34m"
COLOR_BRANCH="\e[1;31m"
COLOR_INPUT="\e[1;31m"
COLOR_SELECT="\e[1;32m"
COLOR_RESET="\e[m"
function main() {
cd $(dirname ${0})/..
if [ $# -lt 1 ]; then
usage
fi
local VERSION=$1
local BRANCH="release/v${VERSION}"
local TAG="v${VERSION}"
check_version_format ${VERSION}
check_current_branch
create_branch ${BRANCH}
./scripts/prepare-release.sh ${VERSION}
finish ${VERSION} ${BRANCH} ${TAG}
}
function usage() {
local COMMAND=`basename ${0}`
echo -e "${COLOR_SECTION}NAME${COLOR_RESET}
${COMMAND} - Create a branch and prepare for new release
${COLOR_SECTION}SYNOPSIS${COLOR_RESET}
${COLOR_COMMAND_NAME}${COMMAND}${COLOR_RESET} <${COLOR_OPTION}new-version${COLOR_RESET}>
${COLOR_SECTION}DESCRIPTION${COLOR_RESET}
This command:
- creates a new branch for release
- updates ${COLOR_FILE}CHANGELOG.md${COLOR_RESET}
- updates package version in ${COLOR_FILE}package.json${COLOR_RESET}
- updates dependencies version in ${COLOR_FILE}package.json${COLOR_RESET}
- verifies
- ...and commits!
${COLOR_OPTION}new-version${COLOR_RESET} must follow \"Semantic Versioning\" <https://semver.org/>.
"
exit 1
}
function check_version_format() {
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
return
fi
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Follow \"Semantic Versioning\" <https://semver.org/> for new version.
" >&2
exit 2
}
function check_current_branch() {
local CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ ${CURRENT_BRANCH} = ${BASE_BRANCH} ]; then
return
fi
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Work on ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} branch
${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET}
" >&2
exit 2
}
function create_branch() {
local BRANCH=$1
git checkout -b ${BRANCH} ${BASE_BRANCH}
}
function finish() {
local VERSION=$1
local BRANCH=$2
local TAG=$3
local TARGET_BRANCH="v${VERSION%%[!0-9]*}"
echo -e "
Branch ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} has been created.
Remaining processes are...
1. Make sure all changes are correct
${COLOR_COMMAND}git diff ${BASE_BRANCH} ${BRANCH}${COLOR_RESET}
2. Push to remote origin
${COLOR_COMMAND}git push --set-upstream origin ${BRANCH}${COLOR_RESET}
3. Create a pull-request: ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET}
${URL_COMPARE}/${BASE_BRANCH}...${BRANCH}?expand=1
select ${COLOR_SELECT}Squash and merge${COLOR_RESET}
4. Create a pull-request: ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}${TARGET_BRANCH}${COLOR_RESET}
${URL_COMPARE}/${TARGET_BRANCH}...${BASE_BRANCH}?expand=1&title=version%20${VERSION}
select ${COLOR_SELECT}Create a merge commit${COLOR_RESET}
5. Create a new release
${URL_RELEASE}?tag=${TAG}&target=${TARGET_BRANCH}&title=${PACKAGE_NAME}%20${VERSION}%20released
Tag version: ${COLOR_INPUT}${TAG}${COLOR_RESET}
Target: ${COLOR_INPUT}${TARGET_BRANCH}${COLOR_RESET}
Release title: ${COLOR_INPUT}${PACKAGE_NAME} ${VERSION} released${COLOR_RESET}
Description this release: (copy and paste CHANGELOG.md)
6. Post processing
${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET}
${COLOR_COMMAND}git pull${COLOR_RESET}
${COLOR_COMMAND}git fetch -p${COLOR_RESET}
${COLOR_COMMAND}git branch -D ${BRANCH}${COLOR_RESET}
That's all!
"
}
main "$@"

112
scripts/prepare-release.sh Executable file
View file

@ -0,0 +1,112 @@
#!/bin/bash
# requires following packages:
# - git; I believe it's already installed.
# - sed; GNU sed is preferred. POSIX sed may not work.
set -e
COLOR_ERROR="\e[1;41m"
COLOR_SECTION="\e[1;34m"
COLOR_COMMAND_NAME="\e[1;34m"
COLOR_OPTION="\e[4;36m"
COLOR_COMMAND="\e[4m"
COLOR_FILE="\e[1;34m"
COLOR_BRANCH="\e[1;31m"
COLOR_INPUT="\e[1;31m"
COLOR_SELECT="\e[1;32m"
COLOR_RESET="\e[m"
function main() {
if [ $# -lt 1 ]; then
usage
fi
cd $(dirname ${0})/..
local VERSION=$1
check_version_format ${VERSION}
update_changelog ${VERSION}
update_package_version ${VERSION}
update_dependencies_version
regenerate_package_lock
build_package
commit_changes ${VERSION}
}
function usage() {
local COMMAND=`basename ${0}`
echo -e "${COLOR_SECTION}NAME${COLOR_RESET}
${COMMAND} - Prepare for new release
${COLOR_SECTION}SYNOPSIS${COLOR_RESET}
${COLOR_COMMAND_NAME}${COMMAND}${COLOR_RESET} <${COLOR_OPTION}new-version${COLOR_RESET}>
${COLOR_SECTION}DESCRIPTION${COLOR_RESET}
This command:
- updates ${COLOR_FILE}CHANGELOG.md${COLOR_RESET}
- updates package version in ${COLOR_FILE}package.json${COLOR_RESET}
- updates dependencies version in ${COLOR_FILE}package.json${COLOR_RESET}
- verifies
- ...and commits!
${COLOR_OPTION}new-version${COLOR_RESET} must follow \"Semantic Versioning\" <https://semver.org/>.
"
exit 1
}
function check_version_format() {
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
return
fi
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Follow \"Semantic Versioning\" <https://semver.org/> for new version.
" >&2
exit 2
}
function update_changelog() {
local VERSION=$1
local DATE=`date "+%Y-%m-%d"`
local KEYWORD="Unreleased"
sed -i".bak" -r \
-e "s/^((##\s+)\[${KEYWORD}\])$/\1\n\n\2[${VERSION}] - ${DATE}/" \
-e "s/^(\[${KEYWORD}\](.*))(v.*)\.\.\.HEAD$/\1v${VERSION}...HEAD\n[${VERSION}]\2\3...v${VERSION}/" \
CHANGELOG.md
}
function update_package_version() {
local VERSION=$1
sed -i".bak" -r \
-e "s/(\"version\"\s*:\s*)\".*?\"/\1\"${VERSION}\"/" \
package.json
}
function update_dependencies_version() {
npm ci
npm run check-updates -- -u
}
function regenerate_package_lock() {
rm -rf package-lock.json node_modules
npm install
}
function build_package() {
npm run build
npm run verify
}
function commit_changes() {
local VERSION=$1
rm -rf node_modules
npm ci --only=production
git add CHANGELOG.md package.json package-lock.json node_modules lib
git commit -m "version ${VERSION}"
}
main "$@"

12
scripts/rebuild.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
set -e
rm -rf node_modules package-lock.json
npm i
npm run build
npm run verify
rm -rf node_modules
npm ci --only=production
git add node_modules package-lock.json lib

40
scripts/update-dependencies.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
# update dependencies
set -e
DATE=$(date +"%Y%m%d")
BRANCH=feature/update-dependencies-${DATE}
COLOR_SUCCESS="\e[1;32m"
COLOR_RESET="\e[m"
# create branch
git checkout develop
git checkout -b ${BRANCH}
# check updates
npm ci
npm run check-updates -- -u
# re-install packages
rm -rf package-lock.json node_modules
npm i
# check
npm run build
npm run verify
# commit
rm -rf node_modules
npm ci --only=production
git add package.json package-lock.json node_modules
git commit -m "update dependencies"
# finished!
echo -e "
${COLOR_SUCCESS}🎉All dependencies are updated successfully.🎉${COLOR_RESET}
Push changes and merge into 'develop' branch.
git push --set-upstream origin ${BRANCH}
"

122
src/main.ts Normal file
View file

@ -0,0 +1,122 @@
import fs from "fs";
import path from "path";
import * as core from "@actions/core";
interface FileInfo
{
name: string;
contents: string;
options: fs.WriteFileOptions;
}
/**
* main function
*/
function main(): void
{
try
{
const files: FileInfo[] = [
{
name: core.getInput("name"),
contents: core.getInput("key", {
required: true,
}),
options: {
mode: 0o400,
flag: "ax",
},
},
{
name: "known_hosts",
contents: prependLf(core.getInput("known_hosts", {
required: true,
})),
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(): string
{
const homeEnv = getHomeEnv();
const home = process.env[homeEnv];
if(home === undefined)
{
throw Error(`${homeEnv} is not defined`);
}
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 LF to value if not empty
* @param value the value to prepend LF
* @returns prepended value
*/
function prependLf(value: string): string
{
if(value.length === 0)
{
// do nothing if empty
return "";
}
return `\n${value}`;
}
main();

View file

@ -0,0 +1,31 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"eslint.enable": true,
"json.format.enable": true,
"typescript.format.enable": true,
"typescript.format.insertSpaceAfterCommaDelimiter": true,
"typescript.format.insertSpaceAfterConstructor": false,
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": false,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"typescript.format.insertSpaceAfterSemicolonInForStatements": true,
"typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
"typescript.format.insertSpaceBeforeFunctionParenthesis": false,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.validate.enable": true
},
"extensions": {
"recommendations": [
"EditorConfig.EditorConfig",
"eg2.vscode-npm-script"
]
}
}

29
tsconfig.json Normal file
View file

@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
},
"exclude": ["node_modules", "**/*.test.ts"]
}