Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/.github/workflows/     Datei vom 15.10.2026 mit Größe 13 kB image not shown  

Quelle  update_dependencies.yml  Sprache: unbekannt

 
Spracherkennung für: .yml vermutete Sprache: MT940 {MT940[55] Python[36] ABAP[35]} [Methode: maximale Elemente, drei Dimensionen]

name: Update Mathlib Dependencies

on:
  schedule:
    - cron: '17 0 * * *'  # Daily at 00:17 UTC
  workflow_dispatch:

jobs:
  lake-update:
    name: Run lake update
    runs-on: ubuntu-latest
    if: github.repository == 'leanprover-community/mathlib4'
    # `lake update` runs the lakefile code (and any `post_update` hooks) of every dependency at
    # its new revision, before anyone has reviewed it. So this job must not get a write-capable
    # token, an OIDC token, any secret or access to the Actions cache. The `update-pr` job reads
    # its result as data.
    permissions:
      contents: read
    cache-mode: none
    steps:
      - name: Checkout repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false # no later step needs git credentials

      - name: Configure Lean
        uses: leanprover/lean-action@fe408643ea7367d8c0404a8be3975bb145f5fb64 # v1.7.0
        with:
          auto-config: false
          use-github-cache: false
          use-mathlib-cache: false

      - name: Update dependencies
        run: lake update -v

      - name: Upload the updated manifest and toolchain
        uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
        with:
          name: lake-update-result
          path: |
            lake-manifest.json
            lean-toolchain
          if-no-files-found: error
          retention-days: 3

  update-pr:
    name: Open or update the PR
    needs: lake-update
    runs-on: ubuntu-latest
    # Holds the app token. Nothing from the dependencies runs in this job: it only takes
    # `lake-manifest.json` and `lean-toolchain` from the `lake-update` job's artifact.
    permissions:
      pull-requests: read
      id-token: write
    env:
      BRANCH_NAME: "update-dependencies-bot-use-only"
    steps:
      - name: Generate app token
        id: app-token
        uses: leanprover-community/mathlib-ci/.github/actions/azure-create-github-app-token@d6393a535c054122e507b6c5e1b2f4c31c604121
        with:
          app-id: ${{ secrets.MATHLIB_UPDATE_DEPENDENCIES_APP_ID }}
          key-vault-name: ${{ vars.MATHLIB_AZ_KEY_VAULT_NAME }}
          key-name: mathlib-update-dependencies-app-pk
          azure-client-id: ${{ vars.GH_APP_AZURE_CLIENT_ID_PR_WRITERS }}
          azure-tenant-id: ${{ secrets.LPC_AZ_TENANT_ID }}

      # This token is masked by the token minting action and will not be logged accidentally.
      - name: Checkout repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0
          token: ${{ steps.app-token.outputs.token }}

      - name: Get branch SHA if it exists
        id: get-branch-sha
        run: |
          # Check if the branch exists remotely
          SHA=$(git ls-remote --heads origin "$BRANCH_NAME" | awk '{print $1}')
          if [ -n "$SHA" ]; then
            echo "Branch '$BRANCH_NAME' exists with SHA: $SHA"
            echo "sha=$SHA" >> "${GITHUB_OUTPUT}"
          else
            echo "Branch '$BRANCH_NAME' does not exist"
            echo "sha=" >> "${GITHUB_OUTPUT}"
          fi

      - name: Get PR and labels
        if: ${{ steps.get-branch-sha.outputs.sha != '' }}
        id: PR # all the steps below are skipped if 'ready-to-merge' is in the list of labels found here
        uses: 8BitJonny/gh-get-current-pr@4056877062a1f3b624d5d4c2bedefa9cf51435c9 # 4.0.0
        # TODO: this may not work properly if the same commit is pushed to multiple branches:
        # https://github.com/8BitJonny/gh-get-current-pr/issues/8
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          sha: ${{ steps.get-branch-sha.outputs.sha }}
          # Only return if PR is still open
          filterOutClosed: true

      - name: Print PR, if found
        run: echo "Found PR ${prNumber} at ${prUrl}"
        if: steps.PR.outputs.pr_found == '
