Skip to content

Commit caaed65

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. To avoid excessive secret exposure in workflows, usage of the injected secrets is handed over to a dedicated action, that configures GPG (for signing secrets) or switches token (for github app token exchange). Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent bedddaf commit caaed65

File tree

3 files changed

+144
-33
lines changed

3 files changed

+144
-33
lines changed

.github/workflows/auto-merge.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ name: Dependabot auto-merge
22

33
on:
44
workflow_call:
5+
inputs:
6+
enable-organization-bot:
7+
description: |
8+
Enable automatic approval and merge of PRs initiated by a bot.
9+
10+
type: boolean
11+
required: false
12+
default: true
13+
organization-bot:
14+
description: |
15+
The bot name for your organization,
16+
for which you wish to enable auto-merge.
17+
18+
Example: bot-go-openapi[bot]
19+
20+
type: string
21+
required: false
22+
default: 'bot-go-openapi[bot]'
523

624
permissions:
725
contents: read
@@ -50,7 +68,7 @@ jobs:
5068
contents: write
5169
pull-requests: write
5270
runs-on: ubuntu-latest
53-
if: ${{ github.event.pull_request.user.login == 'bot-go-openapi[bot]' }}
71+
if: ${{ inputs.enable-organization-bot == 'true' && github.event.pull_request.user.login == inputs.organization-bot }}
5472
env:
5573
PR_URL: ${{github.event.pull_request.html_url}}
5674
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/bump-release.yml

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ on:
4242
(use "|" to replace end of line).
4343
required: false
4444
type: string
45+
enable-tag-signing:
46+
description: |
47+
Enable PGP tag-signing by a bot user.
48+
49+
When enabled, you must pass the GPG secrets to this workflow.
50+
required: false
51+
type: boolean
52+
default: true
4553
cliff-config:
4654
type: string
4755
required: false
@@ -52,6 +60,31 @@ on:
5260
required: false
5361
default: 'https://raw.githubusercontent.com/go-openapi/ci-workflows/refs/heads/master/.cliff.toml'
5462
description: 'URL to the remote git-cliff config file (used if local config does not exist)'
63+
secrets:
64+
gpg-private-key:
65+
description: |
66+
GPG private key in armored format for signing tags.
67+
68+
Default for go-openapi: CI_BOT_GPG_PRIVATE_KEY
69+
70+
Required when enable-tag-signing is true.
71+
required: false
72+
gpg-passphrase:
73+
description: |
74+
Passphrase to unlock the GPG private key.
75+
76+
Default for go-openapi: CI_BOT_GPG_PASSPHRASE
77+
78+
Required when enable-tag-signing is true.
79+
required: false
80+
gpg-fingerprint:
81+
description: |
82+
Fingerprint of the GPG signing key (spaces removed).
83+
84+
Default for go-openapi: CI_BOT_SIGNING_KEY
85+
86+
Required when enable-tag-signing is true.
87+
required: false
5588

5689
jobs:
5790
tag-release:
@@ -94,21 +127,23 @@ jobs:
94127
echo "next-tag=${NEXT_TAG}" >> "$GITHUB_OUTPUT"
95128
echo "::notice title=next-tag:${NEXT_TAG}"
96129
-
97-
name: Import GPG key
98-
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
130+
name: Configure bot credentials
131+
if: ${{ inputs.enable-tag-signing == 'true' }}
132+
uses: go-openapi/gh-actions/ci-jobs/bot-credentials@6c7952706aa7afa9141262485767d9270ef5b00b # master
99133
# This is using the GPG signature of bot-go-openapi.
100134
#
101-
# CI_BOT_GPG_PRIVATE_KEY: the bot gpg key, armored
102-
# CI_BOT_GPG_PASSPHRASE: the bot gpg passphrase
103-
# CI_BOT_SIGNING_KEY: the fingerprint of the subkey used (space removed)
135+
# For go-openapi repos (using secrets: inherit):
136+
# Falls back to: CI_BOT_GPG_PRIVATE_KEY, CI_BOT_GPG_PASSPHRASE, CI_BOT_SIGNING_KEY
137+
#
138+
# For other orgs: explicitly pass secrets with your custom names
104139
# NOTE(fredbi): extracted w/ gpg -K --homedir gnupg --keyid-format LONG --with-keygrip --fingerprint --with-subkey-fingerprint
105140
with:
106-
gpg_private_key: ${{ secrets.CI_BOT_GPG_PRIVATE_KEY }}
107-
passphrase: ${{ secrets.CI_BOT_GPG_PASSPHRASE }}
108-
fingerprint: ${{ secrets.CI_BOT_SIGNING_KEY }}
109-
git_user_signingkey: true
110-
git_commit_gpgsign: true
111-
git_tag_gpgsign: true
141+
enable-gpg-signing: 'true'
142+
gpg-private-key: ${{ secrets.gpg-private-key || secrets.CI_BOT_GPG_PRIVATE_KEY }}
143+
gpg-passphrase: ${{ secrets.gpg-passphrase || secrets.CI_BOT_GPG_PASSPHRASE }}
144+
gpg-fingerprint: ${{ secrets.gpg-fingerprint || secrets.CI_BOT_SIGNING_KEY }}
145+
enable-tag-signing: 'true'
146+
enable-commit-signing: 'false'
112147
-
113148
name: Create and sign tag
114149
env:
@@ -125,8 +160,15 @@ jobs:
125160
fi
126161
echo "::notice title=tag-message:${MESSAGE}"
127162
128-
git tag -s -m "${MESSAGE}" "${NEXT_TAG}"
129-
git tag -v "${NEXT_TAG}"
163+
SIGNED=""
164+
if [[ '${{ inputs.enable-tag-signing }}' == 'true' ]] ; then
165+
SIGNED="-s"
166+
fi
167+
168+
git tag "${SIGNED}" -m "${MESSAGE}" "${NEXT_TAG}"
169+
if [[ -n "${SIGNED}" ]] ; then
170+
git tag -v "${NEXT_TAG}"
171+
fi
130172
git push origin "${NEXT_TAG}"
131173
132174
gh-release:

