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

Quelle  remove_deprecated_decls.yml  Sprache: unbekannt

 
Spracherkennung für: .yml vermutete Sprache: Masm {Masm[40] ABAP[37] BAT[36]} [Methode: maximale Elemente, drei Dimensionen]

name: Remove outdated deprecated declarations

on:
  schedule:
  - cron: "5 4 15 * *" # At 04:05, on the 15th of every month
  workflow_dispatch:
    inputs:
      raw_from_date:
        description: 'starting date for deprecations to remove: YYYY-MM-DD or valid input for date -d, like "5 years ago"'
        required: false
        default: '5 years ago'
        type: string
      raw_to_date:
        description: 'ending date for deprecations to remove: YYYY-MM-DD or valid input for date -d, like "6 months ago"'
        required: false
        default: '6 months ago'
        type: string
      dry_run:
        description: 'if true, only log the outdated declarations, do not remove them and open a PR'
        required: false
        default: false
        type: boolean

env:
  MATHLIB_CACHE_BASE_URL: ${{ vars.MATHLIB_CACHE_BASE_URL }}
  MATHLIB_CACHE_PARALLEL_MAX: ${{ vars.MATHLIB_CACHE_PARALLEL_MAX }}

jobs:
  build:
    name: Remove outdated deprecated declarations
    runs-on: ubuntu-latest
    if: github.repository == 'leanprover-community/mathlib4'
    permissions:
      contents: read
      pull-requests: read
      id-token: write
    env:
      BRANCH_NAME: "deprecated-decls"
    steps:
    - name: Process dates
      id: process_dates
      shell: bash
      env:
        RAW_FROM_DATE: ${{ inputs.raw_from_date }}
        RAW_TO_DATE: ${{ inputs.raw_to_date }}
      run: |
        set -euo pipefail

        # Function to validate YYYY-MM-DD format
        validate_iso_date() {
          local date_str="$1"
          if [[ "$date_str" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
            # Validate it's a real date by parsing it
            if date -d "$date_str" >/dev/null 2>&1; then
              echo "$date_str"
              return 0
            fi
          fi
          return 1
        }

        # Function to safely parse date using `date -d`
        parse_date_safely() {
          local input="$1"

          # Try to parse with date -d and extract YYYY-MM-DD format
          local parsed_date
          if parsed_date=$(date -d "$input" +%Y-%m-%d 2>/dev/null); then
            echo "$parsed_date"
            return 0
          else
            echo "Error: Unable to parse date: $input" >&2
            return 1
          fi
        }

        # Process from_date
        if [[ -n "${RAW_FROM_DATE:-}" ]]; then
          echo "Processing raw_from_date: '
${RAW_FROM_DATE}'"

          if from_date=$(validate_iso_date "${RAW_FROM_DATE}"); then
            echo "Valid ISO date format detected"
          else
            echo "Not a valid ISO date, trying date parser..."
            from_date=$(parse_date_safely "${RAW_FROM_DATE}")
          fi
        else
          echo "No raw_from_date provided, using 5 years ago"
          from_date=$(date -d '
5 years ago' +%Y-%m-%d)
        fi

        # Process to_date
        if [[ -n "${RAW_TO_DATE:-}" ]]; then
          echo "Processing raw_to_date: '
${RAW_TO_DATE}'"

          if to_date=$(validate_iso_date "${RAW_TO_DATE}"); then
            echo "Valid ISO date format detected"
          else
            echo "Not a valid ISO date, trying date parser..."
            to_date=$(parse_date_safely "${RAW_TO_DATE}")
          fi
        else
          echo "No raw_to_date provided, using 6 months ago"
          to_date=$(date -d '
6 months ago' +%Y-%m-%d)
        fi

        echo "Parsed dates - from: $from_date, to: $to_date"

        # Validate date range - from_date should not be after to_date
        if [[ "$from_date" > "$to_date" ]]; then
          echo "Error: from_date ($from_date) cannot be after to_date ($to_date)" >&2
          exit 1
        fi

        # Set outputs
        echo "from_date=$from_date" >> "$GITHUB_OUTPUT"
        echo "to_date=$to_date" >> "$GITHUB_OUTPUT"

    - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

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

    - name: Retrieve caches for unmodified repositories
      run: |
        # Retrieve the cache for the unmodified repository
        # show the current pwd:
        printf $'
Current directory is: %s\n' "$(pwd)"
        printf $'
::group::Running lake env\n'
        lake env | tr '
:' '\n'
        echo "::endgroup::"
        for repo in Mathlib Archive Counterexamples Wanted; do
          echo "::group::Retrieving the cache for ${repo}"
          lake exe cache get "$repo" || true
          echo "::endgroup::"
        done

    - name: set up deprecated doubles
      env:
        OLD_DATE: "${{ steps.process_dates.outputs.from_date }}"
        NEW_DATE: "${{ steps.process_dates.outputs.to_date }}"
        DRY_RUN: "${{ toJson(inputs.dry_run) }}"
      run: |
        # We create a temporary file importing `Mathlib`, `Archive`, `Counterexamples` and
        # `Wanted`, and running `#clear_deprecations` with the expected date-range.
        tmplean="$(mktemp -p Mathlib --suffix=.lean RMDXXX)"
        echo "::group::Creating ${tmplean} file"
        {
          for repo in Mathlib Archive Counterexamples Wanted; do
            printf $'
import %s\n' "$repo"
          done
          REALLY=$([ "$DRY_RUN" = "true" ] && echo "" || echo "really")
          printf $'
#clear_deprecations "%s" "%s" %s\n' "$OLD_DATE" "$NEW_DATE" "$REALLY"
        } | tee -a "${tmplean}"
        echo "::endgroup::"

        # This will add the new files, whose names end in `_with_option.lean` and with the
        # `commandRanges` linter on.  Building these files gives access to the ranges of all
        # the commands in the files with deprecations to be removed.
        # These files ending in `_with_option.lean` get erased after they have been built.
        # If the `really` flag is passed, then the deprecations are removed from the appropriate
        # files.  Otherwise, they are only logged as an output, but the original files are left
        # untouched.
        echo "::group::Building ${tmplean} file -- this may take a while"
        lake build "${tmplean}"
        echo "::endgroup::"

        echo "Deleting ${tmplean}"
        rm "${tmplean}"

    - 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
      if: ${{ steps.get-branch-sha.outputs.sha != '
' }}
      id: find-pr
      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: Send Zulip message (blocked by open PR)
      if: steps.find-pr.outputs.pr_found == '
true'
      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 `remove outdated deprecated declarations`'
        content: |
          Reminder: #${{ steps.find-pr.outputs.number }} is still open; this has prevented [the automatic
          deprecation workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
          from creating a new PR.

    - name: Generate app token
      id: app-token
      if: ${{ steps.process_dates.outputs.from_date && toJson(inputs.dry_run) != '
true' && steps.find-pr.outputs.pr_found != 'true' }}
      uses: leanprover-community/mathlib-ci/.github/actions/azure-create-github-app-token@d6393a535c054122e507b6c5e1b2f4c31c604121
      with:
        app-id: ${{ secrets.MATHLIB_NOLINTS_APP_ID }}
        key-vault-name: ${{ vars.MATHLIB_AZ_KEY_VAULT_NAME }}
        key-name: mathlib-nolints-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: Create Pull Request
      id: pr
      if: ${{ steps.process_dates.outputs.from_date && toJson(inputs.dry_run) != '
true' && steps.find-pr.outputs.pr_found != 'true' }}
      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-nolints[bot] <258989889+mathlib-nolints[bot]@users.noreply.github.com>"
        token: ${{ steps.app-token.outputs.token }}
        commit-message: "chore: remove declarations deprecated between ${{ steps.process_dates.outputs.from_date }} and ${{ steps.process_dates.outputs.to_date }}"
        branch: ${{ env.BRANCH_NAME }}
        base: master
        title: "chore: remove declarations deprecated between ${{ steps.process_dates.outputs.from_date }} and ${{ steps.process_dates.outputs.to_date }}"
        body: |
          I am happy to remove some deprecated declarations for you!
          Please check if there are any remaining stray comments or other issues before merging.

          ---

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

    - name: Send Zulip message (success)
      if: steps.pr.outcome == '
success'
      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 `remove outdated deprecated declarations`'
        content: |
          Please review #${{ steps.pr.outputs.pull-request-number }}, which removes deprecated declarations between ${{ steps.process_dates.outputs.from_date }} and ${{ steps.process_dates.outputs.to_date }}.
          Pay special attention to whether there are stray comments that can also be deleted.

    - name: Send Zulip message (failure)
      if: ${{ toJson(inputs.dry_run) != '
true' && 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 `remove outdated deprecated declarations`'
        content: |
          [`remove outdated deprecated declarations` workflow run failed](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

          triggered by: `${{ github.event_name }}`

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