Skip to content

Commit 0db96b3

Browse files
authored
[skip changelog] Sync certificate check CI workflow with template (#1379)
We have assembled a collection of reusable GitHub Actions workflows: https://github.com/arduino/tooling-project-assets These workflows will be used in the repositories of all Arduino tooling projects. Some minor improvements and standardizations have been made in the upstream "template" workflow, and those are introduced to this repository via this pull request. Notable: - Trigger workflow run on modification to facilitate testing. - `repository_dispatch` event trigger to allow for automated triggering across many repositories via the GitHub API following a relevant external change. - Change Slack webhook repository secret name. - Use major version ref of `rtCamp/action-slack-notify` so that the latest release of the action is used up to the next major bump.
1 parent 4713586 commit 0db96b3

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

.github/workflows/check-certificates.yml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1-
name: Check for issues with signing certificates
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-certificates.md
2+
name: Check Certificates
23

4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
35
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-certificates.ya?ml"
9+
pull_request:
10+
paths:
11+
- ".github/workflows/check-certificates.ya?ml"
412
schedule:
5-
# run every 10 hours
13+
# Run every 10 hours.
614
- 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
1015
workflow_dispatch:
16+
repository_dispatch:
1117

1218
env:
13-
# Begin notifications when there are less than this many days remaining before expiration
19+
# Begin notifications when there are less than this many days remaining before expiration.
1420
EXPIRATION_WARNING_PERIOD: 30
1521

1622
jobs:
1723
check-certificates:
18-
# This workflow would fail in forks that don't have the certificate secrets defined
19-
if: github.repository == 'arduino/arduino-cli'
24+
name: ${{ matrix.certificate.identifier }}
25+
# Only run when the workflow will have access to the certificate secrets.
26+
if: >
27+
(github.event_name != 'pull_request' && github.repository == 'arduino/arduino-cli') ||
28+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-cli')
2029
runs-on: ubuntu-latest
21-
2230
strategy:
2331
fail-fast: false
2432

2533
matrix:
2634
certificate:
27-
- identifier: macOS signing certificate # Text used to identify the certificate in notifications
28-
certificate-secret: INSTALLER_CERT_MAC_P12 # The name of the secret that contains the certificate
29-
password-secret: INSTALLER_CERT_MAC_PASSWORD # The name of the secret that contains the certificate password
35+
# Additional certificate definitions can be added to this list.
36+
- identifier: macOS signing certificate # Text used to identify certificate in notifications.
37+
certificate-secret: INSTALLER_CERT_MAC_P12 # Name of the secret that contains the certificate.
38+
password-secret: INSTALLER_CERT_MAC_PASSWORD # Name of the secret that contains the certificate password.
3039

3140
steps:
3241
- name: Set certificate path environment variable
3342
run: |
34-
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
43+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
3544
echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV"
3645
3746
- name: Decode certificate
@@ -53,18 +62,17 @@ jobs:
5362
exit 1
5463
)
5564
56-
# See: https://github.com/rtCamp/action-slack-notify
5765
- name: Slack notification of certificate verification failure
5866
if: failure()
59-
uses: rtCamp/[email protected]
6067
env:
61-
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
68+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
6269
SLACK_MESSAGE: |
6370
:warning::warning::warning::warning:
6471
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} verification failed!!!
6572
:warning::warning::warning::warning:
6673
SLACK_COLOR: danger
6774
MSG_MINIMAL: true
75+
uses: rtCamp/action-slack-notify@v2
6876

6977
- name: Get days remaining before certificate expiration date
7078
env:
@@ -93,7 +101,7 @@ jobs:
93101
94102
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
95103
96-
# Display the expiration information in the log
104+
# Display the expiration information in the log.
97105
echo "Certificate expiration date: $EXPIRATION_DATE"
98106
echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION"
99107
@@ -108,14 +116,14 @@ jobs:
108116
fi
109117
110118
- name: Slack notification of pending certificate expiration
111-
# Don't send spurious expiration notification if verification fails
119+
# Don't send spurious expiration notification if verification fails.
112120
if: failure() && steps.check-expiration.outcome == 'failure'
113-
uses: rtCamp/[email protected]
114121
env:
115-
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
122+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
116123
SLACK_MESSAGE: |
117124
:warning::warning::warning::warning:
118125
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!
119126
:warning::warning::warning::warning:
120127
SLACK_COLOR: danger
121128
MSG_MINIMAL: true
129+
uses: rtCamp/action-slack-notify@v2

0 commit comments

Comments
 (0)