.github/workflows/contributors.yml

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

3+
permissions:
4+
contents: read
5+
36
on:
47
workflow_call:
8+
inputs:
9+
enable-commit-signing:
10+
description: |
11+
Enable GPG commit signing by a bot user.
512
6-
permissions:
7-
contents: read
13+
When enabled, commits in the pull request will be signed with the bot's GPG key.
14+
required: false
15+
type: boolean
16+
default: true
17+
secrets:
18+
github-app-id:
19+
description: |
20+
GitHub App ID for bot user authentication.
21+
22+
Default for go-openapi: CI_BOT_APP_ID
23+
24+
Required to create pull requests as the bot user.
25+
required: false
26+
github-app-private-key:
27+
description: |
28+
GitHub App private key in PEM format.
29+
30+
Default for go-openapi: CI_BOT_APP_PRIVATE_KEY
31+
32+
Required to create pull requests as the bot user.
33+
required: false
34+
gpg-private-key:
35+
description: |
36+
GPG private key in armored format for signing commits.
37+
38+
Default for go-openapi: CI_BOT_GPG_PRIVATE_KEY
39+
40+
Required when enable-commit-signing is true.
41+
required: false
42+
gpg-passphrase:
43+
description: |
44+
Passphrase to unlock the GPG private key.
45+
46+
Default for go-openapi: CI_BOT_GPG_PASSPHRASE
47+
48+
Required when enable-commit-signing is true.
49+
required: false
50+
gpg-fingerprint:
51+
description: |
52+
Fingerprint of the GPG signing key (spaces removed).
53+
54+
Default for go-openapi: CI_BOT_SIGNING_KEY
55+
56+
Required when enable-commit-signing is true.
57+
required: false
858

959
jobs:
1060
update-contributors:
@@ -32,22 +82,23 @@ jobs:
3282
rm -rf contributors.json
3383
mv contributors.md CONTRIBUTORS.md
3484
-
35-
name: Switch to go-openapi bot user
36-
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
37-
id: app-token
38-
with:
39-
app-id: ${{ secrets.CI_BOT_APP_ID }}
40-
private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
41-
-
42-
name: Import GPG key
43-
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
85+
name: Configure bot credentials
86+
uses: go-openapi/gh-actions/ci-jobs/bot-credentials@6c7952706aa7afa9141262485767d9270ef5b00b # master
87+
id: bot-credentials
88+
# For go-openapi repos (using secrets: inherit):
89+
# Falls back to: CI_BOT_APP_ID, CI_BOT_APP_PRIVATE_KEY, CI_BOT_GPG_PRIVATE_KEY, etc.
90+
#
91+
# For other orgs: explicitly pass secrets with your custom names
4492
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 }}
48-
git_user_signingkey: true
49-
git_commit_gpgsign: true
50-
git_tag_gpgsign: true
93+
enable-github-app: 'true'
94+
github-app-id: ${{ secrets.github-app-id || secrets.CI_BOT_APP_ID }}
95+
github-app-private-key: ${{ secrets.github-app-private-key || secrets.CI_BOT_APP_PRIVATE_KEY }}
96+
enable-gpg-signing: ${{ inputs.enable-commit-signing }}
97+
gpg-private-key: ${{ secrets.gpg-private-key || secrets.CI_BOT_GPG_PRIVATE_KEY }}
98+
gpg-passphrase: ${{ secrets.gpg-passphrase || secrets.CI_BOT_GPG_PASSPHRASE }}
99+
gpg-fingerprint: ${{ secrets.gpg-fingerprint || secrets.CI_BOT_SIGNING_KEY }}
100+
enable-commit-signing: 'true'
101+
enable-tag-signing: 'false'
51102
-
52103
name: Create a PR
53104
id: create-pull-request
@@ -57,12 +108,12 @@ jobs:
57108
branch: doc/contributors-bot
58109
delete-branch: true
59110
title: "doc: updated contributors file"
60-
token: ${{ steps.app-token.outputs.token }}
111+
token: ${{ steps.bot-credentials.outputs.app-token }}
61112
labels: "bot"
62113
draft: false
63114
assignees: fredbi
64115
reviewers: fredbi
65-
sign-commits: true
116+
sign-commits: ${{ inputs.enable-commit-signing }}
66117
signoff: true # DCO
67118

68119
auto-merge:

0 commit comments

Comments
 (0)