Skip to content

Commit 4ae00ba

Browse files
committed
feat: allow reuse of workflows by other organizations
Problem statement ================= When using workflows such as: * contributors * bump-release * auto-merge the retrieval of secrets for commit or tag PGP-signature and token switch with a github app is currently specific to go-openapi. Proposed solution ================= The names of the secrets (not the secrets themselves) can be injected via optional input parameters into these shared workflows. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent f65a52b commit 4ae00ba

2 files changed

Lines changed: 100 additions & 19 deletions

File tree

.github/workflows/bump-release.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,42 @@ on:
4242
(use "|" to replace end of line).
4343
required: false
4444
type: string
45-
env_gpg_private_key:
45+
enable-tag-signing:
46+
description: |
47+
Enable PGP tag-signing by a bot user.
48+
49+
You must specify the GPG related inputs if they differ from the default names for secrets.
50+
required: false
51+
type: boolean
52+
default: true
53+
env-gpg-private-key:
4654
description: |
4755
PGP tag-signing by a bot user.
4856
4957
This is the name of the secret to sign tags.
5058
It contains an armored GPG private key.
51-
Tags are not signed if not provided.
59+
60+
This input does not contain the secret, but the name of the secret.
5261
required: false
5362
type: string
5463
default: CI_BOT_GPG_PRIVATE_KEY
55-
env_passphrase:
64+
env-passphrase:
5665
description: |
5766
PGP tag-signing by a bot user.
5867
5968
This is the name of the secret that containts the passphrase to unlock the GPG key.
60-
Tags are not signed if not provided.
69+
70+
This input does not contain the secret, but the name of the secret.
6171
required: false
6272
type: string
6373
default: CI_BOT_GPG_PASSPHRASE
64-
env_fingerprint:
74+
env-fingerprint:
6575
description: |
6676
PGP tag-signing by a bot user.
6777
6878
This is the name of the secret that contains the fingerprint of the GPG key.
69-
Tags are not signed if not provided.
79+
80+
This input does not contain the secret, but the name of the secret.
7081
required: false
7182
type: string
7283
default: CI_BOT_SIGNING_KEY
@@ -113,6 +124,7 @@ jobs:
113124
echo "::notice title=next-tag:${NEXT_TAG}"
114125
-
115126
name: Import GPG key
127+
if: ${{ enable-tag-signing == 'true' }}
116128
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
117129
# This is using the GPG signature of bot-go-openapi.
118130
#
@@ -121,9 +133,9 @@ jobs:
121133
# CI_BOT_SIGNING_KEY: the fingerprint of the subkey used (space removed)
122134
# NOTE(fredbi): extracted w/ gpg -K --homedir gnupg --keyid-format LONG --with-keygrip --fingerprint --with-subkey-fingerprint
123135
with:
124-
gpg_private_key: ${{ secrets.CI_BOT_GPG_PRIVATE_KEY }}
125-
passphrase: ${{ secrets.CI_BOT_GPG_PASSPHRASE }}
126-
fingerprint: ${{ secrets.CI_BOT_SIGNING_KEY }}
136+
gpg_private_key: ${{ secrets[inputs.env-gpg-private-key] }}
137+
passphrase: ${{ secrets[inputs.env-passphrase] }}
138+
fingerprint: ${{ secrets[inputs.env-fingerprint] }}
127139
git_user_signingkey: true
128140
git_commit_gpgsign: true
129141
git_tag_gpgsign: true
@@ -143,8 +155,15 @@ jobs:
143155
fi
144156
echo "::notice title=tag-message:${MESSAGE}"
145157
146-
git tag -s -m "${MESSAGE}" "${NEXT_TAG}"
147-
git tag -v "${NEXT_TAG}"
158+
SIGNED=""
159+
if [[ '${{ enable-tag-signing }}' == 'true' ]] ; then
160+
SIGNED="-s"
161+
fi
162+
163+
git tag "${SIGNED}" -m "${MESSAGE}" "${NEXT_TAG}"
164+
if [[ -n "${SIGNED}" ]] ; then
165+
git tag -v "${NEXT_TAG}"
166+
fi
148167
git push origin "${NEXT_TAG}"
149168
150169
gh-release:

