Skip to content

Commit 523132c

Browse files
committed
chore: add gpg logic to other node versions workflow
1 parent adea20e commit 523132c

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/other-node-versions.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ jobs:
8787
git config --global user.email test@example.com
8888
git config --global user.name "Tester McPerson"
8989
90+
- name: Generate and configure GPG for signing commits and tags in E2E tests
91+
run: |
92+
# Generate a GPG key for test@example.com and store the output from stderr
93+
GPG_OUTPUT=$(echo "Key-Type: default
94+
Key-Length: 2048
95+
Subkey-Type: default
96+
Subkey-Length: 2048
97+
Name-Real: Tester McPerson
98+
Name-Email: test@example.com
99+
Expire-Date: 0
100+
%no-protection" | gpg --pinentry-mode loopback --batch --generate-key 2>&1)
101+
102+
# Find and extract the revocation file path from sdterr
103+
REVOCATION_FILE=$(echo "$GPG_OUTPUT" | grep '.rev' | tr '\n' ' ' | awk -F "'" '{print $4}')
104+
105+
# Get the GPG key ID and the full fingerprint
106+
export GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2)
107+
export GPG_FULL_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep "$GPG_KEY_ID" | grep -v "sec" | awk '{print $1}' | cut -d'/' -f2)
108+
109+
# Export fingerprint and the path to the revocation file to GITHUB_ENV
110+
# This allows the last step in this job to revoke and delete the key
111+
echo "GPG_FULL_KEY_ID=$GPG_FULL_KEY_ID" >> $GITHUB_ENV
112+
echo "REVOCATION_FILE=$REVOCATION_FILE" >> $GITHUB_ENV
113+
114+
# Setup git signing for commits and tags
115+
git config commit.gpgsign true
116+
git config tag.gpgsign true
117+
git config --global user.signingkey $GPG_KEY_ID
118+
90119
- name: Run e2e tests for task-runner
91120
run: npx nx prepare-for-e2e e2e-run-task-runner && e2e/run/task-runner/src/run-tests.sh
92121
shell: bash
@@ -98,6 +127,17 @@ jobs:
98127
if: ${{ always() }}
99128
run: npx nx-cloud stop-all-agents
100129

130+
- name: Revoke and delete GPG key
131+
# It's important that we always run this step, otherwise the key will remain active if any of the steps above fail
132+
if: ${{ always() }}
133+
run: |
134+
# As instructed in the text of revocation file, there is a colon that needs to be removed manually
135+
sed -i "s/:-----BEGIN PGP PUBLIC KEY BLOCK-----/-----BEGIN PGP PUBLIC KEY BLOCK-----/" $REVOCATION_FILE
136+
137+
# Revoke the key and delete it
138+
gpg --yes --import $REVOCATION_FILE
139+
gpg --batch --yes --delete-secret-and-public-key $GPG_FULL_KEY_ID
140+
101141
agents:
102142
name: Nx Cloud - Agent - node-${{ matrix.node }}-agent-${{ matrix.agent }}
103143
needs: set-node-versions

0 commit comments

Comments
 (0)