Repository navigation
Windows: תיקון ניווט מלוח המספרים במנוע Flutter (#5934) #32690
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
| name: Automerge | ||
|
Check warning on line 1 in .github/workflows/automerge.yml
|
||
| # ממזג בשם Otzaria Bot, בקומיט מיזוג, PR עם תווית automerge כשכל הבדיקות עברו על ה-head שלו. | ||
| # ענף שמאחורי הבסיס עובר קודם ריבייס ודחיפה בכוח, ומיד אחריהם מתבצע המיזוג, בלי להמתין ל-CI על הקומיט המורבס. | ||
| # אין כאן הרצה של קוד מה-PR: רק git rebase ו-push. | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [dev] | ||
| paths: ['.github/workflows/automerge.yml'] | ||
| pull_request_target: | ||
| types: [labeled, ready_for_review] | ||
| workflow_run: | ||
| # המאזינים מוחרגים זה מזה: אחרת כל סיום של אחד מפעיל את האחרים, בשרשרת של כ-20 ריצות. | ||
| workflows: ['**', '!Automerge', '!Auto-Draft Failed CI', '!CI retry on dev and flaky log', '!Dev health'] | ||
| types: [completed] | ||
| permissions: {} | ||
| jobs: | ||
| find: | ||
| name: Find PRs to check | ||
| if: >- | ||
| (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/dev') || | ||
| github.event_name == 'push' || | ||
| (github.event_name == 'pull_request_target' && | ||
| contains(github.event.pull_request.labels.*.name, 'automerge')) || | ||
| (github.event_name == 'workflow_run' && | ||
| ((github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success') || | ||
| (github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'dev' && | ||
| github.event.workflow_run.name == 'Flutter Tests'))) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| pull-requests: read | ||
| outputs: | ||
| prs: ${{ steps.find.outputs.prs }} | ||
| steps: | ||
| - id: find | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR: ${{ github.event.pull_request.number }} | ||
| SHA: ${{ github.event.workflow_run.head_sha }} | ||
| RUN_EVENT: ${{ github.event.workflow_run.event }} | ||
| run: | | ||
| set -euo pipefail | ||
| R=$GITHUB_REPOSITORY | ||
| if [ -n "$PR" ]; then | ||
| prs="[$PR]" | ||
| elif [ "$RUN_EVENT" = push ] || [ "$GITHUB_EVENT_NAME" = push ] || [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then | ||
| prs=$(gh pr list -R "$R" --state open --label automerge --limit 1000 --json number,isDraft --jq 'map(select(.isDraft == false) | .number)') | ||
| else | ||
| prs=$(gh pr list -R "$R" --state open --label automerge --limit 1000 --json number,headRefOid,isDraft \ | ||
| --jq "map(select(.isDraft == false and .headRefOid == \"$SHA\") | .number)") | ||
| fi | ||
| echo "prs=$prs" | tee -a "$GITHUB_OUTPUT" | ||
| merge: | ||
| name: 'Automerge #${{ matrix.pr }}' | ||
| needs: find | ||
| if: needs.find.outputs.prs != '' && needs.find.outputs.prs != '[]' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| pr: ${{ fromJSON(needs.find.outputs.prs) }} | ||
| # מיזוג אחד בכל פעם: ה-PR הבא בודק את הבסיס מחדש אחרי המיזוג הקודם. | ||
| concurrency: | ||
| group: automerge-${{ github.repository }} | ||
| cancel-in-progress: false | ||
| queue: max | ||
| steps: | ||
| - id: token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.BOT_APP_ID }} | ||
| private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} | ||
| - env: | ||
| GH_TOKEN: ${{ steps.token.outputs.token }} | ||
| BOT_SLUG: ${{ steps.token.outputs.app-slug }} | ||
| PR: ${{ matrix.pr }} | ||
| EVENT: ${{ github.event_name }} | ||
| ACTION: ${{ github.event.action }} | ||
| ADDED_LABEL: ${{ github.event.label.name }} | ||
| SENDER: ${{ github.event.sender.login }} | ||
| run: | | ||
| set -euo pipefail | ||
| R=$GITHUB_REPOSITORY | ||
| comment() { | ||
| local f="$RUNNER_TEMP/comment.md" | ||
| printf '<div dir="rtl">\n\n### %s\n\n%s\n\n</div>\n' "$1" "$2" > "$f" | ||
| gh pr comment "$PR" -R "$R" --body-file "$f" | ||
| } | ||
| give_up() { | ||
| gh api -X DELETE "repos/$R/issues/$PR/labels/automerge" > /dev/null 2>&1 || true | ||
| comment "⚠️ המיזוג האוטומטי בוטל" "$1"$'\n\n'"אחרי הטיפול, הוסיפו שוב את התווית \`automerge\`." | ||
| exit 0 | ||
| } | ||
| pr=$(gh api "repos/$R/pulls/$PR") | ||
| [ "$(jq -r .state <<< "$pr")" = open ] || { echo "PR is $(jq -r .state <<< "$pr")"; exit 0; } | ||
| jq -e '.labels | map(.name) | index("automerge") != null' <<< "$pr" > /dev/null \ | ||
| || { echo "No automerge label"; exit 0; } | ||
| [ "$(jq -r .draft <<< "$pr")" = false ] || { echo "Draft"; exit 0; } | ||
| head=$(jq -r .head.sha <<< "$pr") | ||
| base=$(jq -r .base.ref <<< "$pr") | ||
| # כש-dev שבור ממוזג רק PR שמכיל את dev הנוכחי ועבר CI מלא, בלי ריבייס שלא נבדק. | ||
| # גם ריצה שנכשלה חייבת להשתייך להיסטוריה הנוכחית של dev. | ||
| dev_recovery=false | ||
| dev_head=$(gh api "repos/$R/git/ref/heads/dev" --jq .object.sha) | ||
| dev_runs=$(gh api "repos/$R/actions/workflows/flutter_tests.yml/runs?branch=dev&event=push&per_page=100" --jq '.workflow_runs') | ||
| dev_ci=$(jq -c 'first(.[] | select(.status == "completed")) // empty' <<< "$dev_runs") | ||
| [ -n "$dev_ci" ] || { echo "Waiting for a completed CI run on dev"; exit 0; } | ||
| case "$(jq -r .conclusion <<< "$dev_ci")" in | ||
| success) ;; | ||
| failure|timed_out|cancelled) | ||
| [ "$base" = dev ] || { echo "Waiting for green dev CI"; exit 0; } | ||
| dev_recovery=true ;; | ||
| *) echo "Waiting for a successful completed CI run on dev"; exit 0 ;; | ||
| esac | ||
| if jq -e '(map(.status == "completed") | index(true)) as $i | any(.[:$i][]; (.run_attempt // 1) > 1)' <<< "$dev_runs" > /dev/null; then | ||
| echo "Waiting for a newer dev CI retry to finish" | ||
| exit 0 | ||
| fi | ||
| ci_head=$(jq -r '.head_sha // empty' <<< "$dev_ci") | ||
| [ -n "$ci_head" ] || { echo "No verified dev CI commit"; exit 0; } | ||
| if [ "$ci_head" != "$dev_head" ]; then | ||
| relation=$(gh api "repos/$R/compare/$ci_head...$dev_head" --jq .status) | ||
| [ "$relation" = ahead ] || { echo "Last completed dev CI commit is not an ancestor of current dev"; exit 0; } | ||
| fi | ||
| if [ "$dev_recovery" = true ]; then | ||
| echo "Dev recovery: require full PR CI and the current dev commit in the tested head" | ||
| else | ||
| echo "Continuing with green dev baseline $ci_head; current dev $dev_head" | ||
| fi | ||
| base_head=$dev_head | ||
| if [ "$base" != dev ]; then | ||
| base_head=$(gh api "repos/$R/git/ref/heads/$base" --jq .object.sha) | ||
| fi | ||
| # תווית מכל מי שיש לו triage הייתה מאפשרת לו למזג; נבדק בכל ריצה, לא רק בהוספה. | ||
| if [ "$ACTION" = labeled ] && [ "$ADDED_LABEL" = automerge ]; then | ||
| labeler=$SENDER | ||
| else | ||
| labeler=$(gh api --paginate "repos/$R/issues/$PR/events" \ | ||
| --jq '.[] | select(.event == "labeled" and .label.name == "automerge") | .actor.login' | tail -n 1) | ||
| fi | ||
| perm=$(gh api "repos/$R/collaborators/$labeler/permission" --jq .permission 2> /dev/null || echo none) | ||
| case "$perm" in | ||
| admin|write) ;; | ||
| *) give_up "את התווית הוסיף \`$labeler\`, שאין לו הרשאת כתיבה בריפו." ;; | ||
| esac | ||
| # בוחרים ריצה עדכנית לכל workflow ואירוע, בלי לאחד jobs של workflows שונים. | ||
| # ריצות של automerge עצמו אינן CI: ריצה שנכשלה הייתה חוסמת את ה-PR לתמיד. | ||
| workflows=$(gh api --paginate "repos/$R/actions/runs?head_sha=$head&per_page=100" \ | ||
| --jq '.workflow_runs[] | select(.path != ".github/workflows/automerge.yml") | ||
| | {workflow_id, event, run_number, name, status, conclusion, check_suite_id}' \ | ||
| | jq -s 'group_by([.workflow_id, .event]) | map(max_by(.run_number))') | ||
| waiting=$(jq -r '.[] | select(.status != "completed" or (.conclusion | IN("success", "skipped", "neutral") | not)) | .name' <<< "$workflows") | ||
| [ -z "$waiting" ] || { echo "Workflows not passing:"; echo "$waiting"; exit 0; } | ||
| suites=$(jq 'map(.check_suite_id)' <<< "$workflows") | ||
| runs=$(gh api --paginate "repos/$R/commits/$head/check-runs?filter=latest&per_page=100" \ | ||
| --jq '.check_runs[] | {id, name, status, conclusion, suite: .check_suite.id, app: .app.slug}' \ | ||
| | jq -s --argjson suites "$suites" ' | ||
| map(select(.app != "github-actions" or (.suite as $id | $suites | index($id)) != null)) | ||
| | group_by([.suite, .name]) | map(max_by(.id))') | ||
| pending=$(jq -r 'map(select(.status != "completed")) | .[].name' <<< "$runs") | ||
| [ -z "$pending" ] || { echo "Still running:"; echo "$pending"; exit 0; } | ||
| # כשל מטופל ב-auto-draft-failed-ci.yml (הרצה חוזרת או טיוטה); כאן רק לא ממזגים. | ||
| bad=$(jq -r 'map(select(.conclusion | IN("success", "skipped", "neutral") | not)) | .[].name' <<< "$runs") | ||
| [ -z "$bad" ] || { echo "Not passing:"; echo "$bad"; exit 0; } | ||
| if ! jq -e 'any(.[]; .name == "CI result" and .conclusion == "success")' <<< "$runs" > /dev/null; then | ||
| echo "No successful CI result on $head" | ||
| if [ "$ADDED_LABEL" = automerge ] && \ | ||
| ! jq -e '.labels | map(.name) | index("run-ci") != null' <<< "$pr" > /dev/null; then | ||
| comment "⏳ המיזוג האוטומטי ממתין" "ה-CI המלא לא רץ על הקומיט \`${head:0:7}\`. הוסיפו את התווית \`run-ci\`, והמיזוג יתבצע כשהבדיקות יעברו." | ||
| fi | ||
| exit 0 | ||
| fi | ||
| statuses=$(gh api "repos/$R/commits/$head/status") | ||
| if [ "$(jq .total_count <<< "$statuses")" -gt 0 ] && [ "$(jq -r .state <<< "$statuses")" != success ]; then | ||
| echo "Commit statuses are $(jq -r .state <<< "$statuses")" | ||
| exit 0 | ||
| fi | ||
| behind=$(gh api "repos/$R/compare/$base_head...$head" --jq .behind_by) | ||
| if [ "$dev_recovery" = true ] && [ "$behind" != 0 ]; then | ||
| echo "Dev recovery requires an up-to-date PR with successful CI; no automatic rebase" | ||
| marker="<!-- automerge-recovery-behind:$head -->" | ||
| posted=$(gh api --paginate "repos/$R/issues/$PR/comments" --jq '.[].body') | ||
| if [[ "$posted" != *"$marker"* ]]; then | ||
| comment "⏳ המיזוג האוטומטי ממתין לעדכון הענף" "ה-CI של \`dev\` נכשל, ולכן ממוזג כעת רק ענף שמכיל את \`dev\` העדכני ועבר עליו CI מלא. עדכנו את הענף מול \`dev\` והוסיפו שוב את התווית \`automerge\`, או המתינו ש-\`dev\` יחזור לירוק, ואז הריבייס יתבצע אוטומטית."$'\n\n'"$marker" | ||
| fi | ||
| exit 0 | ||
| fi | ||
| if [ "$behind" -gt 0 ]; then | ||
| head_repo=$(jq -r .head.repo.full_name <<< "$pr") | ||
| head_ref=$(jq -r .head.ref <<< "$pr") | ||
| if [ "$head_repo" != "$R" ] && [ "$(jq -r .maintainer_can_modify <<< "$pr")" != true ]; then | ||
| give_up "הענף נמצא ב-fork שלא מאפשר עריכה למתחזקים (Allow edits by maintainers), ולכן אי אפשר לבצע עליו ריבייס. בצעו ריבייס על \`$base\` בעצמכם." | ||
| fi | ||
| echo "$behind commits behind $base; rebasing" | ||
| bot_id=$(gh api "users/${BOT_SLUG}%5Bbot%5D" --jq .id) | ||
| dir="$RUNNER_TEMP/repo" | ||
| git clone -q --no-tags --filter=blob:none --branch "$head_ref" \ | ||
| "https://x-access-token:$GH_TOKEN@github.com/$head_repo.git" "$dir" \ | ||
| || give_up "לא ניתן היה לשכפל את הענף \`$head_ref\` לצורך ריבייס." | ||
| cd "$dir" | ||
| [ "$(git rev-parse HEAD)" = "$head" ] || { echo "Branch moved; a new run will follow"; exit 0; } | ||
| git fetch -q --no-tags "https://x-access-token:$GH_TOKEN@github.com/$R.git" "$base" | ||
| git config user.name "${BOT_SLUG}[bot]" | ||
| git config user.email "${bot_id}+${BOT_SLUG}[bot]@users.noreply.github.com" | ||
| if ! git rebase -q FETCH_HEAD; then | ||
| git rebase --abort | ||
| give_up "יש קונפליקט מול \`$base\`, ולכן הריבייס האוטומטי נכשל." | ||
| fi | ||
| git push -q --force-with-lease="$head_ref:$head" origin "HEAD:$head_ref" \ | ||
| || give_up "הדחיפה אחרי הריבייס נכשלה." | ||
| head=$(git rev-parse HEAD) | ||
| echo "Rebased and pushed $head; merging without waiting for CI" | ||
| fi | ||
| if [ "$(gh api "repos/$R/git/ref/heads/$base" --jq .object.sha)" != "$base_head" ]; then | ||
| echo "Base moved during the checks; retrying on the next eligible event" | ||
| exit 0 | ||
| fi | ||
| # אחרי דחיפה GitHub עשוי לעדכן את ה-head של ה-PR באיחור קצר. | ||
| for attempt in 1 2 3; do | ||
| gh pr merge "$PR" -R "$R" --merge --match-head-commit "$head" && { echo "Merged #$PR"; exit 0; } | ||
| [ "$(gh api "repos/$R/pulls/$PR" --jq .merged)" = true ] && { echo "Already merged"; exit 0; } | ||
| [ "$attempt" = 3 ] || sleep 5 | ||
| done | ||
| give_up "המיזוג של הקומיט \`${head:0:7}\` נדחה ב-GitHub." | ||