Skip to content

Commit b1607cd

Browse files
update build.yml and check-certificates.yml
1 parent aa9b10d commit b1607cd

File tree

2 files changed

+116
-27
lines changed

2 files changed

+116
-27
lines changed

Diff for: .github/workflows/build.yml

+74-4
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,22 @@ env:
6161
container: |
6262
null
6363
# Name of the secret that contains the certificate.
64-
certificate-secret: WINDOWS_SIGNING_CERTIFICATE_PFX
64+
certificate-secret: INSTALLER_CERT_WINDOWS_CER
6565
# Name of the secret that contains the certificate password.
66-
certificate-password-secret: WINDOWS_SIGNING_CERTIFICATE_PASSWORD
66+
certificate-password-secret: INSTALLER_CERT_WINDOWS_PASSWORD
6767
# File extension for the certificate.
6868
certificate-extension: pfx
69+
# Container for windows cert signing
70+
certificate-container: INSTALLER_CERT_WINDOWS_CONTAINER
6971
# Quoting on the value is required here to allow the same comparison expression syntax to be used for this
7072
# and the companion needs.select-targets.outputs.merge-channel-files property (output values always have string
7173
# type).
7274
mergeable-channel-file: 'false'
7375
artifacts:
7476
- path: '*Windows_64bit.exe'
7577
name: Windows_X86-64_interactive_installer
78+
- path: '*Windows_64bit_signed.exe'
79+
name: Windows_X86-64_interactive_installer_signed
7680
- path: '*Windows_64bit.msi'
7781
name: Windows_X86-64_MSI
7882
- path: '*Windows_64bit.zip'
@@ -345,14 +349,15 @@ jobs:
345349
IS_NIGHTLY: ${{ needs.build-type-determination.outputs.is-nightly }}
346350
IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }}
347351
CAN_SIGN: ${{ secrets[matrix.config.certificate-secret] != '' }}
352+
IS_WINDOWS_CONFIG: ${{ matrix.config.name == 'Windows' }}
348353
# The CREATE_* environment vars are only used to run tests. These secrets are optional. Dependent tests will
349354
# be skipped if not available.
350355
CREATE_USERNAME: ${{ secrets.CREATE_USERNAME }}
351356
CREATE_PASSWORD: ${{ secrets.CREATE_PASSWORD }}
352357
CREATE_CLIENT_SECRET: ${{ secrets.CREATE_CLIENT_SECRET }}
353358
run: |
354359
# See: https://www.electron.build/code-signing
355-
if [ $CAN_SIGN = false ]; then
360+
if [ $CAN_SIGN = false ] || [ $IS_WINDOWS_CONFIG = true ]; then
356361
echo "Skipping the app signing: certificate not provided."
357362
else
358363
export CSC_LINK="${{ runner.temp }}/signing_certificate.${{ matrix.config.certificate-extension }}"
@@ -372,7 +377,7 @@ jobs:
372377
yarn --cwd electron-app rebuild
373378
yarn --cwd electron-app build
374379
yarn --cwd electron-app package
375-
380+
376381
# Both macOS jobs generate a "channel update info file" with same path and name. The second job to complete would
377382
# overwrite the file generated by the first in the workflow artifact.
378383
- name: Stage channel file for merge
@@ -406,11 +411,71 @@ jobs:
406411
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
407412
path: ${{ env.BUILD_ARTIFACTS_PATH }}
408413

414+
sign-windows:
415+
runs-on: [self-hosted, windows-sign-pc]
416+
needs: build
417+
418+
defaults:
419+
run:
420+
shell: bash
421+
422+
env:
423+
BUILD_ARTIFACTS_PATH: electron-app/dist/build-artifacts
424+
INSTALLER_CERT_WINDOWS_CER: "/tmp/cert.cer"
425+
# We are hardcoding the path for signtool because is not present on the windows PATH env var by default.
426+
# Keep in mind that this path could change when upgrading to a new runner version
427+
SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x86/signtool.exe"
428+
429+
steps:
430+
- name: Download artifact
431+
uses: actions/download-artifact@v3
432+
with:
433+
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
434+
path: ${{ env.BUILD_ARTIFACTS_PATH }}
435+
436+
- name: Save artifact path to variable
437+
shell: bash
438+
run: |
439+
ARTIFACT=$(find "${{ env.BUILD_ARTIFACTS_PATH }}" -name "*Windows_64bit.exe" | head -n 1)
440+
# Convert to Windows-style path with forward slashes
441+
FULL_PATH=$(cygpath -w $ARTIFACT | sed 's|\\|/|g')
442+
echo "ARTIFACT_PATH=$FULL_PATH" >> $GITHUB_ENV
443+
444+
- name: Save Win signing certificate to file
445+
run: echo "${{ secrets.INSTALLER_CERT_WINDOWS_CER }}" | base64 --decode > ${{ env.INSTALLER_CERT_WINDOWS_CER }}
446+
447+
- name: Sign EXE
448+
env:
449+
CERT_PASSWORD: ${{ secrets.INSTALLER_CERT_WINDOWS_PASSWORD }}
450+
CONTAINER_NAME: ${{ secrets.INSTALLER_CERT_WINDOWS_CONTAINER }}
451+
# https://stackoverflow.com/questions/17927895/automate-extended-validation-ev-code-signing-with-safenet-etoken
452+
run: |
453+
"${{ env.SIGNTOOL_PATH }}" sign -d "Arduino IDE" -f ${{ env.INSTALLER_CERT_WINDOWS_CER }} -csp "eToken Base Cryptographic Provider" -k "[{{${{ env.CERT_PASSWORD }}}}]=${{ env.CONTAINER_NAME }}" -fd sha256 -tr http://timestamp.digicert.com -td SHA256 -v ${{ env.ARTIFACT_PATH }}
454+
455+
- name: Rename signed EXE
456+
shell: bash
457+
run: |
458+
BASE_NAME=$(echo "${{ env.ARTIFACT_PATH }}" | sed 's/.exe$//')
459+
SIGNED_EXE_PATH="${BASE_NAME}_signed.exe"
460+
mv "${{ env.ARTIFACT_PATH }}" "$SIGNED_EXE_PATH"
461+
echo "SIGNED_ARTIFACT_PATH=$SIGNED_EXE_PATH" >> $GITHUB_ENV
462+
463+
- name: Upload artifacts with signed EXE
464+
uses: actions/upload-artifact@v3
465+
with:
466+
name: Windows_X86-64_interactive_installer_signed
467+
path: ${{ env.SIGNED_ARTIFACT_PATH }}
468+
469+
# This step is needed because the self hosted runner does not delete files automatically
470+
- name: Clean up artifacts
471+
run: rm -rf ${{ env.BUILD_ARTIFACTS_PATH }}
472+
409473
merge-channel-files:
410474
needs:
411475
- build-type-determination
412476
- select-targets
413477
- build
478+
- sign-windows
414479
if: needs.select-targets.outputs.merge-channel-files == 'true'
415480
runs-on: ubuntu-latest
416481
permissions: {}
@@ -474,6 +539,7 @@ jobs:
474539
needs:
475540
- select-targets
476541
- build
542+
- sign-windows
477543
if: always() && needs.build.result != 'skipped'
478544
runs-on: ubuntu-latest
479545

@@ -498,6 +564,7 @@ jobs:
498564
needs:
499565
- build-type-determination
500566
- build
567+
- sign-windows
501568
runs-on: ubuntu-latest
502569
outputs:
503570
BODY: ${{ steps.changelog.outputs.BODY }}
@@ -547,6 +614,7 @@ jobs:
547614
- build-type-determination
548615
- merge-channel-files
549616
- changelog
617+
- sign-windows
550618
if: >
551619
always() &&
552620
needs.build-type-determination.result == 'success' &&
@@ -580,6 +648,7 @@ jobs:
580648
- build-type-determination
581649
- merge-channel-files
582650
- changelog
651+
- sign-windows
583652
if: >
584653
always() &&
585654
needs.build-type-determination.result == 'success' &&
@@ -631,6 +700,7 @@ jobs:
631700
- publish
632701
- release
633702
- artifacts
703+
- sign-windows
634704
if: always() && needs.build.result != 'skipped'
635705
runs-on: ubuntu-latest
636706

Diff for: .github/workflows/check-certificates.yml

+42-23
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ jobs:
7474
- identifier: macOS signing certificate # Text used to identify certificate in notifications.
7575
certificate-secret: APPLE_SIGNING_CERTIFICATE_P12 # Name of the secret that contains the certificate.
7676
password-secret: KEYCHAIN_PASSWORD # Name of the secret that contains the certificate password.
77+
type: pkcs12
7778
- identifier: Windows signing certificate
78-
certificate-secret: WINDOWS_SIGNING_CERTIFICATE_PFX
79-
password-secret: WINDOWS_SIGNING_CERTIFICATE_PASSWORD
79+
certificate-secret: INSTALLER_CERT_WINDOWS_CER
80+
# The password for the Windows certificate is not needed, because its not a container, but a single certificate.
81+
type: x509
8082

8183
steps:
8284
- name: Set certificate path environment variable
@@ -95,7 +97,7 @@ jobs:
9597
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
9698
run: |
9799
(
98-
openssl pkcs12 \
100+
openssl ${{ matrix.certificate.type }} \
99101
-in "${{ env.CERTIFICATE_PATH }}" \
100102
-legacy \
101103
-noout \
@@ -122,26 +124,43 @@ jobs:
122124
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
123125
id: get-days-before-expiration
124126
run: |
125-
EXPIRATION_DATE="$(
126-
(
127-
openssl pkcs12 \
128-
-in "${{ env.CERTIFICATE_PATH }}" \
129-
-clcerts \
130-
-legacy \
131-
-nodes \
132-
-passin env:CERTIFICATE_PASSWORD
133-
) | (
134-
openssl x509 \
135-
-noout \
136-
-enddate
137-
) | (
138-
grep \
139-
--max-count=1 \
140-
--only-matching \
141-
--perl-regexp \
142-
'notAfter=(\K.*)'
143-
)
144-
)"
127+
if [[ ${{ matrix.certificate.type }} == "pkcs12" ]]; then
128+
EXPIRATION_DATE="$(
129+
(
130+
openssl pkcs12 \
131+
-in "${{ env.CERTIFICATE_PATH }}" \
132+
-clcerts \
133+
-legacy \
134+
-nodes \
135+
-passin env:CERTIFICATE_PASSWORD
136+
) | (
137+
openssl x509 \
138+
-noout \
139+
-enddate
140+
) | (
141+
grep \
142+
--max-count=1 \
143+
--only-matching \
144+
--perl-regexp \
145+
'notAfter=(\K.*)'
146+
)
147+
)"
148+
elif [[ ${{ matrix.certificate.type }} == "x509" ]]; then
149+
EXPIRATION_DATE="$(
150+
(
151+
openssl x509 \
152+
-in ${{ env.CERTIFICATE_PATH }} \
153+
-noout \
154+
-enddate
155+
) | (
156+
grep \
157+
--max-count=1 \
158+
--only-matching \
159+
--perl-regexp \
160+
'notAfter=(\K.*)'
161+
)
162+
)"
163+
fi
145164
146165
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
147166

0 commit comments

Comments
 (0)