Skip to content

Commit

Permalink
Artifact signing (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavincabbage authored and crazy-max committed Sep 26, 2019
1 parent bb450e4 commit be0c568
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
with:
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -51,6 +52,20 @@ Following inputs can be used as `step.with` keys
|---------------|---------|-----------|------------------------------------------|
| `version` | String | `latest` | GoReleaser version. Example: `v0.117.0` |
| `args` | String | | Arguments to pass to GoReleaser |
| `key` | String | | Private key to import

### Signing

If signing is enabled in your GoReleaser configuration, populate the `key` input with your private key
and reference the key in your signing configuration, e.g.

```
signs:
- artifacts: checksum
args: ["--batch", "-u", "<key id, fingerprint, email, ...>", "--output", "${signature}", "--detach-sign", "${artifact}"]
```

This feature is currently only compatible when using the default `gpg` command and a private key without a passphrase.

## 🀝 How can I help ?

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ inputs:
default: 'latest'
args:
description: 'Arguments to pass to GoReleaser'
key:
description: 'Private key to import'

runs:
using: 'node12'
Expand Down
10 changes: 10 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
const installer = __importStar(require("./installer"));
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const fs = __importStar(require("fs"));
function run(silent) {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
const key = core.getInput('key');
const goreleaser = yield installer.getGoReleaser(version);
let snapshot = '';
if (!process.env.GITHUB_REF ||
Expand All @@ -36,6 +38,14 @@ function run(silent) {
else {
console.log(`βœ… ${process.env.GITHUB_REF.split('/')[2]} tag found`);
}
if (key) {
console.log('πŸ”‘ Importing signing key...');
let path = `${process.env.HOME}/key.asc`;
fs.writeFileSync(path, key, { mode: 0o600 });
yield exec.exec('gpg', ['--import', path], {
silent: silent
});
}
console.log('πŸƒ Running GoReleaser...');
yield exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
silent: silent
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as installer from './installer';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as fs from 'fs';

export async function run(silent?: boolean) {
try {
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
const key = core.getInput('key');
const goreleaser = await installer.getGoReleaser(version);

let snapshot = '';
Expand All @@ -21,6 +23,15 @@ export async function run(silent?: boolean) {
console.log(`βœ… ${process.env.GITHUB_REF!.split('/')[2]} tag found`);
}

if (key) {
console.log('πŸ”‘ Importing signing key...');
let path = `${process.env.HOME}/key.asc`;
fs.writeFileSync(path, key, {mode: 0o600})
await exec.exec('gpg', ['--import', path], {
silent: silent
})
}

console.log('πŸƒ Running GoReleaser...');
await exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
silent: silent
Expand Down

0 comments on commit be0c568

Please sign in to comment.