name: "pr-split score" description: "Score a PR's complexity and suggest splits when it's too large" branding: icon: git-pull-request color: blue inputs: max-loc: description: "Maximum target diff lines per sub-PR" default: "400" min-loc: description: "Minimum target diff lines per sub-PR" default: "" partition-strategy: description: "Backend for partitioning (graph or cp_sat)" default: "graph" priority: description: "Grouping priority (orthogonal or logical)" default: "orthogonal" threshold-groups: description: "Minimum suggested groups before showing the split plan" default: "2" python-version: description: "Python version to use" default: "3.12" post-comment: description: "Whether to post a PR comment with the results" default: "true" outputs: total-loc: description: "Total lines of code in the PR diff" value: ${{ steps.score.outputs.total_loc }} total-groups: description: "Number of suggested groups" value: ${{ steps.score.outputs.total_groups }} objective: description: "Plan objective score (lower is better)" value: ${{ steps.score.outputs.objective }} should-split: description: "Whether the PR should be split (true/false)" value: ${{ steps.score.outputs.should_split }} runs: using: composite steps: - name: Install uv uses: astral-sh/setup-uv@v4 - name: Set up Python shell: bash env: UV_PYTHON_VERSION: ${{ inputs.python-version }} run: uv python install "$UV_PYTHON_VERSION" - name: Install pr-split shell: bash env: PARTITION_STRATEGY: ${{ inputs.partition-strategy }} run: | if [ "$PARTITION_STRATEGY" = "cp_sat" ]; then uv tool install "${{ github.action_path }}[cp-sat]" else uv tool install "${{ github.action_path }}" fi - name: Score PR id: score shell: bash env: MAX_LOC: ${{ inputs.max-loc }} MIN_LOC: ${{ inputs.min-loc }} PARTITION_STRATEGY: ${{ inputs.partition-strategy }} PRIORITY: ${{ inputs.priority }} THRESHOLD_GROUPS: ${{ inputs.threshold-groups }} PR_NUMBER: ${{ github.event.pull_request.number }} BASE_BRANCH: ${{ github.event.pull_request.base.ref }} HEAD_BRANCH: ${{ github.event.pull_request.head.ref }} run: python "${{ github.action_path }}/scripts/score_pr.py" - name: Post comment if: inputs.post-comment == 'true' && steps.score.outputs.should_split == 'true' uses: actions/github-script@v7 with: script: | const fs = require('fs'); const body = fs.readFileSync('${{ steps.score.outputs.comment_path }}', 'utf8'); const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, }); const existing = comments.find(c => c.body.includes('')); if (existing) { await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, body, }); }