|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Summary: run the OSSF Scorecard scanner on PRs and every night. |
| 16 | +# |
| 17 | +# Scorecard (https://github.com/ossf/scorecard) is a repository-scanning tool |
| 18 | +# that evaluates a project's security practices. Its use is suggested by |
| 19 | +# Google's GitHub team. Scorecard's findings are reported in a repo's scanning |
| 20 | +# results page, https://github.com/quantumlib/REPO/security/code-scanning/. |
| 21 | + |
| 22 | +name: Scorecard analysis |
| 23 | +run-name: Run Scorecard scanner for security best practices |
| 24 | + |
| 25 | +on: |
| 26 | + schedule: |
| 27 | + # Run weekly on Saturdays. |
| 28 | + - cron: '30 9 * * 6' |
| 29 | + |
| 30 | + pull_request: |
| 31 | + types: [opened, synchronize] |
| 32 | + branches: |
| 33 | + - main |
| 34 | + - master |
| 35 | + |
| 36 | + # Support merge queues. |
| 37 | + merge_group: |
| 38 | + types: |
| 39 | + - checks_requested |
| 40 | + |
| 41 | + # Allow manual invocation. |
| 42 | + workflow_dispatch: |
| 43 | + inputs: |
| 44 | + debug: |
| 45 | + description: 'Run with debugging options' |
| 46 | + type: boolean |
| 47 | + default: true |
| 48 | + |
| 49 | +# Declare default workflow permissions as read only. |
| 50 | +permissions: read-all |
| 51 | + |
| 52 | +concurrency: |
| 53 | + # Cancel any previously-started but still active runs on the same branch. |
| 54 | + cancel-in-progress: true |
| 55 | + group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}} |
| 56 | + |
| 57 | +jobs: |
| 58 | + run-scorecard: |
| 59 | + if: github.repository_owner == 'quantumlib' |
| 60 | + name: Scorecard analyzer |
| 61 | + runs-on: ubuntu-24.04 |
| 62 | + permissions: |
| 63 | + security-events: write |
| 64 | + id-token: write |
| 65 | + timeout-minutes: 15 |
| 66 | + steps: |
| 67 | + - name: Check out a copy of the git repository |
| 68 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 69 | + with: |
| 70 | + persist-credentials: false |
| 71 | + |
| 72 | + - name: Run Scorecard analysis |
| 73 | + uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2 |
| 74 | + with: |
| 75 | + # Save the results |
| 76 | + results_file: scorecard-results.sarif |
| 77 | + results_format: sarif |
| 78 | + # See https://github.com/ossf/scorecard-action#publishing-results. |
| 79 | + publish_results: true |
| 80 | + |
| 81 | + - name: Upload results to code-scanning dashboard |
| 82 | + uses: github/codeql-action/upload-sarif@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5 |
| 83 | + with: |
| 84 | + sarif_file: scorecard-results.sarif |
| 85 | + |
| 86 | + - if: github.event.inputs.debug == true |
| 87 | + name: Upload results as artifacts to the workflow Summary page |
| 88 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 89 | + with: |
| 90 | + name: Scorecard SARIF file |
| 91 | + path: scorecard-results.sarif |
| 92 | + retention-days: 5 |
| 93 | + |
| 94 | + # Scorecard currently (ver. 2.4.x) doesn't allow submissions from jobs having |
| 95 | + # steps that use "run:". To print to the summary, we need to use another job. |
| 96 | + write-summary: |
| 97 | + name: Scorecard results |
| 98 | + needs: run-scorecard |
| 99 | + runs-on: ubuntu-24.04 |
| 100 | + timeout-minutes: 5 |
| 101 | + steps: |
| 102 | + - name: Write the Scorecard report page link to the workflow summary |
| 103 | + run: | |
| 104 | + repo="${{github.repository}}" |
| 105 | + url="https://scorecard.dev/viewer/?uri=github.com%2F${repo//\//%2F}" |
| 106 | + { |
| 107 | + echo -n "The results are available on the OpenSSF Scorecard " |
| 108 | + echo "[report page for ${{github.repository}}]($url)." |
| 109 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments