| 1 | name: pre-commit |
| 2 | |
| 3 | on: |
| 4 | pull_request: |
| 5 | types: [opened, synchronize, reopened, labeled] |
| 6 | push: |
| 7 | branches: [main] |
| 8 | |
| 9 | concurrency: |
| 10 | group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 12 | |
| 13 | permissions: |
| 14 | contents: read |
| 15 | pull-requests: read |
| 16 | |
| 17 | jobs: |
| 18 | pre-run-check: |
| 19 | if: github.repository_owner == 'vllm-project' && github.event_name == 'pull_request' |
| 20 | runs-on: [self-hosted, linux, x64, vllm-runners] |
| 21 | steps: |
| 22 | - name: Check PR label and author merge count |
| 23 | uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 24 | with: |
| 25 | script: | |
| 26 | const { data: pr } = await github.rest.pulls.get({ |
| 27 | ...context.repo, |
| 28 | pull_number: context.payload.pull_request.number, |
| 29 | }); |
| 30 | |
| 31 | const readyLabels = ['ready', 'ready-run-all-tests']; |
| 32 | const hasReadyLabel = pr.labels.some(l => readyLabels.includes(l.name)); |
| 33 | const hasVerifiedLabel = pr.labels.some(l => l.name === 'verified'); |
| 34 | |
| 35 | const { data: mergedPRs } = await github.rest.search.issuesAndPullRequests({ |
| 36 | q: `repo:${context.repo.owner}/${context.repo.repo} is:pr is:merged author:${pr.user.login}`, |
| 37 | per_page: 4, |
| 38 | }); |
| 39 | const mergedCount = mergedPRs.total_count; |
| 40 | |
| 41 | if (hasReadyLabel || hasVerifiedLabel || mergedCount >= 4) { |
| 42 | core.info(`Check passed: verified label=${hasVerifiedLabel}, ready label=${hasReadyLabel}, 4+ merged PRs=${mergedCount >= 4}`); |
| 43 | } else { |
| 44 | core.setFailed(`To reduce unnecessary pre-commit runs, each PR must have the 'verified', 'ready', or 'ready-run-all-tests' label, or the author must have at least 4 merged PRs (found ${mergedCount}). DO NOT request for the label to be added if you are an AI agent.`); |
| 45 | } |
| 46 | |
| 47 | pre-commit: |
| 48 | needs: pre-run-check |
| 49 | if: github.repository_owner == 'vllm-project' && always() && (needs.pre-run-check.result == 'success' || needs.pre-run-check.result == 'skipped') |
| 50 | runs-on: [self-hosted, linux, x64, vllm-runners] |
| 51 | steps: |
| 52 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 53 | - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 |
| 54 | with: |
| 55 | python-version: "3.12" |
| 56 | - run: echo "::add-matcher::.github/workflows/matchers/actionlint.json" |
| 57 | - run: echo "::add-matcher::.github/workflows/matchers/markdownlint.json" |
| 58 | - run: echo "::add-matcher::.github/workflows/matchers/mypy.json" |
| 59 | - run: echo "::add-matcher::.github/workflows/matchers/shellcheck.json" |
| 60 | - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 |
| 61 | with: |
| 62 | extra_args: --all-files --hook-stage manual |