phanpy/.github/workflows/i18n-automerge.yml

63 lines
1.9 KiB
YAML
Raw Normal View History

2024-08-18 12:40:24 +03:00
name: i18n PR auto-merge
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
2024-08-18 12:49:28 +03:00
workflow_dispatch:
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
2024-08-18 19:05:24 +03:00
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
2024-08-18 12:40:24 +03:00
steps:
- name: Checkout code
uses: actions/checkout@v3
2024-08-18 14:55:23 +03:00
with:
fetch-depth: 0
2024-08-18 12:40:24 +03:00
- name: Count lines changed
run: |
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)
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
echo "ERROR: 50 or fewer lines have been changed. Failing the check."
2024-08-18 12:40:24 +03:00
exit 1
else
2024-08-18 19:05:09 +03:00
echo "Success: More than 50 lines have been changed."
2024-08-18 12:40:24 +03:00
fi
- name: Merge pull request
if: ${{ success() }}
run: |
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
gh pr merge $PR_NUMBER --auto --squash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}