Skip to content

Commit cb877b7

Browse files
committed
Init commit
1 parent 9c5d23e commit cb877b7

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SSH keygen Action
2+
3+
The action runs `ssh-kengen` to generate a key pair stored in `private_key.txt` and `public_key.txt`, with `rsa` encryption and 4096 bits by default. You can specify your inputs.
4+
5+
Or just use [the template](https://github.com/gitx-io/ssh-keygen-template) to run a workflow_dispatch action to generate a specified one.
6+
7+
## inputs
8+
9+
```yaml
10+
comment:
11+
description: 'A comment to help you to identify the key, e.g. your email etc.'
12+
required: false
13+
encryption:
14+
# dsa | ecdsa | ed25519 | rsa
15+
description: 'Encryption type'
16+
required: true
17+
default: 'rsa'
18+
bits:
19+
description: 'Bits'
20+
required: true
21+
default: '4096'
22+
```

action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'SSH key generation'
2+
description: 'To generate a SSH key'
3+
inputs:
4+
comment:
5+
description: 'A comment to help you to identify the key, e.g. your email etc.'
6+
required: false
7+
encryption:
8+
# dsa | ecdsa | ed25519 | rsa
9+
description: 'Encryption type'
10+
required: true
11+
default: 'rsa'
12+
bits:
13+
description: 'Bits'
14+
required: true
15+
default: '4096'
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Generate the key
20+
run: |
21+
comment=${{ inputs.comment }}
22+
[ -z $comment ] && comment="${GITHUB_REPOSITORY}-$(date +%s)"
23+
echo $comment
24+
encryption=${{ inputs.encryption }}
25+
bits=${{ inputs.bits }}
26+
ssh-keygen -t $encryption -b $bits -C $comment -f key -N ""
27+
shell: bash
28+
- name: Rename key files
29+
run: |
30+
mv key private_key.txt
31+
mv key.pub public_key.txt
32+
shell: bash
33+
- name: Store the key files in the repo
34+
run: |
35+
# git commit if there's any change
36+
if test -n "$(git status --porcelain 2>/dev/null)"; then
37+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
38+
git config --local user.name "github-actions[bot]"
39+
git add .
40+
git commit -m "Update a new key"
41+
git push origin ${GITHUB_REF##*/}
42+
fi
43+
shell: bash

0 commit comments

Comments
 (0)