2024-08-18 12:40:24 +03:00
|
|
|
name: i18n PR auto-merge
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
types: [opened, synchronize, reopened, labeled]
|
2024-08-21 06:48:29 +03:00
|
|
|
branches:
|
2024-08-21 17:27:29 +03:00
|
|
|
- main
|
2024-08-18 12:40:24 +03:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
run-and-merge:
|
|
|
|
if: contains(github.event.pull_request.labels.*.name, 'i18n') &&
|
|
|
|
github.event.pull_request.base.ref == 'main' &&
|
|
|
|
github.event.pull_request.head.ref == 'l10n_main'
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2024-08-19 11:09:24 +03:00
|
|
|
- uses: actions/checkout@v4
|
2024-08-18 14:55:23 +03:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2024-08-26 04:03:03 +03:00
|
|
|
- run: sleep 15
|
|
|
|
|
|
|
|
- name: Check if the branch is dirty
|
|
|
|
run: |
|
|
|
|
git fetch origin ${{ github.event.pull_request.head.ref }}
|
|
|
|
if [ $(git rev-parse HEAD) != $(git rev-parse origin/${{ github.event.pull_request.head.ref }}) ]; then
|
|
|
|
echo "Branch is dirty. Exiting..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-08-20 06:01:12 +03:00
|
|
|
- name: Check auto-merge conditions
|
|
|
|
run: |
|
2024-08-18 13:24:33 +03:00
|
|
|
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
|
|
|
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
|
|
|
|
|
|
|
# Debug: Show the base and head SHA
|
|
|
|
echo "Base SHA: $BASE_SHA"
|
|
|
|
echo "Head SHA: $HEAD_SHA"
|
|
|
|
|
2024-08-18 14:55:23 +03:00
|
|
|
# Check if the commits exist
|
|
|
|
if ! git cat-file -e $BASE_SHA || ! git cat-file -e $HEAD_SHA; then
|
|
|
|
echo "ERROR: One or both of the commits are not available."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-18 12:40:24 +03:00
|
|
|
# Calculate the total number of lines changed (added, removed, or modified)
|
2024-08-18 13:24:33 +03:00
|
|
|
LINES_CHANGED=$(git diff --shortstat $BASE_SHA $HEAD_SHA | awk '{print $4 + $6 + $8}')
|
|
|
|
|
|
|
|
if [ -z "$LINES_CHANGED" ]; then
|
|
|
|
LINES_CHANGED=0
|
|
|
|
fi
|
|
|
|
|
2024-08-18 12:40:24 +03:00
|
|
|
echo "Total lines changed: $LINES_CHANGED"
|
|
|
|
|
2024-08-18 19:05:09 +03:00
|
|
|
# Check if the number of lines changed is more than 50
|
|
|
|
if [ "$LINES_CHANGED" -le 50 ]; then
|
2024-08-19 09:47:31 +03:00
|
|
|
exit 0
|
2024-08-18 12:40:24 +03:00
|
|
|
else
|
2024-08-19 17:39:18 +03:00
|
|
|
echo "More than 50 lines have been changed. Merging pull request."
|
2024-09-02 09:00:33 +03:00
|
|
|
|
|
|
|
# List of locales changed
|
|
|
|
LOCALES_CHANGED=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep '\.po$' | awk -F '/' '{print $NF}' | sed 's/\.po$//' | tr '\n' ',' | sed 's/,$//')
|
|
|
|
|
|
|
|
# Better subject
|
|
|
|
# "i18n updates ([LOCALES_CHANGED])"
|
2024-08-19 17:39:18 +03:00
|
|
|
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
|
2024-09-06 14:23:04 +03:00
|
|
|
SUBJECT="i18n updates ($LOCALES_CHANGED) (#$PR_NUMBER)"
|
|
|
|
|
2024-09-05 15:53:51 +03:00
|
|
|
gh pr merge $PR_NUMBER --squash --subject "$SUBJECT" || true
|
2024-08-18 12:40:24 +03:00
|
|
|
fi
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|