Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/.github/actions/cache-trust-dispatch/     Datei vom 15.10.2026 mit Größe 8 kB image not shown  

Quelle  action.yml  Sprache: unbekannt

 
Spracherkennung für: .yml vermutete Sprache: SQL {SQL[48] VDM[35] Fortran[30]} [Methode: maximale Elemente, drei Dimensionen]

# Single source of truth mapping (repo, ref) → (upload container,
# read fallback chain) for Mathlib's multi-container cache.
#
# Called by every job in build_template.yml that reads or writes the cache,
# directly or through setup-build-env, so trust classification is decided in
# exactly one place. Lean-side cache logic stays branch-agnostic; this
# composite is the seam where CI-only trust policy lives.

name: Cache trust dispatch
description: Compute the cache container target and read fallback for this job.

inputs:
  repo:
    description: GitHub repo full name (`owner/name`).
    required: true
  branch:
    description: |
      Branch name (`github.head_ref || github.ref_name`); on tag-triggered
      runs this is the tag name, distinguished via `github.ref_type` inside
      the dispatch step.
    required: true
  head-sha:
    description: |
      Head commit SHA for the ref being built. Used as the per-commit cache
      namespace (`MATHLIB_CACHE_REPO_SCOPE`) for fork-trust uploads, so a
      closed/hidden PR'
s poisoned artifacts cannot be served to a later
      honest PR from the same fork.
    required: true

# Outputs are mirrored to $GITHUB_ENV inside the step, which is what
# downstream `cache get` / `cache put-staged` calls actually read. We
# also expose them as action outputs for callers that need them in
# `with:` blocks (e.g. constructing further `if:` conditions).
outputs:
  primary:
    description: Container name for uploads (master, forks).
    value: ${{ steps.dispatch.outputs.primary }}
  read-chain:
    description: |
      Comma-separated read fallback chain for `MATHLIB_CACHE_FROM`. Empty
      when the job should use the cache tool's repo-level default.
    value: ${{ steps.dispatch.outputs.read-chain }}
  repo-scope:
    description: |
      Per-commit namespace suffix for `MATHLIB_CACHE_REPO_SCOPE`. Set to
      the head SHA for `forks` uploads; empty for `master` uploads, where
      scoping isn'
t applied.
    value: ${{ steps.dispatch.outputs.repo-scope }}

runs:
  using: composite
  steps:
    - name: Compute trust dispatch
      id: dispatch
      shell: bash
      env:
        REPO: ${{ inputs.repo }}
        BRANCH: ${{ inputs.branch }}
        HEAD_SHA: ${{ inputs.head-sha }}
        # Whether `branch` names a branch or a tag. Read from the run context
        # rather than an input: unlike `repo`/`branch`, the value does not
        # depend on which event shape (PR vs push) the caller handles.
        REF_TYPE: ${{ github.ref_type }}
      run: |
        PRIMARY=""
        READ_CHAIN=""
        REPO_SCOPE=""

        # Security note: this dispatch is NOT the trust boundary for writes.
        # The real enforcement is the OIDC-gated credential minted in the upload
        # jobs: the credential is scoped to a specific container, so a malicious
        # actor rewriting this case to `--container=master` from a fork build
        # would be rejected by the storage regardless. The dispatch exists so the
        # workflow does the right thing in the honest case; defence in depth is
        # the credential scope.

        # The privileged container `master` is writable only by mathlib4's own
        # native CI, whose OIDC-gated credential is scoped to match. A cross-repo pull
        # request is built by build_fork.yml with fork-trust credentials
        # whatever repo the PR head lives on (e.g. a `bump/*` branch on the
        # mathlib4-nightly-testing fork), so it can only write `forks`.
        # `GITHUB_REPOSITORY` is the repo the workflow runs as (the base repo
        # for `pull_request_target`), i.e. the one whose credentials this job
        # holds; when it differs from `$REPO`, the build is a fork and targets
        # `forks` regardless of the head repo'
s own trust class.
        if [ "$REPO" != "$GITHUB_REPOSITORY" ]; then
          PRIMARY="forks"
        else
        case "$REPO" in
          "leanprover-community/mathlib4")
            if [ "$REF_TYPE" = "tag" ]; then
              case "$BRANCH" in
                v4.*)
                  # `v4.*` release tags: release_cache.yml rebuilds every
                  # release commit and publishes it into `master`, the
                  # container canonical checkouts read. Tag creation is
                  # restricted to release managers by a tag ruleset, and the
                  # `cache-upload-master` environment admits `v4.*` tag refs,
                  # so these builds carry master trust. Reads use the tool's
                  # default for the canonical repo, `master` alone, for the
                  # same fill-in reason as the master/staging arm below.
                  PRIMARY="master"
                  ;;
                *)
                  # Other tags have no trust class of their own:
                  # fork-equivalent, like the dev-branch arm below.
                  PRIMARY="forks"
                  READ_CHAIN="master,forks"
                  ;;
              esac
            else
              case "$BRANCH" in
                "master"|"staging")
                  # Master, staging, and `v4.*` release tags (above) are the
                  # only writers that feed `master` (`staging` is bors'
s merge
                  # candidate, which fast-forwards to `master`). Reads use the
                  # tool's default for the canonical repo, `master` alone, and
                  # the chain must not widen: files the read chain serves are
                  # skipped at stage time, so every file missing from `master`
                  # is a miss that gets rebuilt and uploaded, and `master`
                  # fills itself into a standalone cache. (Only PRIMARY=master
                  # does this; other runs write to `forks` and widen the
                  # chain.)
                  PRIMARY="master"
                  ;;
                *)
                  # `bors trying`, `ci-dev/*`, maintainer dev branches on the
                  # canonical repo: trust level is fork-equivalent (the
                  # minted credential scopes them to `forks`). Reads must widen
                  # past the default [master] so the post-build verification
                  # finds the just-uploaded fork-trust artifacts.
                  PRIMARY="forks"
                  READ_CHAIN="master,forks"
                  ;;
              esac
            fi
            ;;
          *)
            # Foreign fork, or the nightly-testing repo, which is a fork in
            # the cache'
s model. The cache tool's default chain for a fork repo
            # is [master, forks] (master-first): master supplies the
            # bulk of unchanged upstream deps, forks supplies PR-specific
            # files. No widening needed, so MATHLIB_CACHE_FROM stays unset.
            PRIMARY="forks"
            ;;
        esac
        fi

        # Per-commit cache namespace, only for fork-trust uploads. Closes the
        # within-fork temporal replay attack: each commit'
s CI run gets its
        # own /f/{repo}/{sha}/... namespace, so artifacts from a closed/
        # hidden PR cannot be served to a later honest build on the same
        # fork. Master uploads are not scoped: master has a single writer, so
        # it has no replay risk.
        if [ "$PRIMARY" = "forks" ]; then
          REPO_SCOPE="$HEAD_SHA"
        fi

        echo "primary=$PRIMARY"           >> "$GITHUB_OUTPUT"
        echo "read-chain=$READ_CHAIN"     >> "$GITHUB_OUTPUT"
        echo "repo-scope=$REPO_SCOPE"     >> "$GITHUB_OUTPUT"
        echo "MATHLIB_CACHE_PRIMARY=$PRIMARY" >> "$GITHUB_ENV"
        if [ -n "$READ_CHAIN" ]; then
          echo "MATHLIB_CACHE_FROM=$READ_CHAIN" >> "$GITHUB_ENV"
        fi
        if [ -n "$REPO_SCOPE" ]; then
          echo "MATHLIB_CACHE_REPO_SCOPE=$REPO_SCOPE" >> "$GITHUB_ENV"
        fi
        # Visible in CI logs so a glance at any cache-touching step shows
        # what trust class the job is operating under.
        SCOPE_NOTE=""
        if [ -n "$REPO_SCOPE" ]; then
          SCOPE_NOTE=", MATHLIB_CACHE_REPO_SCOPE=$REPO_SCOPE"
        fi
        if [ -n "$READ_CHAIN" ]; then
          echo "cache-trust-dispatch: REPO=$REPO BRANCH=$BRANCH → container=$PRIMARY, MATHLIB_CACHE_FROM=$READ_CHAIN$SCOPE_NOTE"
        else
          echo "cache-trust-dispatch: REPO=$REPO BRANCH=$BRANCH → container=$PRIMARY, MATHLIB_CACHE_FROM=<default>$SCOPE_NOTE"
        fi

[Dauer der Verarbeitung: 0.3 Sekunden, vorverarbeitet 2026-11-22]