Skip to content

Commit 0d96689

Browse files
committed
add GPG key signing to the action
Signed-off-by: Andrew Brandt <[email protected]>
1 parent da4d586 commit 0d96689

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

action.yaml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,37 @@ runs:
138138
- name: Commit values to repo-properties.yaml
139139
if: ${{ inputs.dry-run-enabled != 'true' }}
140140
shell: bash
141+
env:
142+
GPG_PRIVATE_KEY: ${{ secrets.GPG_KEY_CONTENTS }}
143+
GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
141144
run: |
142-
git config user.name "${{ inputs.commit-author-name }}"
143-
git config user.email "${{ inputs.commit-author-email }}"
145+
# Import GPG key
146+
echo "$GPG_PRIVATE_KEY" | gpg --batch --import
147+
148+
# Get the GPG key ID
149+
KEY_ID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec/{print $5}' | head -n1)
150+
151+
# Trust the key (avoid interactive trust prompts)
152+
echo -e "5\ny\n" | gpg --command-fd 0 --expert --edit-key "$KEY_ID" trust
153+
154+
# Configure Git to use this key
155+
git config --global user.name "${{ inputs.commit-author-name }}"
156+
git config --global user.email "${{ inputs.commit-author-email }}"
157+
git config --global commit.gpgsign true
158+
git config --global user.signingkey "$KEY_ID"
159+
git config --global gpg.program gpg
160+
161+
# Prevent pinentry prompt (for passphrase-protected keys)
162+
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg.conf
163+
echo "use-agent" >> ~/.gnupg/gpg.conf
164+
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
165+
echo RELOADAGENT | gpg-connect-agent
166+
export GPG_TTY=$(tty)
167+
168+
# Make the commit
144169
git add repo-properties.yaml
145-
git commit -m "chore: commit repo custom properties to properties file" || echo "Nothing to commit"
170+
echo "$GPG_PASSPHRASE" | \
171+
gpg --batch --yes --passphrase-fd 0 \
172+
git commit -S -m "chore: commit repo custom properties to properties file" || echo "Nothing to commit"
173+
146174
git push

0 commit comments

Comments
 (0)