.github/workflows/contributors.yml

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,71 @@
11
name: Contributors
22

3+
permissions:
4+
contents: read
5+
36
on:
47
workflow_call:
8+
inputs:
9+
env-app-id:
10+
description: |
11+
The name of the secret that contains the app ID of the user that creates the PR.
512
6-
permissions:
7-
contents: read
13+
This workflow exchanges the token to impersonate the app user, so we
14+
don't have issues with the gihub-actions user approving or merging the PR.
15+
16+
This input does not contain the secret, but the name of the secret.
17+
type: string
18+
required: false
19+
default: CI_BOT_APP_ID
20+
env-app-private-key:
21+
description: |
22+
The name of the secret that contains the app secret key of the user that creates the PR.
23+
24+
This workflow exchanges the token to impersonate the app user, so we
25+
don't have issues with the gihub-actions user approving or merging the PR.
26+
27+
This input does not contain the secret, but the name of the secret.
28+
type: string
29+
required: false
30+
default: CI_BOT_APP_PRIVATE_KEY
31+
enable-commit-signing:
32+
required: false
33+
type: boolean
34+
default: true
35+
env-gpg-private-key:
36+
description: |
37+
PGP tag-signing by a bot user.
38+
39+
This is the name of the secret to sign tags.
40+
It contains an armored GPG private key.
41+
Tags are not signed if not provided.
42+
43+
This input does not contain the secret, but the name of the secret.
44+
required: false
45+
type: string
46+
default: CI_BOT_GPG_PRIVATE_KEY
47+
env-passphrase:
48+
description: |
49+
PGP tag-signing by a bot user.
50+
51+
This is the name of the secret that containts the passphrase to unlock the GPG key.
52+
Tags are not signed if not provided.
53+
54+
This input does not contain the secret, but the name of the secret.
55+
required: false
56+
type: string
57+
default: CI_BOT_GPG_PASSPHRASE
58+
env-fingerprint:
59+
description: |
60+
PGP tag-signing by a bot user.
61+
62+
This is the name of the secret that contains the fingerprint of the GPG key.
63+
Tags are not signed if not provided.
64+
65+
This input does not contain the secret, but the name of the secret.
66+
required: false
67+
type: string
68+
default: CI_BOT_SIGNING_KEY
869

970
jobs:
1071
update-contributors:
@@ -36,15 +97,16 @@ jobs:
3697
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
3798
id: app-token
3899
with:
39-
app-id: ${{ secrets.CI_BOT_APP_ID }}
40-
private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
100+
app-id: ${{ secrets[inputs.env-app-id] }}
101+
private-key: ${{ secrets[inputs.env-app-private-key] }}
41102
-
42103
name: Import GPG key
43104
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
105+
if: ${{ inputs.enable-commit-signing == 'true' }}
44106
with:
45-
gpg_private_key: ${{ secrets.CI_BOT_GPG_PRIVATE_KEY }}
46-
passphrase: ${{ secrets.CI_BOT_GPG_PASSPHRASE }}
47-
fingerprint: ${{ secrets.CI_BOT_SIGNING_KEY }}
107+
gpg_private_key: ${{ secrets[inputs.env-gpg-private-key] }}
108+
passphrase: ${{ secrets[inputs.env-passphrase] }}
109+
fingerprint: ${{ secrets[inputs.env-fingerprint] }}
48110
git_user_signingkey: true
49111
git_commit_gpgsign: true
50112
git_tag_gpgsign: true
@@ -62,7 +124,7 @@ jobs:
62124
draft: false
63125
assignees: fredbi
64126
reviewers: fredbi
65-
sign-commits: true
127+
sign-commits: ${{ inputs.enable-commit-signing }}
66128
signoff: true # DCO
67129

68130
auto-merge:

0 commit comments

Comments
 (0)