true'
        env:
          prNumber: ${{ steps.PR.outputs.number }}
          prUrl: ${{ steps.PR.outputs.pr_url }}

      - name: Get latest mathlib-ci SHA
        if: ${{ !contains(steps.PR.outputs.pr_labels, '
ready-to-merge') }}
        id: mathlib-ci-sha
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          SHA=$(gh api repos/leanprover-community/mathlib-ci/commits/HEAD --jq '.sha')
          echo "sha=$SHA" >> "$GITHUB_OUTPUT"

      - name: Update mathlib-ci ref in get-mathlib-ci action
        if: ${{ !contains(steps.PR.outputs.pr_labels, 'ready-to-merge') }}
        id: update-mathlib-ci-ref
        run: |
          sed -i "s|^\( *default: \)[0-9a-f]\{40\}|\1${{ steps.mathlib-ci-sha.outputs.sha }}|" \
            .github/actions/get-mathlib-ci/action.yml
          if git diff --quiet .github/actions/get-mathlib-ci/action.yml; then
            echo "modified=false" >> "$GITHUB_OUTPUT"
          else
            echo "modified=true" >> "$GITHUB_OUTPUT"
          fi

      - name: Download the updated manifest and toolchain
        if: ${{ !contains(steps.PR.outputs.pr_labels, '
ready-to-merge') }}
        uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
        with:
          name: lake-update-result
          path: ${{ runner.temp }}/lake-update-result

      - name: Check the toolchain and apply the updated manifest
        id: check_toolchain
        # The artifact comes from a job that ran upstream code, so treat it as data: skip the PR if
        # the toolchain changed, and otherwise take only the manifest, once it has the shape
        # `lake update` writes.
        if: ${{ !contains(steps.PR.outputs.pr_labels, 'ready-to-merge') }}
        env:
          RESULT_DIR: ${{ runner.temp }}/lake-update-result
        run: |
          for f in lake-manifest.json lean-toolchain; do
            if [ ! -f "$RESULT_DIR/$f" ] || [ -L "$RESULT_DIR/$f" ]; then
              echo "::error::$f is missing from the lake-update-result artifact or is not a regular file"
              exit 1
            fi
          done
          if ! cmp -s lean-toolchain "$RESULT_DIR/lean-toolchain"; then
            echo "toolchain_modified=true" >> "$GITHUB_OUTPUT"
            echo "Lean toolchain file was modified. Skipping PR creation."
            exit 0
          fi
          if ! jq -e '.packages | type == "array" and all(.[]; .type == "git"
                and (.rev | type == "string" and test("^[0-9a-f]{40}$"))
                and (.url | type == "string" and startswith("https://"))
                and (.inputRev | . == null or type == "string"))'
 \
                "$RESULT_DIR/lake-manifest.json" > /dev/null; then
            echo "
::error::lake-manifest.json from the lake-update job does not look like a Lake manifest"
            exit 1
          fi
          # Apart from the revisions, the manifest must match master's: the same packages, URLs and
          # so on. A transitive package'
s `inputRev` is copied from its parent's manifest, so it may
          # change too. When an update legitimately changes more, a maintainer should do it by hand.
          # The packages are sorted rather than keyed by name, so a duplicate entry is a difference.
          shape='
del(.packages[].rev) | .packages |= (
            map(if .inherited then del(.inputRev) else . end) | sort_by(.name)
          )'
          if ! diff <(jq -S "$shape" lake-manifest.json) <(jq -S "$shape" "$RESULT_DIR/lake-manifest.json"); then
            echo "::error::lake update changed more than the dependencies'
 revisions (diff above: master, then the update); update the dependencies by hand"
            exit 1
          fi
          cp "
$RESULT_DIR/lake-manifest.json" lake-manifest.json
          echo "toolchain_modified=false" >> "$GITHUB_OUTPUT"

      - name: Determine PR state
        # only run if check_toolchain ran and returned "false"
        if: ${{ steps.check_toolchain.outputs.toolchain_modified == 'false' }}
        id: determine_state
        run: |
          # Tracked files: lake-manifest.json and .github/actions/get-mathlib-ci/action.yml
          #
          # Two-layer model
          # ────────────────────────────────────────────────────────────────────
          # create-pull-request (CPR) compares against master: it always
          # force-pushes when called with any pending changes, even if the branch
          # already has identical content.  This gate is therefore the ONLY
          # mechanism preventing unnecessary force-pushes.
          #
          # needs_update : working tree differs from master   → PR should exist
          # branch_stale : working tree differs from branch tip → CPR would push
          #
          # States (checked in priority order):
          #   IDLE       : no open PR + !needs_update → skip CPR
          #   SUPERSEDED : open PR + !needs_update  → call CPR to close PR
          #   CONFLICT   : merge-conflict label     → call CPR to rebase
          #   STALE      : open PR + branch_stale   → call CPR to update branch
          #   ABSENT     : needs_update + (no branch or no open PR) → call CPR to create PR
          #   PENDING    : open PR + needs_update + !branch_stale → skip CPR

          # ── inputs ──────────────────────────────────────────────────────────
          needs_update=false
          if ! git diff --quiet "origin/master" -- lake-manifest.json || \
             [ "${{ steps.update-mathlib-ci-ref.outputs.modified }}" == "true" ]; then
            needs_update=true
          fi

          branch_stale=false
          if [ -n "${{ steps.get-branch-sha.outputs.sha }}" ]; then
            if ! git diff --quiet "origin/$BRANCH_NAME" -- lake-manifest.json || \
               ! git diff --quiet "origin/$BRANCH_NAME" -- .github/actions/get-mathlib-ci/action.yml; then
              branch_stale=true
            fi
          fi

          pr_open="
${{ steps.PR.outputs.pr_found }}"
          merge_conflict="
${{ contains(steps.PR.outputs.pr_labels, 'merge-conflict') }}"

          echo "needs_update=$needs_update"
          echo "branch_stale=$branch_stale"
          echo "pr_open=$pr_open"
          echo "merge_conflict=$merge_conflict"

          # ── state ───────────────────────────────────────────────────────────
          if [ "$pr_open" != "true" ] && [ "$needs_update" == "false" ]; then
            state="IDLE"
          elif [ "$pr_open" == "true" ] && [ "$needs_update" == "false" ]; then
            state="SUPERSEDED"
          elif [ "$merge_conflict" == "true" ]; then
            state="CONFLICT"
          elif [ "$pr_open" == "true" ] && [ "$branch_stale" == "true" ]; then
            state="STALE"
          elif [ -z "${{ steps.get-branch-sha.outputs.sha }}" ] || [ "$pr_open" != "true" ]; then
            state="ABSENT"
          else
            state="PENDING"
          fi

          echo "State: $state"
          echo "state=$state" >> "$GITHUB_OUTPUT"

          if [ "$state" == "PENDING" ] || [ "$state" == "IDLE" ]; then
            create_pr=false
          else
            create_pr=true
          fi
          echo "create_pr=$create_pr" >> "$GITHUB_OUTPUT"

      - name: Generate PR title
        id: pr-title
        if: ${{ steps.determine_state.outputs.create_pr == '
true' }}
        run: |
          echo "timestamp=$(date -u +"%Y-%m-%d-%H-%M")" >> "$GITHUB_ENV"
          echo "pr_title=chore: update Mathlib dependencies $(date -u +"%Y-%m-%d")" >> "$GITHUB_ENV"

      - name: Create Pull Request
        if: ${{ steps.pr-title.outcome == 'success' }}
        uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          # this needs to be set, otherwise the last person who edited the `cron` line may get tagged
          author: "mathlib-update-dependencies[bot] <258990618+mathlib-update-dependencies[bot]@users.noreply.github.com>"
          token: ${{ steps.app-token.outputs.token }}
          commit-message: "chore: update Mathlib dependencies ${{ env.timestamp }}"
          # this branch is referenced in update_dependencies_zulip.yml
          branch: ${{ env.BRANCH_NAME }}
          base: master
          # Only the files this workflow means to change, whatever else is in the working tree.
          add-paths: |
            lake-manifest.json
            .github/actions/get-mathlib-ci/action.yml
          title: "${{ env.pr_title }}"
          body: |
            This PR updates the Mathlib dependencies.

            It is not merged automatically: a maintainer should look at what the new
            dependency revisions bring in before sending it to bors.

            ---

            [workflow run for this PR](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

  notify-failure:
    name: Report a failure on Zulip
    needs: [lake-update, update-pr]
    if: ${{ failure() }}
    runs-on: ubuntu-latest
    permissions: {}
    steps:
      - name: Send Zulip message (failure)
        uses: zulip/github-actions-zulip/send-message@f675f2b4eb2a95fae974215476dcb7ad8dfeff6b # v2.0.2
        with:
          api-key: ${{ secrets.ZULIP_API_KEY }}
          email: '
github-mathlib4-bot@leanprover.zulipchat.com'
          organization-url: 'https://leanprover.zulipchat.com'
          to: 'nightly-testing-mathlib'
          type: 'stream'
          topic: 'Mathlib `lake update` failure'
          content: |
            ["Update dependencies" workflow run failed!](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

[Dauer der Verarbeitung: 0.5 Sekunden, vorverarbeitet 2026-11-18]