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  maintainer_merge_wf_run.yml  Sprache: unbekannt

 
Spracherkennung für: .yml vermutete Sprache: Abap {ABAP[72] Algol[39] SPS[32]} [Methode: maximale Elemente, drei Dimensionen]

name: Maintainer merge (workflow_run)

# triggers the action when
on:
  workflow_run:
    workflows: ["Maintainer merge"]
    types:
      - completed

jobs:
  ping_zulip:
    name: Ping maintainers on Zulip
    runs-on: ubuntu-latest
    if: ${{ github.repository == 'leanprover-community/mathlib4' && github.event.workflow_run.conclusion == 'success' }}
    permissions:
      actions: read
      contents: read
      id-token: write
      issues: read # for `verify` on issue comments
      pull-requests: write
    steps:
      # For review events, GitHub runs the producer workflow from the PR, so the artifact is
      # untrusted. With `verify`, the bridge fetches the comment or review and its PR from the
      # API and checks them against GitHub's record of the producer run; we only use those
      # verified values (and `run.*`), never the artifact's own contents.
      - name: Consume bridge artifact
        id: bridge
        uses: leanprover-community/privilege-escalation-bridge/consume@120e98bbb1e9438be8973be645ef67e9cddc39ba # v2.1.0
        with:
          artifact: workflow-data
          source_workflow: Maintainer merge
          require_event: issue_comment,pull_request_review,pull_request_review_comment
          verify: true
          fail_on_missing: false
          token: ${{ github.token }}
          extract: |
            author=verified.trigger.author
            comment=verified.trigger.body
            pr_number=verified.pr.number
            pr_author=verified.pr.author
            pr_title=verified.pr.title
            pr_url=verified.pr.url
            event_name=run.event

      - name: Find maintainer merge/delegate
        id: merge_or_delegate
        if: ${{ steps.bridge.outputs.pr_number != '
' }}
        env:
          AUTHOR: ${{ steps.bridge.outputs.author }}
          COMMENT: ${{ steps.bridge.outputs.comment }}
        run: |
          # same parsing as in maintainer_merge.yml, but applied to the verified comment
          # we strip `\r` since line endings from GitHub contain this character
          COMMENT="${COMMENT//$'
\r'/}"

          # mathlib-splicebot[bot] relays put the command on the first line (see the comment
          # template in the SPLICEBOT_LABEL_COMMANDS repo variable), while its other comments
          # can quote user-controlled text (such as file names) on later lines, so for the bot
          # we only look at the first line.
          if [ "${AUTHOR}" = "mathlib-splicebot[bot]" ]
          then
            COMMENT="${COMMENT%%$'
\n'*}"
          fi

          m_or_d="$(printf '
%s' "${COMMENT}" |
            # captures `maintainer merge/delegate` as well as an optional `?`, ignoring subsequent spaces
            sed -n '
s=^maintainer  *\(merge\|delegate\)\(?\?\) *$=\1\2=p' | head -1)"

          printf $'"maintainer delegate" or "maintainer merge" found? \'%s\'\n' "${m_or_d}"

          printf $'mOrD=%s\n' "${m_or_d}" >> "${GITHUB_OUTPUT}"

      - if: ${{ steps.merge_or_delegate.outputs.mOrD != '' }}
        name: Resolve splice-bot attribution
        id: attribution
        env:
          AUTHOR: ${{ steps.bridge.outputs.author }}
          COMMENT: ${{ steps.bridge.outputs.comment }}
        run: |
          # When mathlib-splicebot[bot] relays a 'maintainer merge/delegate' command
          # from a review comment on the original PR, its comment ends with an
          # attribution line of the form (see the SPLICEBOT_LABEL_COMMANDS repo variable)
          #   Requested by @reviewer via splice-bot from #12345.
          # so the Zulip report and PR comment credit the requesting reviewer instead
          # of the bot. The requester's free text is rendered by SpliceBot as a
          # markdown blockquote, so this line-anchored match cannot be forged; we
          # additionally only trust the attribution line when the comment author is
          # the bot itself.
          display_author="${AUTHOR}"
          if [ "${AUTHOR}" = "mathlib-splicebot[bot]" ]
          then
            attributed="$(printf '
%s' "${COMMENT}" | tr -d '\r' |
              sed -n '
s=^Requested by @\([A-Za-z0-9-][A-Za-z0-9-]*\) via splice-bot from #\([0-9][0-9]*\)\.$=\1 (via splice-bot from #\2)=p' | tail -1)"
            if [ -n "${attributed}" ]
            then
              display_author="${attributed}"
            fi
          fi
          echo "display_author=${display_author}" | tee -a "$GITHUB_OUTPUT"

      # bot usernames would cause this step to error with "Could not resolve to a User...",
      # so we skip it for all bot accounts; allowed bots are validated in the next step
      - if: ${{ steps.merge_or_delegate.outputs.mOrD != '' && ! endsWith(steps.bridge.outputs.author, '[bot]') }}
        name: Check whether user is part of mathlib-reviewers team
        uses: tspascoal/get-user-teams-membership@b2546c5affc730fd8e3d8483ae9ad3621938c2f9 # v4.0.2
        id: actorTeams
        with:
          organization: leanprover-community # optional. Default value ${{ github.repository_owner }}
                  # Organization to get membership from.
          team: 'mathlib-reviewers'
          username: ${{ steps.bridge.outputs.author }}
          GITHUB_TOKEN: ${{ secrets.MATHLIB_REVIEWERS_TEAM_KEY }} # (Requires scope: `read:org`)

      - if: ${{ steps.merge_or_delegate.outputs.mOrD != '' }}
        name: Determine whether the author may use the maintainer merge command
        id: authorized
        env:
          AUTHOR: ${{ steps.bridge.outputs.author }}
          IS_TEAM_MEMBER: ${{ steps.actorTeams.outputs.isTeamMember }}
        run: |
          # mathlib-splicebot[bot] posts 'maintainer merge' comments on split PRs
          # on behalf of reviewers; SpliceBot's command-level authorization
          # (see SPLICEBOT_LABEL_COMMANDS) has already checked that the
          # requester is a reviewer or maintainer.
          if [ "${IS_TEAM_MEMBER}" = "true" ] || [ "${AUTHOR}" = "mathlib-splicebot[bot]" ]
          then
            echo "authorized=true" | tee -a "$GITHUB_OUTPUT"
          else
            echo "authorized=false" | tee -a "$GITHUB_OUTPUT"
          fi

      - name: Checkout local actions
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ github.workflow_sha }}
          fetch-depth: 1
          sparse-checkout: .github/actions
          path: workflow-actions
      - name: Get mathlib-ci
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        uses: ./workflow-actions/.github/actions/get-mathlib-ci

      - name: Determine Zulip topic
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        id: determine_topic
        run: |
          "${CI_SCRIPTS_DIR}/maintainer/get_tlabel.sh" "/repos/leanprover-community/mathlib4/issues/${PR_NUMBER}" >> "$GITHUB_OUTPUT"
        env:
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
          PR_NUMBER: ${{ steps.bridge.outputs.pr_number }}

      - name: Form the message
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        id: form_the_message
        run: |
          message="$(
            "${CI_SCRIPTS_DIR}/maintainer/maintainer_merge_message.sh" "${AUTHOR}" "${M_OR_D}" "${EVENT_NAME}" "${PR_NUMBER}" "${PR_URL}" "${PR_TITLE}" "${COMMENT}" "${PR_AUTHOR}"
          )"
          trigger_name="${EVENT_NAME}"
          trigger_run_url="${{ github.event.workflow_run.html_url }}"
          wf_run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          metadata=$'
