Skip to content

Commit 2ad82af

Browse files
committed
ci(gh-actions/update-flake-lock): Enable GPG commit signing
1 parent 080d1d8 commit 2ad82af

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

.github/workflows/reusable-update-flake-lock.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ on:
1414
default: ''
1515
required: false
1616
type: string
17+
sign-commits:
18+
description: 'Enable GPG commit signing'
19+
default: false
20+
required: false
21+
type: boolean
1722

1823
secrets:
1924
NIX_GITHUB_TOKEN:
@@ -31,6 +36,12 @@ on:
3136
CREATE_PR_APP_PRIVATE_KEY:
3237
description: Private key of the GitHub App used for opening pull requests.
3338
required: true
39+
GIT_GPG_SIGNING_SECRET_KEY:
40+
description: GPG secret key used to sign commits
41+
required: false
42+
GIT_GPG_SIGNING_PASSPHRASE:
43+
description: GPG passphrase for secret key
44+
required: false
3445

3546
outputs:
3647
pr-url:
@@ -61,13 +72,29 @@ jobs:
6172
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
6273
substituters: ${{ vars.SUBSTITUTERS }}
6374

75+
- name: Import GPG key with passphrase
76+
env:
77+
GIT_GPG_SIGNING_SECRET_KEY: ${{ secrets.GIT_GPG_SIGNING_SECRET_KEY }}
78+
GIT_GPG_SIGNING_PASSPHRASE: ${{ secrets.GIT_GPG_SIGNING_PASSPHRASE }}
79+
run: |
80+
echo "$GIT_GPG_SIGNING_SECRET_KEY" \
81+
| gpg --batch --yes \
82+
--pinentry-mode loopback \
83+
--passphrase "$GIT_GPG_SIGNING_PASSPHRASE" \
84+
--import
85+
86+
- name: Configure Git credentials
87+
run: |
88+
git config --local user.name "${{ vars.GIT_USER_NAME }}"
89+
git config --local user.email "${{ vars.GIT_USER_EMAIL }}"
90+
git config --local user.signingkey "${{ vars.GIT_GPG_SIGNING_KEY_ID }}"
91+
git config --local commit.gpgsign true
92+
6493
- name: Run `nix flake update`
6594
id: update-lockfile
66-
run: |
67-
curl -fsSL --proto '=https' --tlsv1.2 \
68-
https://raw.githubusercontent.com/metacraft-labs/nixos-modules/main/scripts/commit_flake_update.bash \
69-
-o commit_flake_update.bash
70-
FLAKE_INPUT=${{ inputs.flake-input }} bash commit_flake_update.bash
95+
run: ${GITHUB_ACTION_PATH}/scripts/commit_flake_update.bash
96+
env:
97+
FLAKE_INPUT: ${{ inputs.flake-input }}
7198

7299
- uses: tibdex/[email protected]
73100
id: generate-token

scripts/commit_flake_update.bash

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ set -euo pipefail
44

55
FLAKE_INPUT=${FLAKE_INPUT:-""}
66

7-
if ! git config --get user.name >/dev/null 2>&1 || \
8-
[ "$(git config --get user.name)" = "" ] ||
9-
! git config --get user.email >/dev/null 2>&1 || \
10-
[ "$(git config --get user.email)" = "" ]; then
11-
echo "git config user.{name,email} is not set - configuring"
12-
set -x
13-
git config --local user.email "[email protected]"
14-
git config --local user.name "beep boop"
7+
running_in_github_actions() {
8+
[ -n "$CI" ] && \
9+
[ -n "$GITHUB_REPOSITORY" ] && \
10+
[ -n "$GITHUB_RUN_ID" ] && \
11+
[ -n "$GITHUB_TOKEN" ] && \
12+
curl --silent --fail \
13+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
14+
-H "Accept: application/vnd.github.v3+json" \
15+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" > /dev/null 2>&1
16+
}
17+
18+
if running_in_github_actions; then
19+
echo "Running in GitHub Actions."
20+
git config --list --show-origin
1521
fi
1622

1723
current_commit="$(git rev-parse HEAD)"
1824
export PRE_COMMIT_ALLOW_NO_CONFIG=1
1925

20-
git config --list --show-origin
21-
2226
nix flake update $FLAKE_INPUT --accept-flake-config --commit-lock-file
2327
commit_after_update="$(git rev-parse HEAD)"
2428

0 commit comments

Comments
 (0)