Security #29
This file contains hidden or 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
| name: Security | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| schedule: | |
| - cron: "23 4 * * 1" | |
| workflow_dispatch: | |
| concurrency: | |
| group: security-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| env: | |
| PYTHONIOENCODING: utf-8 | |
| PYTHONUTF8: "1" | |
| jobs: | |
| workflow-policy: | |
| name: Workflow policy | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Check out source | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Python | |
| uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 | |
| with: | |
| python-version: "3.14" | |
| - name: Enforce immutable action references and least privilege | |
| run: python tools/check_workflows.py | |
| dependency-review: | |
| name: Dependency review | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Check out source | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Review dependency changes | |
| uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 | |
| with: | |
| fail-on-severity: moderate | |
| codeql: | |
| name: CodeQL (${{ matrix.language }}) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| actions: read | |
| contents: read | |
| security-events: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| language: [python, actions] | |
| steps: | |
| - name: Check out source | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1 | |
| with: | |
| languages: ${{ matrix.language }} | |
| queries: security-extended | |
| - name: Analyze repository | |
| uses: github/codeql-action/analyze@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1 | |
| with: | |
| category: /language:${{ matrix.language }} | |
| required: | |
| name: Security required | |
| if: always() | |
| needs: [workflow-policy, dependency-review, codeql] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Enforce security jobs | |
| env: | |
| POLICY_RESULT: ${{ needs.workflow-policy.result }} | |
| DEPENDENCY_RESULT: ${{ needs.dependency-review.result }} | |
| CODEQL_RESULT: ${{ needs.codeql.result }} | |
| run: | | |
| python - <<'PY' | |
| import os | |
| policy = os.environ["POLICY_RESULT"] | |
| dependency = os.environ["DEPENDENCY_RESULT"] | |
| codeql = os.environ["CODEQL_RESULT"] | |
| if policy != "success" or codeql != "success" or dependency not in {"success", "skipped"}: | |
| raise SystemExit( | |
| "security jobs did not pass: " | |
| f"policy={policy}, dependency={dependency}, codeql={codeql}" | |
| ) | |
| print("all applicable security jobs passed") | |
| PY |