🔄 synced file(s) with PaddleHQ/go-library-template #86
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DO NOT EDIT: This file should only be modified in the `go-library-template` repo. | |
| name: Label PRs with size and comment if too large | |
| on: | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| actions: write # required for `workflow-dispatch` to trigger the automerge workflow | |
| jobs: | |
| pr_size: | |
| name: Label PRs with size and comment if too large | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Check out code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Calculate lines changed | |
| id: lines_changed | |
| run: | | |
| # 1. Use git diff --shortstat to calculate all changed lines | |
| # 2. Exclude go.mod, go.sum and mocks | |
| # 3. Use awk to sum the added and deleted lines to get total lines changed | |
| LINES_CHANGED=`git diff --shortstat origin/${{ github.event.pull_request.base.ref }} -- \ | |
| ':!go.mod' \ | |
| ':!go.sum' \ | |
| ':!*/mocks/*' \ | |
| | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print inserted+deleted}'` | |
| echo "total=${LINES_CHANGED}" >> "$GITHUB_OUTPUT" | |
| - name: Label PR with size | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # 1. get all labels | |
| # 2. Extract the label name | |
| # 3. Filter by size/* | |
| # 4. remove it | |
| gh pr view ${{ github.event.pull_request.number }} \ | |
| --json labels \ | |
| -q '.labels[].name | select(. | startswith("size/"))' \ | |
| | xargs -I {} gh pr edit ${{ github.event.pull_request.number }} --remove-label {} | |
| SIZE="" | |
| if [ ${{ steps.lines_changed.outputs.total }} -lt 50 ]; then | |
| SIZE="xs" | |
| elif [ ${{ steps.lines_changed.outputs.total }} -lt 100 ]; then | |
| SIZE="s" | |
| elif [ ${{ steps.lines_changed.outputs.total }} -lt 500 ]; then | |
| SIZE="m" | |
| elif [ ${{ steps.lines_changed.outputs.total }} -lt 1000 ]; then | |
| SIZE="l" | |
| else | |
| SIZE="xl" | |
| fi | |
| # Create the label if it doesn't exist | |
| gh label create --repo ${{ github.repository }} "size/${SIZE}" || true | |
| # Add the label to the PR | |
| gh pr edit ${{ github.event.pull_request.number }} --add-label "size/${SIZE}" | |
| - name: Comment PR to warn about PR size | |
| uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3 | |
| with: | |
| comment-tag: very_large_pr | |
| mode: ${{ steps.lines_changed.outputs.total >= 1000 && 'upsert' || 'delete' }} | |
| message: | | |
| > [!IMPORTANT] | |
| > ## :warning: PR is very large :warning: | |
| > | |
| > This PR exceeds the recommended size of 1,000 lines. Please make sure you are NOT addressing multiple | |
| > issues with one PR. Note this PR might be rejected due to its size. | |
| - name: Automerge | |
| uses: ./.github/actions/trigger-automerge | |
| with: | |
| event: ${{ toJSON(github.event) }} | |
| hasAutoApproverPrivateKey: ${{ secrets.AUTO_APPROVER_PRIVATE_KEY != '' }} |