['"${trigger_name}"$']('"${trigger_run_url}"$'), [wf_run]('"${wf_run_url}"$')'
          echo "${metadata}"
          # message="${message}"$'
\n\n---\n'"${metadata}"
          printf '
title<<EOF\n%s\nEOF' "${message}" | tee "$GITHUB_OUTPUT"
        env:
          AUTHOR: ${{ steps.attribution.outputs.display_author }}
          M_OR_D: ${{ steps.merge_or_delegate.outputs.mOrD }}
          EVENT_NAME: ${{ steps.bridge.outputs.event_name }}
          PR_NUMBER: ${{ steps.bridge.outputs.pr_number }}
          PR_URL: ${{ steps.bridge.outputs.pr_url }}
          PR_TITLE: ${{ steps.bridge.outputs.pr_title }}
          COMMENT: ${{ steps.bridge.outputs.comment }}
          PR_AUTHOR: ${{ steps.bridge.outputs.pr_author }}

      - name: Send message on Zulip
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        continue-on-error: 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: '
mathlib reviewers'
          type: '
stream'
          topic: ${{ steps.determine_topic.outputs.topic }}
          content: ${{ steps.form_the_message.outputs.title }}

      - name: Compose PR comment body
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        id: pr_comment
        env:
          DISPLAY_AUTHOR: ${{ steps.attribution.outputs.display_author }}
          EVENT_NAME: ${{ steps.bridge.outputs.event_name }}
        run: |
          body="�� Pull request has been placed on the maintainer queue by ${DISPLAY_AUTHOR}."
          trigger_name="${EVENT_NAME}"
          trigger_run_url="${{ github.event.workflow_run.html_url }}"
          wf_run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          metadata=$'
['"${trigger_name}"$']('"${trigger_run_url}"$'), [wf_run]('"${wf_run_url}"$')'
          echo "${metadata}"
          # body="${body}"$'
\n\n---\n'"${metadata}"
          printf '
body<<EOF\n%s\nEOF\n' "${body}" | tee -a "$GITHUB_OUTPUT"

      - name: Add comment to PR
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        continue-on-error: true
        uses: GrantBirki/comment@937820f3623fd0e300294bcc64ac7577fc0ad4cc # v3.0.3
        with:
          issue-number: ${{ steps.bridge.outputs.pr_number }}
          body: ${{ steps.pr_comment.outputs.body }}

      - if: ${{ steps.authorized.outputs.authorized == '
true' }}
        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_TRIAGE_APP_ID }}
          key-vault-name: ${{ vars.MATHLIB_AZ_KEY_VAULT_NAME }}
          key-name: mathlib-triage-app-pk
          azure-client-id: ${{ vars.GH_APP_AZURE_CLIENT_ID_TRIAGE }}
          azure-tenant-id: ${{ secrets.LPC_AZ_TENANT_ID }}

      - name: Add label to PR
        if: ${{ steps.authorized.outputs.authorized == '
true' }}
        continue-on-error: true
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        env:
          PR_NUMBER: ${{ steps.bridge.outputs.pr_number }}
        with:
          # labels added by GITHUB_TOKEN won'
t trigger the Zulip emoji workflow
          # This token is masked by the token minting action and will not be logged accidentally.
          github-token: ${{ steps.app-token.outputs.token }}
          script: |
            const { owner, repo } = context.repo;
            const issue_number = Number(process.env.PR_NUMBER);
            await github.rest.issues.addLabels({ owner, repo, issue_number, labels: ['maintainer-merge'] });

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