mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-11-24 22:11:02 -05:00
Initial commit
This commit is contained in:
commit
851e05c587
26 changed files with 50498 additions and 0 deletions
15
.editorconfig
Normal file
15
.editorconfig
Normal file
|
@ -0,0 +1,15 @@
|
|||
# This file is for unifying the coding style for different editors and IDEs.
|
||||
# More information at http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/dist/** linguist-generated=true
|
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
* @crazy-max
|
30
.github/CONTRIBUTING.md
vendored
Normal file
30
.github/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
## Contributing
|
||||
|
||||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
||||
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork](https://github.com/crazy-max/ghaction-import-gpg/fork) and clone the repository
|
||||
2. Configure and install the dependencies: `npm install`
|
||||
3. Make sure the tests pass on your machine: `npm run test`
|
||||
4. Create a new branch: `git checkout -b my-branch-name`
|
||||
5. Make your change, add tests, and make sure the tests still pass
|
||||
6. Run pre-checkin: `npm run pre-checkin`
|
||||
7. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-import-gpg/compare)
|
||||
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||
|
||||
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
||||
|
||||
- Write tests.
|
||||
- Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
|
||||
- We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
|
||||
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as **separate pull requests**.
|
||||
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
||||
|
||||
## Resources
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
|
||||
- [GitHub Help](https://help.github.com)
|
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
github: crazy-max
|
||||
custom: https://www.paypal.me/crazyws
|
33
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
33
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
---
|
||||
|
||||
### Behaviour
|
||||
|
||||
#### Steps to reproduce this issue
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
#### Expected behaviour
|
||||
|
||||
> Tell me what should happen
|
||||
|
||||
#### Actual behaviour
|
||||
|
||||
> Tell me what happens instead
|
||||
|
||||
### Configuration
|
||||
|
||||
* Repository URL (if public):
|
||||
* Build URL (if public):
|
||||
|
||||
```yml
|
||||
# paste your YAML workflow file here and remove sensitive data
|
||||
```
|
||||
|
||||
### Logs
|
||||
|
||||
> Download the [log file of your build](https://help.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#downloading-logs) and [attach it](https://help.github.com/en/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests) to this issue.
|
29
.github/SUPPORT.md
vendored
Normal file
29
.github/SUPPORT.md
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Support [![](https://isitmaintained.com/badge/resolution/crazy-max/ghaction-import-gpg.svg)](https://isitmaintained.com/project/crazy-max/ghaction-import-gpg)
|
||||
|
||||
## Reporting an issue
|
||||
|
||||
Please do a search in [open issues](https://github.com/crazy-max/ghaction-import-gpg/issues?utf8=%E2%9C%93&q=) to see if the issue or feature request has already been filed.
|
||||
|
||||
If you find your issue already exists, make relevant comments and add your [reaction](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments). Use a reaction in place of a "+1" comment.
|
||||
|
||||
:+1: - upvote
|
||||
|
||||
:-1: - downvote
|
||||
|
||||
If you cannot find an existing issue that describes your bug or feature, submit an issue using the guidelines below.
|
||||
|
||||
## Writing good bug reports and feature requests
|
||||
|
||||
File a single issue per problem and feature request.
|
||||
|
||||
* Do not enumerate multiple bugs or feature requests in the same issue.
|
||||
* Do not add your issue as a comment to an existing issue unless it's for the identical input. Many issues look similar, but have different causes.
|
||||
|
||||
The more information you can provide, the more likely someone will be successful reproducing the issue and finding a fix.
|
||||
|
||||
You are now ready to [create a new issue](https://github.com/crazy-max/ghaction-import-gpg/issues/new/choose)!
|
||||
|
||||
## Closure policy
|
||||
|
||||
* Issues that don't have the information requested above (when applicable) will be closed immediately and the poster directed to the support guidelines.
|
||||
* Issues that go a week without a response from original poster are subject to closure at my discretion.
|
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "06:00"
|
||||
timezone: "Europe/Paris"
|
||||
labels:
|
||||
- ":game_die: dependencies"
|
||||
- ":robot: bot"
|
26
.github/workflows/lint.yml
vendored
Normal file
26
.github/workflows/lint.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
name: lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '.github/workflows/lint.yml'
|
||||
- 'src/*'
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
# https://github.com/actions/checkout
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
# https://github.com/actions/setup-node
|
||||
name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
-
|
||||
name: Setup TS
|
||||
run: npm install tslint typescript -g
|
||||
-
|
||||
name: Lint check
|
||||
run: tslint './src/*.ts'
|
96
.gitignore
vendored
Normal file
96
.gitignore
vendored
Normal file
|
@ -0,0 +1,96 @@
|
|||
/.dev
|
||||
node_modules/
|
||||
lib
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## 1.0.0 (2019/09/22)
|
||||
|
||||
* Initial version
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 CrazyMax
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
44
README.md
Normal file
44
README.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
[![GitHub release](https://img.shields.io/github/release/crazy-max/ghaction-import-gpg.svg?style=flat-square)](https://github.com/crazy-max/ghaction-import-gpg/releases/latest)
|
||||
[![GitHub marketplace](https://img.shields.io/badge/marketplace-import--gpg-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/import-gpg)
|
||||
[![Test workflow](https://github.com/crazy-max/ghaction-import-gpg/workflows/test/badge.svg)](https://github.com/crazy-max/ghaction-import-gpg/actions?workflow=test)
|
||||
[![Become a sponsor](https://img.shields.io/badge/sponsor-crazy--max-181717.svg?logo=github&style=flat-square)](https://github.com/sponsors/crazy-max)
|
||||
[![Paypal Donate](https://img.shields.io/badge/donate-paypal-00457c.svg?logo=paypal&style=flat-square)](https://www.paypal.me/crazyws)
|
||||
|
||||
## About
|
||||
|
||||
GitHub Action to easily import your GPG key to sign commits and tags.
|
||||
|
||||
If you are interested, [check out](https://git.io/Je09Y) my other :octocat: GitHub Actions!
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
name: import-gpg
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: master
|
||||
|
||||
jobs:
|
||||
import-gpg:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Import GPG key
|
||||
uses: crazy-max/ghaction-import-gpg@master
|
||||
env:
|
||||
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
|
||||
```
|
||||
|
||||
## How can I help?
|
||||
|
||||
All kinds of contributions are welcome :raised_hands:! The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon: You can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) :clap: or by making a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely! :rocket:
|
||||
|
||||
Thanks again for your support, it is much appreciated! :pray:
|
||||
|
||||
## License
|
||||
|
||||
MIT. See `LICENSE` for more details.
|
151
__tests__/gpg.test.ts
Normal file
151
__tests__/gpg.test.ts
Normal file
|
@ -0,0 +1,151 @@
|
|||
import {deleteKey, getVersion, importKey} from '../src/gpg';
|
||||
import * as child_process from 'child_process';
|
||||
|
||||
const userInfo = {
|
||||
name: 'Joe Tester',
|
||||
email: 'joe@foo.bar',
|
||||
passphrase: 'with stupid passphrase',
|
||||
keyID: 'D523BD50DD70B0BA',
|
||||
userID: 'Joe Tester <joe@foo.bar>',
|
||||
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
|
||||
pgp: `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
lQdGBF6tzaABEACjFbX7PFEG6vDPN2MPyxYW7/3o/sonORj4HXUFjFxxJxktJ3x3
|
||||
N1ayHPJ1lqIeoiY7jVbq0ZdEVGkd3YsKG9ZMdZkzGzY6PQPC/+M8OnzOiOPwUdWc
|
||||
+Tdhh115LvVz0MMKYiab6Sn9cgxj9On3LCQKpjvMDpPo9Ttf6v2GQIw8h2ACvdzQ
|
||||
71LtIELS/I+dLbfZiwpUu2fhQT13EJkEnYMOYwM5jNUd66P9itUc7MrOWjkicrKP
|
||||
oF1dQaCM+tuKuxvD8WLdiwU5x60NoGkJHHUehKQXl2dVzjpqEqHKEB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0/XT/sr+z23z0kpZH
|
||||
D3dXPX0BwM4IP9xu31CNg10x0rKwjbxy8VaskFEelpqpu+gpAnxqMd1evpeUHcOd
|
||||
r5RgPgkNFfba9Nbxf7uEX+HOmsOM+kdtSmdGIvsBZjVnW31nnoDMp49jG4OynjrH
|
||||
cRuoM9sxdr6UDqb22CZ3/e0YN4UaZM3YDWMVaP/QBVgvIFcdByqNWezpd9T4ZUII
|
||||
MZlaV1uRnHg6B/zTzhIdMM80AXz6Uv6kw4S+Lt7HlbrnMT7uKLuvzH7cle0hcIUa
|
||||
PejgXO0uIRolYQ3sz2tMGhx1MfBqH64=
|
||||
=WbwB
|
||||
-----END PGP PRIVATE KEY BLOCK-----`
|
||||
};
|
||||
|
||||
describe('gpg', () => {
|
||||
describe('getVersion', () => {
|
||||
it('returns GnuPG and libgcrypt version', async () => {
|
||||
await getVersion().then(version => {
|
||||
console.log(version);
|
||||
expect(version.gnupg).not.toEqual('');
|
||||
expect(version.libgcrypt).not.toEqual('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('importKey', () => {
|
||||
it('imports key to GnuPG', async () => {
|
||||
await importKey(userInfo.pgp).then(() => {
|
||||
console.log(
|
||||
child_process.execSync(`gpg --batch --list-keys --keyid-format LONG ${userInfo.email}`, {encoding: 'utf8'})
|
||||
);
|
||||
console.log(
|
||||
child_process.execSync(`gpg --batch --list-secret-keys --keyid-format LONG ${userInfo.email}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteKey', () => {
|
||||
it('removes key from GnuPG', async () => {
|
||||
await importKey(userInfo.pgp);
|
||||
await deleteKey(userInfo.fingerprint);
|
||||
});
|
||||
});
|
||||
});
|
138
__tests__/openpgp.test.ts
Normal file
138
__tests__/openpgp.test.ts
Normal file
|
@ -0,0 +1,138 @@
|
|||
import {readPrivateKey, generateKeyPair} from '../src/openpgp';
|
||||
|
||||
const userInfo = {
|
||||
name: 'Joe Tester',
|
||||
email: 'joe@foo.bar',
|
||||
passphrase: 'with stupid passphrase',
|
||||
keyID: 'D523BD50DD70B0BA',
|
||||
userID: 'Joe Tester <joe@foo.bar>',
|
||||
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
|
||||
pgp: `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
lQdGBF6tzaABEACjFbX7PFEG6vDPN2MPyxYW7/3o/sonORj4HXUFjFxxJxktJ3x3
|
||||
N1ayHPJ1lqIeoiY7jVbq0ZdEVGkd3YsKG9ZMdZkzGzY6PQPC/+M8OnzOiOPwUdWc
|
||||
+Tdhh115LvVz0MMKYiab6Sn9cgxj9On3LCQKpjvMDpPo9Ttf6v2GQIw8h2ACvdzQ
|
||||
71LtIELS/I+dLbfZiwpUu2fhQT13EJkEnYMOYwM5jNUd66P9itUc7MrOWjkicrKP
|
||||
oF1dQaCM+tuKuxvD8WLdiwU5x60NoGkJHHUehKQXl2dVzjpqEqHKEBJt9tfJ9lpE
|
||||
YIisgwB8o3pes0fgCehjW2zI95/o9+ayJ6nl4g5+mSvWRXEu66h71nwM0Yuvquk8
|
||||
3me7qhYfDrDdCwcxS5BS1hwakTgUQLD99FZjbx1j8sq96I65O0GRdyU2PR8KIjwu
|
||||
JrkTH4ZlKxK3FQghUhFoA5GkiDb+eClmRMSni5qg+81T4XChmUkEprA3eWCHL+Ma
|
||||
xRNNxLS+r6hH9HG5JBxpV3iaTI9HHpnQKhEeaLXqsUTDZliN9hP7Ywo8bpUB8j2d
|
||||
oWYwDV4dPyMKr6Fb8RDCh2q5gJGbVp8w/NmmBTeL+IP2fFggJkRfyumv3Ul7x66L
|
||||
tBFQ4rYo4JUUrGweSTneG6REIgxH66hIrNl6Vo/D1ZyknTe1dMOu/BTkkQARAQAB
|
||||
/gcDAqra8KO+h3bfyu90vxTL1ro4x/x9il7VBcWlIR4cBP7Imgxv+T4hwPIu8P1x
|
||||
lOlxLNWegFOV0idoTy1o3VLLB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1J
|
||||
gkCdJ/HwAY+r93Lbl5g8gz8d0vJEyfn//34sn9u+toSTw55GcG9Ks1kSKIeDNh0h
|
||||
MiPm3HmJAh8EGAEIAAkFAl6tzaACGwwACgkQfYUety1zvaBV9hAAgliX36pXJ59g
|
||||
3I9/4R68e/fGg0FMM6D+01yCeiKApOYRrJ0cYKn7ITDYmHhlGGpBAie90UsqX12h
|
||||
hdLP7LoQx7sjTyzQt6JmpA8krIwi2ON7FKBkdYb8IYx4mE/5vKnYT4/SFnwTmnZY
|
||||
+m+NzK2U/qmhq8JyO8gozdAKJUcgz49IVv2Ij0tQ4qaPbyPwQxIDyKnT758nJhB1
|
||||
jTqo+oWtER8q3okzIlqcArqn5rDaNJx+DRYL4E/IddyHQAiUWUka8usIUqeW5reu
|
||||
zoPUE2CCfOJSGArkqHQQqMx0WEzjQTwAPaHrQbera4SbiV/o4CLCV/u5p1Qnig+Q
|
||||
iUsakmlD299t//125LIQEa5qzd9hRC7u1uJS7VdW8eGIEcZ0/XT/sr+z23z0kpZH
|
||||
D3dXPX0BwM4IP9xu31CNg10x0rKwjbxy8VaskFEelpqpu+gpAnxqMd1evpeUHcOd
|
||||
r5RgPgkNFfba9Nbxf7uEX+HOmsOM+kdtSmdGIvsBZjVnW31nnoDMp49jG4OynjrH
|
||||
cRuoM9sxdr6UDqb22CZ3/e0YN4UaZM3YDWMVaP/QBVgvIFcdByqNWezpd9T4ZUII
|
||||
MZlaV1uRnHg6B/zTzhIdMM80AXz6Uv6kw4S+Lt7HlbrnMT7uKLuvzH7cle0hcIUa
|
||||
PejgXO0uIRolYQ3sz2tMGhx1MfBqH64=
|
||||
=WbwB
|
||||
-----END PGP PRIVATE KEY BLOCK-----`
|
||||
};
|
||||
|
||||
describe('openpgp', () => {
|
||||
describe('readPrivateKey', () => {
|
||||
it('returns a PGP private key', async () => {
|
||||
await readPrivateKey(userInfo.pgp).then(privateKey => {
|
||||
expect(privateKey.keyID).toEqual(userInfo.keyID);
|
||||
expect(privateKey.userID).toEqual(userInfo.userID);
|
||||
expect(privateKey.fingerprint).toEqual(userInfo.fingerprint);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateKeyPair', () => {
|
||||
it('generates a PGP key pair', async () => {
|
||||
await generateKeyPair(userInfo.name, userInfo.email, userInfo.passphrase).then(keyPair => {
|
||||
expect(keyPair).not.toBeUndefined();
|
||||
expect(keyPair.publicKey).not.toBeUndefined();
|
||||
expect(keyPair.privateKey).not.toBeUndefined();
|
||||
});
|
||||
}, 30000);
|
||||
});
|
||||
});
|
12
action.yml
Normal file
12
action.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
name: 'Import GPG'
|
||||
description: 'GitHub Action to easily import your GPG key to sign commits and tags'
|
||||
author: 'crazy-max'
|
||||
branding:
|
||||
color: 'green'
|
||||
icon: 'key'
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
post: 'dist/index.js'
|
44353
dist/index.js
generated
vendored
Normal file
44353
dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
11
jest.config.js
Normal file
11
jest.config.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: false
|
||||
}
|
5279
package-lock.json
generated
Normal file
5279
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
43
package.json
Normal file
43
package.json
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "import-gpg",
|
||||
"description": "GitHub Action to easily import your GPG key to sign commits and tags",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"test": "jest --coverage",
|
||||
"pre-checkin": "npm run format && npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/crazy-max/ghaction-import-gpg.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"gpg",
|
||||
"signing",
|
||||
"git"
|
||||
],
|
||||
"author": "CrazyMax",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.3",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/github": "^2.1.1",
|
||||
"openpgp": "^4.10.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^25.2.1",
|
||||
"@types/node": "^13.13.4",
|
||||
"@types/openpgp": "^4.4.10",
|
||||
"@zeit/ncc": "^0.22.1",
|
||||
"jest": "^25.5.0",
|
||||
"jest-circus": "^25.5.0",
|
||||
"jest-runtime": "^25.5.0",
|
||||
"prettier": "^2.0.5",
|
||||
"ts-jest": "^25.4.0",
|
||||
"typescript": "^3.8.3",
|
||||
"typescript-formatter": "^7.2.2"
|
||||
}
|
||||
}
|
51
src/gpg.ts
Normal file
51
src/gpg.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {unlinkSync, writeFileSync} from 'fs';
|
||||
import child_process from 'child_process';
|
||||
|
||||
export interface Version {
|
||||
gnupg: string;
|
||||
libgcrypt: string;
|
||||
}
|
||||
|
||||
const gpg = async (args: string[] = []): Promise<string> => {
|
||||
return child_process
|
||||
.execSync(`gpg ${args.join(' ')}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
.trim();
|
||||
};
|
||||
|
||||
export const getVersion = async (): Promise<Version> => {
|
||||
let gnupgVersion: string = '';
|
||||
let libgcryptVersion: string = '';
|
||||
|
||||
await gpg(['--version']).then(stdout => {
|
||||
for (let line of stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||
if (line.startsWith('gpg (GnuPG) ')) {
|
||||
gnupgVersion = line.substr('gpg (GnuPG) '.length).trim();
|
||||
} else if (line.startsWith('gpg (GnuPG/MacGPG2) ')) {
|
||||
gnupgVersion = line.substr('gpg (GnuPG/MacGPG2) '.length).trim();
|
||||
} else if (line.startsWith('libgcrypt ')) {
|
||||
libgcryptVersion = line.substr('libgcrypt '.length).trim();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
gnupg: gnupgVersion,
|
||||
libgcrypt: libgcryptVersion
|
||||
};
|
||||
};
|
||||
|
||||
export const importKey = async (armoredText: string): Promise<void> => {
|
||||
const keyPath: string = `${process.env.HOME}/key.pgp`;
|
||||
writeFileSync(keyPath, armoredText, {mode: 0o600});
|
||||
|
||||
await gpg(['--import', '--batch', '--yes', keyPath]).finally(() => {
|
||||
unlinkSync(keyPath);
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteKey = async (fingerprint: string): Promise<void> => {
|
||||
await gpg(['--batch', '--yes', ' --delete-secret-keys', fingerprint]);
|
||||
await gpg(['--batch', '--yes', ' --delete-keys', fingerprint]);
|
||||
};
|
51
src/main.ts
Normal file
51
src/main.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import * as core from '@actions/core';
|
||||
import {deleteKey, importKey} from './gpg';
|
||||
import {PrivateKey, readPrivateKey} from './openpgp';
|
||||
import * as stateHelper from './state-helper';
|
||||
|
||||
let privateKey: PrivateKey | undefined;
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
if (!process.env.SIGNING_KEY) {
|
||||
core.setFailed('Signing key required');
|
||||
return;
|
||||
}
|
||||
|
||||
core.debug(`SIGNING_KEY: ${process.env.SIGNING_KEY}`);
|
||||
core.debug(`PASSPHRASE: ${process.env.PASSPHRASE}`);
|
||||
|
||||
core.info('🔮 Checking signing key...');
|
||||
privateKey = await readPrivateKey(process.env.SIGNING_KEY);
|
||||
core.debug(`key.fingerprint=${privateKey.fingerprint}`);
|
||||
core.debug(`key.keyID=${privateKey.keyID}`);
|
||||
core.debug(`key.userID=${privateKey.userID}`);
|
||||
core.debug(`key.creationTime: ${privateKey.creationTime}`);
|
||||
|
||||
core.info('🔑 Importing secret key...');
|
||||
await importKey(process.env.SIGNING_KEY);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanup(): Promise<void> {
|
||||
if (!privateKey) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
core.info('🚿 Removing keys from GnuPG...');
|
||||
await deleteKey(privateKey.fingerprint);
|
||||
} catch (error) {
|
||||
core.warning(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Main
|
||||
if (!stateHelper.IsPost) {
|
||||
run();
|
||||
}
|
||||
// Post
|
||||
else {
|
||||
cleanup();
|
||||
}
|
53
src/openpgp.ts
Normal file
53
src/openpgp.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import * as openpgp from 'openpgp';
|
||||
|
||||
export interface PrivateKey {
|
||||
fingerprint: string;
|
||||
keyID: string;
|
||||
userID: string;
|
||||
creationTime: Date;
|
||||
}
|
||||
|
||||
export interface KeyPair {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
}
|
||||
|
||||
export const readPrivateKey = async (armoredText: string): Promise<PrivateKey> => {
|
||||
const {
|
||||
keys: [privateKey],
|
||||
err: err
|
||||
} = await openpgp.key.readArmored(armoredText);
|
||||
if (err?.length) {
|
||||
throw err[0];
|
||||
}
|
||||
|
||||
return {
|
||||
fingerprint: privateKey.getFingerprint().toUpperCase(),
|
||||
keyID: await privateKey.getEncryptionKey().then(encKey => {
|
||||
// @ts-ignore
|
||||
return encKey?.getKeyId().toHex().toUpperCase();
|
||||
}),
|
||||
userID: await privateKey.getPrimaryUser().then(primaryUser => {
|
||||
return primaryUser.user.userId.userid;
|
||||
}),
|
||||
creationTime: privateKey.getCreationTime()
|
||||
};
|
||||
};
|
||||
|
||||
export const generateKeyPair = async (
|
||||
name: string,
|
||||
email: string,
|
||||
passphrase: string,
|
||||
numBits: number = 4096
|
||||
): Promise<KeyPair> => {
|
||||
const keyPair = await openpgp.generateKey({
|
||||
userIds: [{name: name, email: email}],
|
||||
numBits,
|
||||
passphrase
|
||||
});
|
||||
|
||||
return {
|
||||
publicKey: keyPair.publicKeyArmored.replace(/\r\n/g, '\n').trim(),
|
||||
privateKey: keyPair.privateKeyArmored.replace(/\r\n/g, '\n').trim()
|
||||
};
|
||||
};
|
14
src/state-helper.ts
Normal file
14
src/state-helper.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
// From https://github.com/actions/checkout/blob/master/src/state-helper.ts
|
||||
|
||||
import * as coreCommand from '@actions/core/lib/command';
|
||||
|
||||
/**
|
||||
* Indicates whether the POST action is running
|
||||
*/
|
||||
export const IsPost = !!process.env['STATE_isPost'];
|
||||
|
||||
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
||||
// This is necessary since we don't have a separate entry point.
|
||||
if (!IsPost) {
|
||||
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true');
|
||||
}
|
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
Loading…
Reference in a new issue