1+ name : Check for issues with signing certificates
2+
3+ on :
4+ schedule :
5+ # run every 10 hours
6+ - cron : " 0 */10 * * *"
7+ # workflow_dispatch event allows the workflow to be triggered manually.
8+ # This could be used to run an immediate check after updating certificate secrets.
9+ # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch
10+ workflow_dispatch :
11+
12+ env :
13+ # Begin notifications when there are less than this many days remaining before expiration
14+ EXPIRATION_WARNING_PERIOD : 30
15+
16+ jobs :
17+ check-certificates :
18+ runs-on : ubuntu-latest
19+
20+ strategy :
21+ fail-fast : false
22+
23+ matrix :
24+ certificate :
25+ - identifier : macOS signing certificate # Text used to identify the certificate in notifications
26+ certificate-secret : INSTALLER_CERT_MAC_P12 # The name of the secret that contains the certificate
27+ password-secret : INSTALLER_CERT_MAC_PASSWORD # The name of the secret that contains the certificate password
28+ - identifier : Windows signing certificate
29+ certificate-secret : INSTALLER_CERT_WINDOWS_PFX
30+ password-secret : INSTALLER_CERT_WINDOWS_PASSWORD
31+
32+ steps :
33+ - name : Set certificate path environment variable
34+ run : |
35+ # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
36+ echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV"
37+ - name : Decode certificate
38+ env :
39+ CERTIFICATE : ${{ secrets[matrix.certificate.certificate-secret] }}
40+ run : |
41+ echo "${{ env.CERTIFICATE }}" | base64 --decode > "${{ env.CERTIFICATE_PATH }}"
42+ - name : Verify certificate
43+ env :
44+ CERTIFICATE_PASSWORD : ${{ secrets[matrix.certificate.password-secret] }}
45+ run : |
46+ (
47+ openssl pkcs12 \
48+ -in "${{ env.CERTIFICATE_PATH }}" \
49+ -noout -passin env:CERTIFICATE_PASSWORD
50+ ) || (
51+ echo "::error::Verification of ${{ matrix.certificate.identifier }} failed!!!"
52+ exit 1
53+ )
54+ # See: https://github.com/rtCamp/action-slack-notify
55+ - name : Slack notification of certificate verification failure
56+ if : failure()
57+ uses : rtCamp/action-slack-notify@v2.1.0
58+ env :
59+ SLACK_WEBHOOK : ${{ secrets.TEAM_CREATE_CHANNEL_SLACK_WEBHOOK }}
60+ SLACK_MESSAGE : |
61+ :warning::warning::warning::warning:
62+ WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} verification failed!!!
63+ :warning::warning::warning::warning:
64+ SLACK_COLOR : danger
65+ MSG_MINIMAL : true
66+
67+ - name : Get days remaining before certificate expiration date
68+ env :
69+ CERTIFICATE_PASSWORD : ${{ secrets[matrix.certificate.password-secret] }}
70+ id : get-days-before-expiration
71+ run : |
72+ EXPIRATION_DATE="$(
73+ (
74+ openssl pkcs12 \
75+ -in "${{ env.CERTIFICATE_PATH }}" \
76+ -clcerts \
77+ -nodes \
78+ -passin env:CERTIFICATE_PASSWORD
79+ ) | (
80+ openssl x509 \
81+ -noout \
82+ -enddate
83+ ) | (
84+ grep \
85+ --max-count=1 \
86+ --only-matching \
87+ --perl-regexp \
88+ 'notAfter=(\K.*)'
89+ )
90+ )"
91+ DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
92+ # Display the expiration information in the log
93+ echo "Certificate expiration date: $EXPIRATION_DATE"
94+ echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION"
95+ echo "::set-output name=days::$DAYS_BEFORE_EXPIRATION"
96+ - name : Check if expiration notification period has been reached
97+ id : check-expiration
98+ run : |
99+ if [[ ${{ steps.get-days-before-expiration.outputs.days }} -lt ${{ env.EXPIRATION_WARNING_PERIOD }} ]]; then
100+ echo "::error::${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!"
101+ exit 1
102+ fi
103+ - name : Slack notification of pending certificate expiration
104+ # Don't send spurious expiration notification if verification fails
105+ if : failure() && steps.check-expiration.outcome == 'failure'
106+ uses : rtCamp/action-slack-notify@v2.1.0
107+ env :
108+ SLACK_WEBHOOK : ${{ secrets.TEAM_CREATE_CHANNEL_SLACK_WEBHOOK }}
109+ SLACK_MESSAGE : |
110+ :warning::warning::warning::warning:
111+ WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!
112+ :warning::warning::warning::warning:
113+ SLACK_COLOR : danger
114+ MSG_MINIMAL : true
0 commit comments