Skip to content

Commit ed6e4ab

Browse files
committed
ci: add workflow to auto-merge l10n PRs
Automatically approves and enables auto-merge for PRs that: - Have the 'l10n' label - Are authored by hay-kot or github-actions[bot] - Only modify files in frontend/lang/ or locales directories - Are under 200 lines changed
1 parent 15b5917 commit ed6e4ab

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Auto-merge l10n PRs
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, labeled]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-merge:
13+
runs-on: ubuntu-latest
14+
if: contains(github.event.pull_request.labels.*.name, 'l10n')
15+
16+
steps:
17+
- name: Validate PR author
18+
env:
19+
AUTHOR: ${{ github.event.pull_request.user.login }}
20+
run: |
21+
if [[ "$AUTHOR" != "hay-kot" && "$AUTHOR" != "github-actions[bot]" ]]; then
22+
echo "::error::PR author must be hay-kot or github-actions[bot] for auto-merge (got: $AUTHOR)"
23+
exit 1
24+
fi
25+
echo "Author validated: $AUTHOR"
26+
27+
- name: Validate PR size
28+
env:
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
PR_NUMBER: ${{ github.event.pull_request.number }}
31+
REPO: ${{ github.repository }}
32+
run: |
33+
ADDITIONS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json additions --jq '.additions')
34+
DELETIONS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json deletions --jq '.deletions')
35+
TOTAL=$((ADDITIONS + DELETIONS))
36+
37+
echo "PR changes: +$ADDITIONS -$DELETIONS (total: $TOTAL lines)"
38+
39+
if [ "$TOTAL" -gt 200 ]; then
40+
echo "::error::PR exceeds 200 line change limit ($TOTAL lines)"
41+
exit 1
42+
fi
43+
44+
- name: Validate file paths
45+
env:
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
PR_NUMBER: ${{ github.event.pull_request.number }}
48+
REPO: ${{ github.repository }}
49+
run: |
50+
FILES=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json files --jq '.files[].path')
51+
52+
for file in $FILES; do
53+
if [[ ! "$file" =~ ^frontend/lang/ ]] && [[ ! "$file" =~ ^mealie/repos/seed/resources/[^/]+/locales/ ]]; then
54+
echo "::error::Invalid file path: $file"
55+
echo "Only files in frontend/lang/ or mealie/repos/seed/resources/*/locales/ are allowed"
56+
exit 1
57+
fi
58+
done
59+
60+
echo "All files are in allowed paths"
61+
62+
- name: Approve PR
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
PR_NUMBER: ${{ github.event.pull_request.number }}
66+
REPO: ${{ github.repository }}
67+
run: |
68+
gh pr review "$PR_NUMBER" \
69+
--repo "$REPO" \
70+
--approve \
71+
--body "Auto-approved: l10n PR from trusted author with valid file paths"
72+
73+
- name: Enable auto-merge
74+
env:
75+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
PR_NUMBER: ${{ github.event.pull_request.number }}
77+
REPO: ${{ github.repository }}
78+
run: |
79+
gh pr merge "$PR_NUMBER" \
80+
--repo "$REPO" \
81+
--auto \
82+
--squash

0 commit comments

Comments
 (0)