mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Feature/centos (#176)
* check on CentOS container * update README * update links * update CHANGELOG * refactor insertLf()
This commit is contained in:
parent
cdcc4725b3
commit
68b956be12
6 changed files with 137 additions and 57 deletions
95
.github/workflows/verify-on-container-centos.yml
vendored
Normal file
95
.github/workflows/verify-on-container-centos.yml
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
|
||||
|
||||
name: Docker container (CentOS)
|
||||
|
||||
on:
|
||||
- push
|
||||
|
||||
jobs:
|
||||
ssh-pem:
|
||||
name: Connect to github.com (PEM format)
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-16.04
|
||||
- ubuntu-18.04
|
||||
- ubuntu-20.04
|
||||
container:
|
||||
- centos:7
|
||||
- centos:8
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Install packages
|
||||
run: |
|
||||
yum install -y git openssh-clients
|
||||
- name: Checkout source codes
|
||||
uses: actions/checkout@v2
|
||||
- name: Install SSH key
|
||||
uses: ./.
|
||||
with:
|
||||
key: ${{ secrets.SSH_KEY_PEM }}
|
||||
known_hosts: ${{ secrets.KNOWN_HOSTS }}
|
||||
- name: print created files
|
||||
run: ls -l /root/.ssh
|
||||
- name: git clone through SSH
|
||||
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
|
||||
ssh-pkcs8:
|
||||
name: Connect to github.com (PKCS8 format)
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-16.04
|
||||
- ubuntu-18.04
|
||||
- ubuntu-20.04
|
||||
container:
|
||||
- centos:7
|
||||
- centos:8
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Install packages
|
||||
run: |
|
||||
yum install -y git openssh-clients
|
||||
- name: Checkout source codes
|
||||
uses: actions/checkout@v2
|
||||
- name: Install SSH key
|
||||
uses: ./.
|
||||
with:
|
||||
key: ${{ secrets.SSH_KEY_PKCS8 }}
|
||||
known_hosts: ${{ secrets.KNOWN_HOSTS }}
|
||||
- name: print created files
|
||||
run: ls -l /root/.ssh
|
||||
- name: git clone through SSH
|
||||
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
|
||||
ssh-rfc4716:
|
||||
name: Connect to github.com (RFC4716 format)
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-16.04
|
||||
- ubuntu-18.04
|
||||
- ubuntu-20.04
|
||||
container:
|
||||
- centos:7
|
||||
- centos:8
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Install packages
|
||||
run: |
|
||||
yum install -y git openssh-clients
|
||||
- name: Checkout source codes
|
||||
uses: actions/checkout@v2
|
||||
- name: Install SSH key
|
||||
uses: ./.
|
||||
with:
|
||||
key: ${{ secrets.SSH_KEY_RFC4716 }}
|
||||
known_hosts: ${{ secrets.KNOWN_HOSTS }}
|
||||
- name: print created files
|
||||
run: ls -l /root/.ssh
|
||||
- name: git clone through SSH
|
||||
run: git clone git@github.com:shimataro/ssh-key-action.git tmp
|
|
@ -1,6 +1,6 @@
|
|||
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
|
||||
|
||||
name: Docker container
|
||||
name: Docker container (Ubuntu)
|
||||
|
||||
on:
|
||||
- push
|
|
@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
### Added
|
||||
|
||||
* Support Docker container (thanks [@kujaomega](https://github.com/kujaomega))
|
||||
* Support Ubuntu/CentOS Docker container (thanks [@kujaomega](https://github.com/kujaomega))
|
||||
* Support PKCS8/RFC4716 formats (thanks [@tats-u](https://github.com/tats-u))
|
||||
|
||||
### Changed
|
||||
|
|
28
README.md
28
README.md
|
@ -6,7 +6,8 @@
|
|||
[![Ubuntu 20.04][image-verify-ubuntu-2004]][link-verify-ubuntu-2004]
|
||||
[![Ubuntu 18.04][image-verify-ubuntu-1804]][link-verify-ubuntu-1804]
|
||||
[![Ubuntu 16.04][image-verify-ubuntu-1604]][link-verify-ubuntu-1604]
|
||||
[![Docker container][image-verify-docker-container]][link-verify-docker-container]
|
||||
[![Docker container (Ubuntu)][image-verify-docker-container-ubuntu]][link-verify-docker-container-ubuntu]
|
||||
[![Docker container (CentOS)][image-verify-docker-container-centos]][link-verify-docker-container-centos]
|
||||
[![Release][image-release]][link-release]
|
||||
[![License][image-license]][link-license]
|
||||
[![Stars][image-stars]][link-stars]
|
||||
|
@ -15,10 +16,11 @@ This action installs SSH key in `~/.ssh`.
|
|||
|
||||
Useful for SCP, SFTP, and `rsync` over SSH in deployment script.
|
||||
|
||||
works on:
|
||||
tested on:
|
||||
|
||||
* all [virtual machines](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources) (Windows Server 2019, macOS Catalina, and Ubuntu 20.04/18.04/16.04)
|
||||
* [Docker container](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer) (needs `openssh-client` package)
|
||||
* [all available virtual machines](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources) (Windows Server 2019, macOS Catalina, and Ubuntu 20.04/18.04/16.04)
|
||||
* [Docker container (Ubuntu)](https://hub.docker.com/_/ubuntu) / requires `openssh-client` package
|
||||
* [Docker container (CentOS)](https://hub.docker.com/_/centos) / requires `openssh-clients` package
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -131,19 +133,21 @@ The scripts and documentation in this project are released under the [MIT Licens
|
|||
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
|
||||
[link-build]: https://github.com/shimataro/ssh-key-action/actions/workflows/build.yml
|
||||
[image-verify-windows-2019]: https://github.com/shimataro/ssh-key-action/workflows/Windows%20Server%202019/badge.svg?event=push&branch=v2
|
||||
[link-verify-windows-2019]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Windows+Server+2019%22
|
||||
[link-verify-windows-2019]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-windows-server-2019.yml
|
||||
[image-verify-macos-1015]: https://github.com/shimataro/ssh-key-action/workflows/macOS%20Catalina/badge.svg?event=push&branch=v2
|
||||
[link-verify-macos-1015]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22macOS+Catalina%22
|
||||
[link-verify-macos-1015]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-macos-1015.yml
|
||||
[image-verify-ubuntu-2004]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu%2020.04/badge.svg?event=push&branch=v2
|
||||
[link-verify-ubuntu-2004]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Ubuntu+20.04%22
|
||||
[link-verify-ubuntu-2004]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-ubuntu-2004.yml
|
||||
[image-verify-ubuntu-1804]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu%2018.04/badge.svg?event=push&branch=v2
|
||||
[link-verify-ubuntu-1804]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Ubuntu+18.04%22
|
||||
[link-verify-ubuntu-1804]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-ubuntu-1804.yml
|
||||
[image-verify-ubuntu-1604]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu%2016.04/badge.svg?event=push&branch=v2
|
||||
[link-verify-ubuntu-1604]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Ubuntu+16.04%22
|
||||
[image-verify-docker-container]: https://github.com/shimataro/ssh-key-action/workflows/Docker%20container/badge.svg?event=push&branch=v2
|
||||
[link-verify-docker-container]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Docker+container%22
|
||||
[link-verify-ubuntu-1604]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-ubuntu-1604.yml
|
||||
[image-verify-docker-container-ubuntu]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-container-ubuntu.yml/badge.svg?event=push&branch=v2
|
||||
[link-verify-docker-container-ubuntu]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-container-ubuntu.yml
|
||||
[image-verify-docker-container-centos]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-container-centos.yml/badge.svg?event=push&branch=v2
|
||||
[link-verify-docker-container-centos]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-container-centos.yml
|
||||
[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
|
||||
|
|
28
lib/index.js
28
lib/index.js
|
@ -430,9 +430,9 @@ function main() {
|
|||
const files = [
|
||||
{
|
||||
name: core.getInput("name"),
|
||||
contents: insertLf(core.getInput("key", { required: true }), {
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("key", {
|
||||
required: true,
|
||||
}), false, true),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "ax",
|
||||
|
@ -440,10 +440,9 @@ function main() {
|
|||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: insertLf(core.getInput("known_hosts", { required: true }), {
|
||||
prepend: true,
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("known_hosts", {
|
||||
required: true,
|
||||
}), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
|
@ -451,10 +450,7 @@ function main() {
|
|||
},
|
||||
{
|
||||
name: "config",
|
||||
contents: insertLf(core.getInput("config"), {
|
||||
prepend: true,
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("config"), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
|
@ -510,20 +506,20 @@ function getHomeEnv() {
|
|||
/**
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to insert LF
|
||||
* @param options options
|
||||
* @param prepend true to prepend
|
||||
* @param append true to append
|
||||
* @returns new value
|
||||
*/
|
||||
function insertLf(value, options) {
|
||||
const normalizedOptions = Object.assign({ prepend: false, append: false }, options);
|
||||
function insertLf(value, prepend, append) {
|
||||
let affectedValue = value;
|
||||
if (value.length === 0) {
|
||||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
if (normalizedOptions.prepend && !affectedValue.startsWith("\n")) {
|
||||
if (prepend && !affectedValue.startsWith("\n")) {
|
||||
affectedValue = `\n${affectedValue}`;
|
||||
}
|
||||
if (normalizedOptions.append && !affectedValue.endsWith("\n")) {
|
||||
if (append && !affectedValue.endsWith("\n")) {
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
return affectedValue;
|
||||
|
|
39
src/main.ts
39
src/main.ts
|
@ -10,13 +10,6 @@ interface FileInfo
|
|||
options: fs.WriteFileOptions;
|
||||
}
|
||||
|
||||
/** options for insertLf() */
|
||||
interface InsertLfOptions
|
||||
{
|
||||
prepend?: boolean;
|
||||
append?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* main function
|
||||
*/
|
||||
|
@ -27,9 +20,9 @@ function main(): void
|
|||
const files: FileInfo[] = [
|
||||
{
|
||||
name: core.getInput("name"),
|
||||
contents: insertLf(core.getInput("key", {required: true}), {
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("key", {
|
||||
required: true,
|
||||
}), false, true),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "ax",
|
||||
|
@ -37,10 +30,9 @@ function main(): void
|
|||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: insertLf(core.getInput("known_hosts", {required: true}), {
|
||||
prepend: true,
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("known_hosts", {
|
||||
required: true,
|
||||
}), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
|
@ -48,10 +40,7 @@ function main(): void
|
|||
},
|
||||
{
|
||||
name: "config",
|
||||
contents: insertLf(core.getInput("config"), {
|
||||
prepend: true,
|
||||
append: true,
|
||||
}),
|
||||
contents: insertLf(core.getInput("config"), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
|
@ -123,16 +112,12 @@ function getHomeEnv(): string
|
|||
/**
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to insert LF
|
||||
* @param options options
|
||||
* @param prepend true to prepend
|
||||
* @param append true to append
|
||||
* @returns new value
|
||||
*/
|
||||
function insertLf(value: string, options: InsertLfOptions): string
|
||||
function insertLf(value: string, prepend: boolean, append: boolean): string
|
||||
{
|
||||
const normalizedOptions: Required<InsertLfOptions> = {
|
||||
prepend: false,
|
||||
append: false,
|
||||
...options,
|
||||
};
|
||||
let affectedValue = value;
|
||||
|
||||
if(value.length === 0)
|
||||
|
@ -140,11 +125,11 @@ function insertLf(value: string, options: InsertLfOptions): string
|
|||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
if(normalizedOptions.prepend && !affectedValue.startsWith("\n"))
|
||||
if(prepend && !affectedValue.startsWith("\n"))
|
||||
{
|
||||
affectedValue = `\n${affectedValue}`;
|
||||
}
|
||||
if(normalizedOptions.append && !affectedValue.endsWith("\n"))
|
||||
if(append && !affectedValue.endsWith("\n"))
|
||||
{
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue