ci: enforce Pinned-Dependencies check in CI for PRs #1098
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2023 The Fuchsia Authors | |
# | |
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | |
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | |
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | |
# This file may not be copied, modified, or distributed except according to | |
# those terms. | |
# This workflow uses actions that are not certified by GitHub. They are provided | |
# by a third-party and are governed by separate terms of service, privacy | |
# policy, and support documentation. | |
name: Scorecard supply-chain security | |
on: | |
# For Branch-Protection check. Only the default branch is supported. See | |
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection | |
branch_protection_rule: | |
# To guarantee Maintained check is occasionally updated. See | |
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained | |
schedule: | |
- cron: "29 15 * * 6" | |
push: | |
branches: ["main"] | |
# Add pull_request trigger to check PRs | |
pull_request: | |
branches: ["main"] | |
# Declare default permissions as read only. | |
permissions: read-all | |
jobs: | |
analysis: | |
name: Scorecard analysis | |
runs-on: ubuntu-latest | |
permissions: | |
# Needed to upload the results to code-scanning dashboard. | |
security-events: write | |
# Needed to publish results and get a badge (see publish_results below). | |
id-token: write | |
steps: | |
- name: "Checkout code" | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
persist-credentials: false | |
- name: "Run analysis" | |
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 | |
with: | |
results_file: results.sarif | |
results_format: sarif | |
# To enable the Branch-Protection check on a *public* repository | |
repo_token: ${{ secrets.SCORECARD_TOKEN }} | |
# Public repositories: | |
# - Publish results to OpenSSF REST API for easy access by consumers | |
# - Allows the repository to include the Scorecard badge. | |
# - See https://github.com/ossf/scorecard-action#publishing-results. | |
publish_results: true | |
# Enable only Pinned-Dependencies check | |
checks: pinned-dependencies | |
# Add step to fail if Pinned-Dependencies check fails | |
- name: "Check Pinned Dependencies Score" | |
run: | | |
score=$(jq -r '.runs[0].results[] | select(.ruleId=="pinned-dependencies") | .score' results.sarif) | |
if (( $(echo "$score < 9" | bc -l) )); then | |
echo "Pinned-Dependencies check failed with score: $score" | |
echo "Please ensure all dependencies are pinned to specific versions." | |
echo "Common locations to check:" | |
echo "- GitHub Actions workflow files (.github/workflows/*.yml)" | |
echo "- Package manager files (package.json, requirements.txt, etc.)" | |
echo "- Docker images in Dockerfiles" | |
exit 1 | |
fi | |
echo "Pinned-Dependencies check passed with score: $score" | |
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF | |
# format to the repository Actions tab. | |
- name: "Upload artifact" | |
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | |
with: | |
name: SARIF file | |
path: results.sarif | |
retention-days: 5 | |
# Upload the results to GitHub's code scanning dashboard. | |
- name: "Upload to code-scanning" | |
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 | |
with: | |
sarif_file: results.sarif | |
# Reference to the main all-jobs-succeed job | |
all-jobs-succeed: | |
needs: [analysis] | |
if: false # This job never runs, it's just for dependency tracking | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "This job is never executed, it exists only for dependency tracking" |