Skip to content

Commit 11ca3f2

Browse files
committed
fixup! release: create initial Windows installer build workflow
Migrate secrets to Azure Key Vault. Names of the secrets in the AKV, and the AKV and Managed Identity IDs themselves are stored in GitHub environment secrets. This indirection allows for an easy way to re-point these to different Key Vault secrets without modifying the workflow file itself. In forks, this would allow others to use their own AKV and sercrets with the same workflow. Signed-off-by: Matthew John Cheetham <[email protected]>
1 parent 7089111 commit 11ca3f2

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

.github/workflows/build-git-installers.yml

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
permissions:
99
id-token: write # required for Azure login via OIDC
1010

11+
env:
12+
DO_WIN_CODESIGN: ${{ secrets.WIN_CODESIGN_CERT_SECRET_NAME != '' && secrets.WIN_CODESIGN_PASS_SECRET_NAME != '' }}
13+
DO_WIN_GPGSIGN: ${{ secrets.WIN_GPG_KEYGRIP_SECRET_NAME != '' && secrets.WIN_GPG_PRIVATE_SECRET_NAME != '' && secrets.WIN_GPG_PASSPHRASE_SECRET_NAME != '' }}
14+
1115
jobs:
1216
# Check prerequisites for the workflow
1317
prereqs:
@@ -101,43 +105,62 @@ jobs:
101105
git remote add -f origin https://github.com/git-for-windows/git &&
102106
git fetch "https://github.com/${{github.repository}}" refs/tags/${tag_name}:refs/tags/${tag_name} &&
103107
git reset --hard ${tag_name}
108+
- name: Log in to Azure
109+
uses: azure/login@v2
110+
with:
111+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
112+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
113+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
114+
- name: Download code signing secrets
115+
id: codesign-secrets
116+
if: env.DO_WIN_CODESIGN == 'true'
117+
uses: ./.github/actions/akv-secret
118+
with:
119+
vault: ${{ secrets.AZURE_VAULT }}
120+
secrets: |
121+
${{ secrets.WIN_CODESIGN_CERT_SECRET_NAME }} base64> home/.sig/codesign.p12
122+
${{ secrets.WIN_CODESIGN_PASS_SECRET_NAME }} > home/.sig/codesign.pass
104123
- name: Prepare home directory for code-signing
105-
env:
106-
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
107-
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
108-
if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
124+
if: ${{ steps.codesign-secrets.outcome == 'success' }}
109125
shell: bash
110126
run: |
111-
cd home &&
112-
mkdir -p .sig &&
113-
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >.sig/codesign.p12 &&
114-
echo -n "$CODESIGN_PASS" >.sig/codesign.pass
115127
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
128+
- name: Download GPG secrets
129+
id: gpg-secrets
130+
if: env.DO_WIN_GPGSIGN == 'true'
131+
uses: ./.github/actions/akv-secret
132+
with:
133+
vault: ${{ secrets.AZURE_VAULT }}
134+
secrets: |
135+
${{ secrets.WIN_GPG_KEYGRIP_SECRET_NAME }} > $output:keygrip
136+
${{ secrets.WIN_GPG_PRIVATE_SECRET_NAME }} > $output:private-key
137+
${{ secrets.WIN_GPG_PASSPHRASE_SECRET_NAME }} > $output:passphrase
116138
- name: Prepare home directory for GPG signing
117-
if: env.GPGKEY != ''
139+
if: ${{ steps.gpg-secrets.outputs.keygrip != '' && steps.gpg-secrets.outputs.private-key != '' }}
118140
shell: bash
119141
run: |
120142
# This section ensures that the identity for the GPG key matches the git user identity, otherwise
121143
# signing will fail
122144
123-
echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import &&
124-
info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
145+
# Import the GPG private key
146+
echo -n '${{ steps.gpg-secrets.outputs.private-key }}' | gpg $GPG_OPTIONS --import &&
147+
148+
info="$(gpg --list-keys --with-colons '${{ steps.gpg-secrets.outputs.keygrip }}' | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
125149
git config --global user.name "${info% <*}" &&
126150
git config --global user.email "<${info#*<}"
127-
env:
128-
GPGKEY: ${{secrets.GPGKEY}}
129151
- name: Build mingw-w64-${{matrix.arch.toolchain}}-git
130-
env:
131-
GPGKEY: "${{secrets.GPGKEY}}"
132152
shell: bash
133153
run: |
134154
set -x
135155
156+
# Build the GPGKEY variable
157+
export GPGKEY="${{ steps.gpg-secrets.outputs.keygrip }} --passphrase '${{ steps.gpg-secrets.outputs.passphrase }}' --yes --batch --no-tty --pinentry-mode loopback --digest-algo SHA256" &&
158+
136159
# Make sure that there is a `/usr/bin/git` that can be used by `makepkg-mingw`
137160
printf '#!/bin/sh\n\nexec /${{matrix.arch.mingwprefix}}/bin/git.exe "$@"\n' >/usr/bin/git &&
138161
139162
sh -x /usr/src/build-extra/please.sh build-mingw-w64-git --only-${{matrix.arch.name}} --build-src-pkg -o artifacts HEAD &&
140-
if test -n "$GPGKEY"
163+
if test -n "${{ steps.gpg-secrets.outputs.keygrip }}"
141164
then
142165
for tar in artifacts/*.tar*
143166
do
@@ -195,16 +218,19 @@ jobs:
195218
shell: bash
196219
run: |
197220
git clone --filter=blob:none --single-branch -b main https://github.com/git-for-windows/build-extra /usr/src/build-extra
221+
- name: Download code signing secrets
222+
id: codesign-secrets
223+
if: env.DO_WIN_CODESIGN == 'true'
224+
uses: ./.github/actions/akv-secret
225+
with:
226+
vault: ${{ secrets.AZURE_VAULT }}
227+
secrets: |
228+
${{ secrets.WIN_CODESIGN_CERT_SECRET_NAME }} base64> home/.sig/codesign.p12
229+
${{ secrets.WIN_CODESIGN_PASS_SECRET_NAME }} > home/.sig/codesign.pass
198230
- name: Prepare home directory for code-signing
199-
env:
200-
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
201-
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
202-
if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
231+
if: ${{ steps.codesign-secrets.outcome == 'success' }}
203232
shell: bash
204233
run: |
205-
mkdir -p home/.sig &&
206-
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >home/.sig/codesign.p12 &&
207-
echo -n "$CODESIGN_PASS" >home/.sig/codesign.pass &&
208234
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
209235
- name: Retarget auto-update to microsoft/git
210236
shell: bash
@@ -313,7 +339,9 @@ jobs:
313339
fi &&
314340
openssl dgst -sha256 artifacts/${{matrix.type.fileprefix}}-*.exe | sed "s/.* //" >artifacts/sha-256.txt
315341
- name: Verify that .exe files are code-signed
316-
if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
342+
env:
343+
DO_CODE_SIGN: ${{ secrets.WIN_CODESIGN_CERT_SECRET_NAME != '' }}
344+
if: env.DO_CODE_SIGN == 'true'
317345
shell: bash
318346
run: |
319347
PATH=$PATH:"/c/Program Files (x86)/Windows Kits/10/App Certification Kit/" \

0 commit comments

Comments
 (0)