Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  PR_summary.yml  Sprache: unbekannt

 
Spracherkennung für: .yml vermutete Sprache: SQL {SQL[60] MT940[50] VDM[45]} [Methode: maximale Elemente, drei Dimensionen]

name: Post PR summary comment

on:
  pull_request_target:

# Limit permissions for GITHUB_TOKEN for the entire workflow
permissions:
  contents: read
  pull-requests: write  # Only allow PR comments/labels
  # All other permissions are implicitly 'none'

jobs:
  build:
    name: "post-or-update-summary-comment"
    runs-on: ubuntu-latest
    if: github.repository == 'leanprover-community/mathlib4'

    steps:
    - name: Checkout code
      uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        fetch-depth: 0
        path: pr-branch
        # Untrusted (potentially fork) checkout: don't persist the GITHUB_TOKEN into its .git/config.
        persist-credentials: false
        # Only trusted base-repo scripts run against this checkout, so checking out
        # fork PR code under pull_request_target is safe.
        allow-unsafe-pr-checkout: true

    - name: Checkout local actions
      uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      with:
        ref: ${{ github.workflow_sha }}
        fetch-depth: 1
        sparse-checkout: .github/actions
        path: workflow-actions
        persist-credentials: false
    - name: Get mathlib-ci
      uses: ./workflow-actions/.github/actions/get-mathlib-ci

    - name: Update the merge-conflict label
      run: |
        cd pr-branch
        printf '
PR number: "%s"\n' "${{ github.event.pull_request.number }}"
        git config user.name "leanprover-community-mathlib4-bot"
        git config user.email "leanprover-community-mathlib4-bot@users.noreply.github.com"

        if git merge origin/master --no-ff --no-commit
        then
          git merge --abort || true
          echo "This PR does not have merge conflicts with master."
          # we use curl rather than octokit/request-action so that the job won'
t fail
          # (and send an annoying email) if the labels don't exist
          curl --request DELETE \
            --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/merge-conflict \
            --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'

        else
          echo "This PR has merge conflicts with master."
          # we use curl rather than octokit/request-action so that the job won't fail
          # (and send an annoying email) if the labels don'
t exist
          curl --request POST \
            --header 'Accept: application/vnd.github+json' \
            --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
            --header 'X-GitHub-Api-Version: 2022-11-28' \
            --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
            --data '{"labels":["merge-conflict"]}'
        fi

    - name: Set up Python
      uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
      with:
        python-version: 3.x

    - name: Install dependencies
      run: |
        sudo apt-get install -y jq
        # If you have additional dependencies, install them here

    - name: Get changed and removed/renamed files
      run: |
        cd pr-branch
        git fetch origin ${{ github.base_ref }}  # fetch the base branch

        # Get the list of all changed files.
        echo "Saving the changed files to 'changed_files.txt'..."
        git diff --name-only origin/${{ github.base_ref }}... | tee changed_files.txt

        # Get all newly added files.
        echo "Checking for added files..."
        git diff --name-only --diff-filter A origin/${{ github.base_ref }}... | tee added_files.txt

        # Get all Lean files which were removed or renamed.
        echo "Checking for removed files..."

        # Shows the `D`eleted files, one per line.
        git diff --name-only --diff-filter D origin/${{ github.base_ref }}... -- '*.lean' | tee removed_files.txt
        echo "Checking for renamed files..."

        # Shows the `R`enamed files, in human-readable format
        # The `awk` pipe
        # * extracts into an array the old name as the key and the new name as the value
        # * eventually prints "`oldName` was renamed to `newName`" for each key-value pair.
        git diff -p --summary --diff-filter=R origin/${{ github.base_ref }}... -- '*.lean' |
          awk '
            /^rename from / {
                file=$0
                gsub(/rename from /, "", file)
                oldFile=file
              }
            /^rename to / {
                file=$0
                gsub(/rename to /, "", file)
                oldNew[oldFile]=file
              } END {
                for(old in oldNew) {
                  printf("`%s` was renamed to `%s`\n", old, oldNew[old])
                }
              }'
 | tee renamed_files.txt

    - name: Compute (re)moved files without deprecation
      run: |
        cd pr-branch
        touch moved_without_deprecation.txt
        touch extraneous_deprecated_module.txt
        git checkout ${{ github.base_ref }}
        while IFS= read -r file
        do
          if grep ^deprecated_module "${file}" ; then
            # shellcheck disable=SC2016
            printf '\n⚠️ **warning**: removed file `%s` contains a module deprecation: please add this in a follow-up PR instead\n' "${file}" |
              tee -a extraneous_deprecated_module.txt
          else
            # shellcheck disable=SC2016
            printf '\nnote: file `%s` was removed.\nPlease create a follow-up pull request adding a module deprecation. Thanks!\n' "${file}" |
              tee -a moved_without_deprecation.txt
          fi
        done < removed_files.txt
        IFS=$'\n'
        while IFS= read -r file
        do
          if grep ^deprecated_module "${file}" ; then
            # shellcheck disable=SC2016
            printf '\n⚠️ **warning**: renamed file `%s` contains a module deprecation: please add this in a follow-up PR instead\n' "${file}" |
              tee -a extraneous_deprecated_module.txt
          else
            # shellcheck disable=SC2016
            printf '\nnote: file `%s` without a module deprecation\nPlease create a follow-up pull request adding one. Thanks!\n' "${file}" |
              tee -a moved_without_deprecation.txt
          fi
        done < renamed_files.txt

        # we return to the PR branch, since the next step wants it!
        git checkout -

    - name: Compute transitive imports
      run: |
        cd pr-branch
        # the checkout dance, to avoid a detached head
        git checkout master
        git checkout -
        currentHash="$(git rev-parse HEAD)"
        printf 'currentHash=%s\n' "${currentHash}"

        echo "Compute the counts for the HEAD of the PR"
        python "${CI_SCRIPTS_DIR}/pr_summary/count-trans-deps.py" "Mathlib/" > head.json

        # Checkout the merge base
        git checkout "$(git merge-base master ${{ github.event.pull_request.head.sha }})"

        echo "Compute the counts for the merge base"
        python "${CI_SCRIPTS_DIR}/pr_summary/count-trans-deps.py" "Mathlib/" > base.json

        # switch back to the current branch: the `declarations_diff` script should be here
        git checkout "${currentHash}" --

    - name: Post or update the summary comment
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        BRANCH_NAME: ${{ github.head_ref }}
      run: |
        cd pr-branch
        currentHash="$(git rev-parse HEAD)"
        PR="${{ github.event.pull_request.number }}"
        title="### PR summary"

        graphAndHighPercentReports=$(python "${CI_SCRIPTS_DIR}/pr_summary/import-graph-report.py" base.json head.json changed_files.txt)

        echo "Produce import count comment"
        importCount=$(
          printf '%s\n' "${graphAndHighPercentReports}" | sed '/^Import changes exceeding/Q'
          "${CI_SCRIPTS_DIR}/pr_summary/import_trans_difference.sh"
        )

        echo "Produce high percentage imports"
        high_percentages=$(
          printf '%s\n' "${graphAndHighPercentReports}" | sed -n '/^Import changes exceeding/,$p'
        )
        # if there are files with large increase in transitive imports, then we add the `large-import` label
        if [ -n "${high_percentages}" ]
        then
          high_percentages=$'\n\n'"${high_percentages}"
          gh pr edit "${PR}" --add-label large-import
        else # otherwise, we remove the label
          gh pr edit "${PR}" --remove-label large-import
        fi

        if [ "$(printf '%s' "${importCount}" | wc -l)" -gt 12 ]
        then
          importCount="$(printf '<details><summary>\n\n%s\n\n</summary>\n\n%s\n\n</details>\n' "#### Import changes for modified files" "${importCount}")"
        else
          importCount="$(printf '#### Import changes for modified files\n\n%s\n' "${importCount}")"
        fi

        echo "Compute Declarations' diff comment"
        declDiff=$("${CI_SCRIPTS_DIR}/pr_summary/declarations_diff.sh")
        if [ "$(printf '%s' "${declDiff}" | wc -l)" -gt 15 ]
        then
          declDiff="$(printf '<details><summary>\n\n%s\n\n</summary>\n\n%s\n\n</details>\n' "#### Declarations diff (regex)" "${declDiff}")"
        else
          declDiff="$(printf '#### Declarations diff (regex)\n\n%s\n' "${declDiff}")"
        fi
        # Append the post-build, Lean-aware diff region. The `decls-diff.yml`
        # workflow later replaces the content between the markers (see mathlib-ci's
        # `updateDeclsDiffSection.py`); the regex block above is left as-is. The
        # markers are HTML comments (invisible when rendered), and the heading
        # carries the status (`pending` → `(Lean)` / `(Lean -- unavailable)`).
        #
        # Because this pre-build step rewrites the whole comment, it would otherwise
        # blank a previously-shown diff back to `pending` on every push. Instead we
        # ask `updateDeclsDiffSection.py` (MODE=emit) to carry the existing real diff
        # forward — relabelled stale — so it stays visible until the new build lands;
        # on the first run (or with no prior diff) it prints the pending placeholder.
        leanRegion="$(MODE=emit \
          NEW_HEADING='
#### Declarations diff (Lean -- stale, waiting for the new build)' \
          REPO="${{ github.repository }}" PR_NUMBER="${PR}" PR_HEAD_SHA="${currentHash}" \
          python3 "${CI_SCRIPTS_DIR}/pr_summary/updateDeclsDiffSection.py" \
          || printf '#### Declarations diff (Lean -- pending)\n\n_Computed after the build finishes._')"
        declDiff="$(printf '
%s\n\n<!-- DECLS_DIFF_LEAN_BEGIN -->\n%s\n<!-- DECLS_DIFF_LEAN_END -->\n' "${declDiff}" "${leanRegion}")"
        git checkout "${currentHash}" --
        hashURL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}/commits/${currentHash}"
        printf 'hashURL: %s' "${hashURL}"

        echo "Compute technical debt changes"
        techDebtVar="$("${CI_SCRIPTS_DIR}/reporting/technical-debt-metrics.sh" pr_summary)"

        # If the PR decreased technical debt, add the `tech debt` label.
        # The metrics script emits a summary line "Decrease in <level> tech debt:" for each
        # level (strong/weak) that went down (and "Increase ..."/"No changes ..." otherwise),
        # so matching either of those two lines means the PR reduced some tech debt.
        if grep -qE "Decrease in (strong|weak) tech debt" <<< "${techDebtVar}"
        then
          printf $'Adding "tech debt" label to PR %s\n' "${PR}"
          gh pr edit "${PR}" --add-label "tech debt"
        fi

        # mathlib-ci classifies tech debt into `strong` (e.g. porting notes,
        # adaptation notes, erw, maxHeartbeats modifications — should rarely
        # increase) and `weak` (large files, exposed public sections, simp
        # +instances, deprecated files — fine to increase in a normal PR).
        # The `increases-technical-debt` label flags a PR that increases a
        # STRONG metric, so that a reviewer notices. It does not block merging.
        #
        # We test for the *safe* patterns rather than the *unsafe* one so that
        # if mathlib-ci changes the script's output wording we fail loudly
        # (label added) rather than silently (label never added).
        if printf '
%s' "${techDebtVar}" | grep -qE 'Decrease in strong tech debt:|No changes to strong technical debt\.'; then
          gh pr edit "${PR}" --remove-label increases-technical-debt
        else
          gh pr edit "${PR}" --add-label increases-technical-debt
        fi

        echo "Compute documentation reminder"
        workflowFilesChanged="$(grep '
^\.github/workflows/' changed_files.txt || true)"
        if [ -n "${workflowFilesChanged}" ]
        then
          # Format each changed workflow path as a Markdown bullet: "- `path`"
          workflowFilesChangedMarkdown="$(sed "s|^|- \`|; s|\$|\`|" <<< "${workflowFilesChanged}")"
          workflowDocsReminder="$(printf "### ⚠️ Workflow documentation reminder\nThis PR modifies files under \`.github/workflows/\`.\nPlease update \`docs/workflows.md\` if the workflow inventory, triggers, or behavior changed.\n\nModified workflow files:\n%s\n" "${workflowFilesChangedMarkdown}")"
        else
          workflowDocsReminder=""
        fi

        echo "Compute scripts-location reminder"
        scriptsFilesAdded="$(grep '
^scripts/' added_files.txt || true)"
        if [ -n "${scriptsFilesAdded}" ]
        then
          # Format each added scripts path as a Markdown bullet: "- `path`"
          scriptsFilesAddedMarkdown="$(sed "s|^|- \`|; s|\$|\`|" <<< "${scriptsFilesAdded}")"
          scriptsLocationReminder="$(printf "### ⚠️ Scripts folder reminder\nThis PR adds files under \`scripts/\`.\nPlease consider whether each added script belongs in this repository or in [\`leanprover-community/mathlib-ci\`](https://github.com/leanprover-community/mathlib-ci).\n\nA script belongs in **\`mathlib-ci\`** if it is a CI automation script that interacts with GitHub (e.g. managing labels, posting comments, triggering bots), runs from a trusted external checkout in CI, or requires access to secrets.\n\nA script belongs in **this repository** (\`scripts/\`) if it is a developer or maintainer tool to be run locally, a code maintenance or analysis utility, a style linting tool, or a data file used by the library'
s own linters.\n\nSee the [\`mathlib-ci\` README](https://github.com/leanprover-community/mathlib-ci) for more details.\n\nAdded scripts files:\n%s\n" "${scriptsFilesAddedMarkdown}")"
        else
          scriptsLocationReminder=""
        fi

        # store in a file, to avoid "long arguments" error.
        printf '%s [%s](%s)%s\n\n%s\n\n---\n\n%s\n\n---\n\n%s\n' "${title}" "$(git rev-parse --short HEAD)" "${hashURL}" "${high_percentages}" "${importCount}" "${declDiff}" "${techDebtVar}" > please_merge_master.md
        if [ -n "${workflowDocsReminder}" ]
        then
          printf '
\n\n---\n\n%s\n' "${workflowDocsReminder}" >> please_merge_master.md
        fi
        if [ -n "${scriptsLocationReminder}" ]
        then
          printf '\n\n---\n\n%s\n' "${scriptsLocationReminder}" >> please_merge_master.md
        fi

        echo "Include any errors about removed or renamed files without deprecation,"
        echo "as well as errors about extraneous deprecated_module additions."
        if [ -s moved_without_deprecation.txt ]
        then
          printf '
\n\n---\n\n' >> please_merge_master.md
          cat moved_without_deprecation.txt >> please_merge_master.md
        fi
        if [ -s extraneous_deprecated_module.txt ]
        then
          printf '\n\n---\n\n' >> please_merge_master.md
          cat extraneous_deprecated_module.txt >> please_merge_master.md
        fi

        cat please_merge_master.md
        "${CI_SCRIPTS_DIR}/pr_summary/update_PR_comment.sh" please_merge_master.md "${title}" "${PR}"

    - name: Update the file-removed label
      run: |
        cd pr-branch
        undeprecatedMoves="$(cat moved_without_deprecation.txt)"
        if [ -n "$undeprecatedMoves" ]; then
          echo "This PR has undeprecated module (re)movals."
          # we use curl rather than octokit/request-action so that the job won'
t fail
          # (and send an annoying email) if the labels don't exist
          curl --request POST \
            --header 'Accept: application/vnd.github+json' \
            --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
            --header 'X-GitHub-Api-Version: 2022-11-28' \
            --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
            --data '{"labels":["file-removed"]}'

        else
          echo "This PR (re)moves no modules without deprecations."
          # we use curl rather than octokit/request-action so that the job won't fail
          # (and send an annoying email) if the labels don'
t exist
          curl --request DELETE \
            --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/file-removed \
            --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
        fi

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

                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,106
#Domains=862,749