1
0
Fork 0
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:
shimataro 2021-02-24 21:24:03 +09:00 committed by GitHub
parent cdcc4725b3
commit 68b956be12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 137 additions and 57 deletions

View 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

View file

@ -1,6 +1,6 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions # https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: Docker container name: Docker container (Ubuntu)
on: on:
- push - push

View file

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added ### 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)) * Support PKCS8/RFC4716 formats (thanks [@tats-u](https://github.com/tats-u))
### Changed ### Changed

View file

@ -6,7 +6,8 @@
[![Ubuntu 20.04][image-verify-ubuntu-2004]][link-verify-ubuntu-2004] [![Ubuntu 20.04][image-verify-ubuntu-2004]][link-verify-ubuntu-2004]
[![Ubuntu 18.04][image-verify-ubuntu-1804]][link-verify-ubuntu-1804] [![Ubuntu 18.04][image-verify-ubuntu-1804]][link-verify-ubuntu-1804]
[![Ubuntu 16.04][image-verify-ubuntu-1604]][link-verify-ubuntu-1604] [![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] [![Release][image-release]][link-release]
[![License][image-license]][link-license] [![License][image-license]][link-license]
[![Stars][image-stars]][link-stars] [![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. 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) * [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](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer) (needs `openssh-client` package) * [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 ## Usage
@ -131,19 +133,21 @@ The scripts and documentation in this project are released under the [MIT Licens
See [CHANGELOG.md](CHANGELOG.md). See [CHANGELOG.md](CHANGELOG.md).
[image-build]: https://github.com/shimataro/ssh-key-action/workflows/Build/badge.svg?event=push&branch=v2 [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 [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 [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 [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 [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 [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 [link-verify-ubuntu-1604]: https://github.com/shimataro/ssh-key-action/actions/workflows/verify-on-ubuntu-1604.yml
[image-verify-docker-container]: https://github.com/shimataro/ssh-key-action/workflows/Docker%20container/badge.svg?event=push&branch=v2 [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]: https://github.com/shimataro/ssh-key-action/actions?query=workflow%3A%22Docker+container%22 [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 [image-release]: https://img.shields.io/github/release/shimataro/ssh-key-action.svg
[link-release]: https://github.com/shimataro/ssh-key-action/releases [link-release]: https://github.com/shimataro/ssh-key-action/releases
[image-license]: https://img.shields.io/github/license/shimataro/ssh-key-action.svg [image-license]: https://img.shields.io/github/license/shimataro/ssh-key-action.svg

View file

@ -430,9 +430,9 @@ function main() {
const files = [ const files = [
{ {
name: core.getInput("name"), name: core.getInput("name"),
contents: insertLf(core.getInput("key", { required: true }), { contents: insertLf(core.getInput("key", {
append: true, required: true,
}), }), false, true),
options: { options: {
mode: 0o400, mode: 0o400,
flag: "ax", flag: "ax",
@ -440,10 +440,9 @@ function main() {
}, },
{ {
name: "known_hosts", name: "known_hosts",
contents: insertLf(core.getInput("known_hosts", { required: true }), { contents: insertLf(core.getInput("known_hosts", {
prepend: true, required: true,
append: true, }), true, true),
}),
options: { options: {
mode: 0o644, mode: 0o644,
flag: "a", flag: "a",
@ -451,10 +450,7 @@ function main() {
}, },
{ {
name: "config", name: "config",
contents: insertLf(core.getInput("config"), { contents: insertLf(core.getInput("config"), true, true),
prepend: true,
append: true,
}),
options: { options: {
mode: 0o644, mode: 0o644,
flag: "a", flag: "a",
@ -510,20 +506,20 @@ function getHomeEnv() {
/** /**
* prepend/append LF to value if not empty * prepend/append LF to value if not empty
* @param value the value to insert LF * @param value the value to insert LF
* @param options options * @param prepend true to prepend
* @param append true to append
* @returns new value * @returns new value
*/ */
function insertLf(value, options) { function insertLf(value, prepend, append) {
const normalizedOptions = Object.assign({ prepend: false, append: false }, options);
let affectedValue = value; let affectedValue = value;
if (value.length === 0) { if (value.length === 0) {
// do nothing if empty // do nothing if empty
return ""; return "";
} }
if (normalizedOptions.prepend && !affectedValue.startsWith("\n")) { if (prepend && !affectedValue.startsWith("\n")) {
affectedValue = `\n${affectedValue}`; affectedValue = `\n${affectedValue}`;
} }
if (normalizedOptions.append && !affectedValue.endsWith("\n")) { if (append && !affectedValue.endsWith("\n")) {
affectedValue = `${affectedValue}\n`; affectedValue = `${affectedValue}\n`;
} }
return affectedValue; return affectedValue;

View file

@ -10,13 +10,6 @@ interface FileInfo
options: fs.WriteFileOptions; options: fs.WriteFileOptions;
} }
/** options for insertLf() */
interface InsertLfOptions
{
prepend?: boolean;
append?: boolean;
}
/** /**
* main function * main function
*/ */
@ -27,9 +20,9 @@ function main(): void
const files: FileInfo[] = [ const files: FileInfo[] = [
{ {
name: core.getInput("name"), name: core.getInput("name"),
contents: insertLf(core.getInput("key", {required: true}), { contents: insertLf(core.getInput("key", {
append: true, required: true,
}), }), false, true),
options: { options: {
mode: 0o400, mode: 0o400,
flag: "ax", flag: "ax",
@ -37,10 +30,9 @@ function main(): void
}, },
{ {
name: "known_hosts", name: "known_hosts",
contents: insertLf(core.getInput("known_hosts", {required: true}), { contents: insertLf(core.getInput("known_hosts", {
prepend: true, required: true,
append: true, }), true, true),
}),
options: { options: {
mode: 0o644, mode: 0o644,
flag: "a", flag: "a",
@ -48,10 +40,7 @@ function main(): void
}, },
{ {
name: "config", name: "config",
contents: insertLf(core.getInput("config"), { contents: insertLf(core.getInput("config"), true, true),
prepend: true,
append: true,
}),
options: { options: {
mode: 0o644, mode: 0o644,
flag: "a", flag: "a",
@ -123,16 +112,12 @@ function getHomeEnv(): string
/** /**
* prepend/append LF to value if not empty * prepend/append LF to value if not empty
* @param value the value to insert LF * @param value the value to insert LF
* @param options options * @param prepend true to prepend
* @param append true to append
* @returns new value * @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; let affectedValue = value;
if(value.length === 0) if(value.length === 0)
@ -140,11 +125,11 @@ function insertLf(value: string, options: InsertLfOptions): string
// do nothing if empty // do nothing if empty
return ""; return "";
} }
if(normalizedOptions.prepend && !affectedValue.startsWith("\n")) if(prepend && !affectedValue.startsWith("\n"))
{ {
affectedValue = `\n${affectedValue}`; affectedValue = `\n${affectedValue}`;
} }
if(normalizedOptions.append && !affectedValue.endsWith("\n")) if(append && !affectedValue.endsWith("\n"))
{ {
affectedValue = `${affectedValue}\n`; affectedValue = `${affectedValue}\n`;
} }