diff --git a/.github/workflows/check-certificates.yml b/.github/workflows/check-certificates.yml index 5185912ac..92dec0148 100644 --- a/.github/workflows/check-certificates.yml +++ b/.github/workflows/check-certificates.yml @@ -1,20 +1,31 @@ -name: Check for issues with signing certificates +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-certificates.md +name: Check Certificates +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows on: + push: + paths: + - ".github/workflows/check-certificates.ya?ml" + pull_request: + paths: + - ".github/workflows/check-certificates.ya?ml" schedule: - # run every 10 hours + # Run every 10 hours. - cron: "0 */10 * * *" - # workflow_dispatch event allows the workflow to be triggered manually. - # This could be used to run an immediate check after updating certificate secrets. - # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch workflow_dispatch: + repository_dispatch: env: - # Begin notifications when there are less than this many days remaining before expiration + # Begin notifications when there are less than this many days remaining before expiration. EXPIRATION_WARNING_PERIOD: 30 jobs: check-certificates: + name: ${{ matrix.certificate.identifier }} + # Only run when the workflow will have access to the certificate secrets. + if: > + (github.event_name != 'pull_request' && github.repository == 'arduino/arduino-create-agent') || + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-create-agent') runs-on: ubuntu-18.04 strategy: @@ -22,9 +33,10 @@ jobs: matrix: certificate: - - identifier: macOS signing certificate # Text used to identify the certificate in notifications - certificate-secret: INSTALLER_CERT_MAC_P12 # The name of the secret that contains the certificate - password-secret: INSTALLER_CERT_MAC_PASSWORD # The name of the secret that contains the certificate password + # Additional certificate definitions can be added to this list. + - identifier: macOS signing certificate # Text used to identify certificate in notifications. + certificate-secret: INSTALLER_CERT_MAC_P12 # Name of the secret that contains the certificate. + password-secret: INSTALLER_CERT_MAC_PASSWORD # Name of the secret that contains the certificate password. - identifier: Windows signing certificate certificate-secret: INSTALLER_CERT_WINDOWS_PFX password-secret: INSTALLER_CERT_WINDOWS_PASSWORD @@ -32,13 +44,15 @@ jobs: steps: - name: Set certificate path environment variable run: | - # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV" + - name: Decode certificate env: CERTIFICATE: ${{ secrets[matrix.certificate.certificate-secret] }} run: | echo "${{ env.CERTIFICATE }}" | base64 --decode > "${{ env.CERTIFICATE_PATH }}" + - name: Verify certificate env: CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }} @@ -51,10 +65,9 @@ jobs: echo "::error::Verification of ${{ matrix.certificate.identifier }} failed!!!" exit 1 ) - # See: https://github.com/rtCamp/action-slack-notify + - name: Slack notification of certificate verification failure if: failure() - uses: rtCamp/action-slack-notify@v2 env: SLACK_WEBHOOK: ${{ secrets.TEAM_CREATE_CHANNEL_SLACK_WEBHOOK }} SLACK_MESSAGE: | @@ -63,6 +76,7 @@ jobs: :warning::warning::warning::warning: SLACK_COLOR: danger MSG_MINIMAL: true + uses: rtCamp/action-slack-notify@v2 - name: Get days remaining before certificate expiration date env: @@ -88,11 +102,15 @@ jobs: 'notAfter=(\K.*)' ) )" + DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))" - # Display the expiration information in the log + + # Display the expiration information in the log. echo "Certificate expiration date: $EXPIRATION_DATE" echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION" + echo "::set-output name=days::$DAYS_BEFORE_EXPIRATION" + - name: Check if expiration notification period has been reached id: check-expiration run: | @@ -100,10 +118,10 @@ jobs: echo "::error::${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!" exit 1 fi + - name: Slack notification of pending certificate expiration - # Don't send spurious expiration notification if verification fails + # Don't send spurious expiration notification if verification fails. if: failure() && steps.check-expiration.outcome == 'failure' - uses: rtCamp/action-slack-notify@v2 env: SLACK_WEBHOOK: ${{ secrets.TEAM_CREATE_CHANNEL_SLACK_WEBHOOK }} SLACK_MESSAGE: | @@ -111,4 +129,5 @@ jobs: WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!! :warning::warning::warning::warning: SLACK_COLOR: danger - MSG_MINIMAL: true \ No newline at end of file + MSG_MINIMAL: true + uses: rtCamp/action-slack-notify@v2