From d03a0102bd900cabd1e5739ebaf0009f83e2e34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 22 Jul 2025 14:55:13 +0200 Subject: [PATCH 1/2] Add github actions --- .github/workflows/check-pr-size.yml | 48 +++++++++++++++++++++++++++++ .github/workflows/stale-prs.yml | 29 +++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .github/workflows/check-pr-size.yml create mode 100644 .github/workflows/stale-prs.yml diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml new file mode 100644 index 00000000..c6bb0fec --- /dev/null +++ b/.github/workflows/check-pr-size.yml @@ -0,0 +1,48 @@ +name: Check PR size + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + check_pr_size: + runs-on: ubuntu-latest + timeout-minutes: 1 + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Calculate changed lines + id: diff_check + run: | + # Get the target branch commit (base) and the PR branch commit (head) + BASE_SHA="${{ github.event.pull_request.base.sha }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" + echo "Base SHA: $BASE_SHA" + echo "Head SHA: $HEAD_SHA" + + # Compute the merge base between the two branches + MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA") + echo "Merge Base: $MERGE_BASE" + + # Calculate added and deleted lines between the merge base and the head commit + TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \ + | grep -Ev "(pnpm-lock.json|schema.d.ts)" \ + | awk '{ added += $1; deleted += $2 } END { print added + deleted }') + + # Default to 0 if nothing is output + TOTAL_CHANGED=${TOTAL_CHANGED:-0} + echo "Total changed lines: $TOTAL_CHANGED" + + # Make the total available for later steps + echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT" + + - name: Fail if too many changes + if: ${{ steps.diff_check.outputs.total > 500 }} + run: | + echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit." + echo "Please reduce the size of this PR." + exit 1 diff --git a/.github/workflows/stale-prs.yml b/.github/workflows/stale-prs.yml new file mode 100644 index 00000000..4c77c94c --- /dev/null +++ b/.github/workflows/stale-prs.yml @@ -0,0 +1,29 @@ +name: Mark stale PRs + +on: + schedule: + - cron: "0 7 * * *" + workflow_dispatch: + +permissions: + issues: write + pull-requests: write + +jobs: + stale_prs: + runs-on: ubuntu-latest + + steps: + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + days-before-stale: 30 + days-before-close: 15 + stale-pr-message: "This pull request has been inactive for 30 days. Is it still in progress? If so, please leave a comment or make an update to keep it open. Otherwise, it will be closed automatically in 15 days." + close-pr-message: "This pull request was closed automatically due to prolonged inactivity." + # Labels + stale-pr-label: stalled + exempt-draft-pr: true + # Do not touch issues + days-before-issue-stale: -1 + days-before-issue-close: -1 From d124fa7494bd28f045a954a55b75c31c8240f82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 22 Jul 2025 15:00:12 +0200 Subject: [PATCH 2/2] Update check-pr-size.yml --- .github/workflows/check-pr-size.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml index c6bb0fec..c9291779 100644 --- a/.github/workflows/check-pr-size.yml +++ b/.github/workflows/check-pr-size.yml @@ -30,7 +30,6 @@ jobs: # Calculate added and deleted lines between the merge base and the head commit TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \ - | grep -Ev "(pnpm-lock.json|schema.d.ts)" \ | awk '{ added += $1; deleted += $2 } END { print added + deleted }') # Default to 0 if nothing is output