5353 env :
5454 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
5555 run : |
56- # Fetch dev branch to compare
5756 git fetch origin dev
58-
59- # Check if there are differences between master and dev
60- # Exit code 0 means no differences, exit code 1 means there are differences
6157 git diff --quiet master origin/dev || HAS_DIFF=$?
6258
6359 if [ -z "$HAS_DIFF" ]; then
@@ -68,23 +64,19 @@ jobs:
6864 echo "Found differences between master and dev. Creating PR..."
6965 fi
7066
71- # Create branch for PR with timestamp
7267 BRANCH_NAME="update-dev-from-master-$(date +'%Y-%m-%d-%H-%M')"
7368 git checkout -b $BRANCH_NAME
7469 git push origin $BRANCH_NAME --force
7570
76- # Create PR using GitHub CLI with explicit repo
7771 PR_TITLE="Sync master with upstream release $LATEST_TAG"
7872 PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp"
7973
80- # Create PR with explicit repository specification
8174 gh pr create \
8275 --repo menloresearch/llama.cpp \
8376 --title "$PR_TITLE" \
8477 --body "$PR_BODY" \
8578 --head "$BRANCH_NAME" \
86- --base dev \
87- --reviewer vansangpfiev || PR_FAILED=$?
79+ --base dev \ || PR_FAILED=$?
8880
8981 echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
9082
9486 exit 0
9587 fi
9688
97- # Get PR number
9889 PR_NUMBER=$(gh pr list --repo menloresearch/llama.cpp --head "$BRANCH_NAME" --json number --jq '.[0].number')
9990
10091 if [[ -z "$PR_NUMBER" ]]; then
@@ -111,40 +102,90 @@ jobs:
111102 env :
112103 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
113104 run : |
114- # Check if PR can be merged
115105 MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus')
106+ echo "PR merge status: $MERGE_STATUS"
107+
116108 if [[ "$MERGE_STATUS" != "CLEAN" ]]; then
117- echo "PR has conflicts and needs manual review"
109+ echo "PR has conflicts and needs manual review. Stopping automatic merge."
110+ echo "SKIP_MERGE=true" >> $GITHUB_ENV
118111 exit 0
119112 fi
120113
121- # Wait for CI checks without hardcoded attempts
122- echo "Waiting for CI checks to complete..."
123- while true; do
124- ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt')
125- if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then
126- echo "CI is still running, waiting..."
127- sleep 60
128- else
129- echo "CI has completed, checking states..."
130- ci_states=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json state --jq '.[].state')
131- if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then
132- echo "CI failed, exiting..."
133- exit 1
114+ # Check if there are any CI checks
115+ CI_CHECKS_EXIST=false
116+ MAX_ATTEMPTS=5
117+
118+ for i in $(seq 1 $MAX_ATTEMPTS); do
119+ echo "Checking for CI checks (attempt $i of $MAX_ATTEMPTS)..."
120+ CI_CHECK_COUNT=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json name --jq 'length')
121+
122+ if [[ "$CI_CHECK_COUNT" -gt 0 ]]; then
123+ CI_CHECKS_EXIST=true
124+ echo "Found $CI_CHECK_COUNT CI checks"
125+ break
126+ fi
127+
128+ echo "No CI checks found yet, waiting 10 seconds..."
129+ sleep 10
130+ done
131+
132+ # Only wait for CI if checks exist
133+ if [[ "$CI_CHECKS_EXIST" == "true" ]]; then
134+ echo "Waiting for CI checks to complete..."
135+ MAX_WAIT_TIME=10 # Maximum wait time in minutes
136+ WAIT_INTERVAL=30 # Check interval in seconds
137+ ELAPSED_TIME=0
138+
139+ while (( ELAPSED_TIME < MAX_WAIT_TIME * 60 )); do
140+ # Get CI check details
141+ CI_STATUS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json status,conclusion --jq '.[].status')
142+
143+ # If any are still in progress, wait
144+ if echo "$CI_STATUS" | grep -q "IN_PROGRESS"; then
145+ echo "CI is still running, waiting... ($ELAPSED_TIME seconds elapsed of $(( MAX_WAIT_TIME * 60 )) max)"
146+ sleep $WAIT_INTERVAL
147+ ELAPSED_TIME=$((ELAPSED_TIME + WAIT_INTERVAL))
134148 else
135- echo "CI passed, proceeding with merge..."
149+ # All checks are complete
150+ echo "All CI checks completed!"
151+
152+ # Check for failures
153+ CI_CONCLUSIONS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json conclusion --jq '.[].conclusion')
154+ if echo "$CI_CONCLUSIONS" | grep -qE "FAILURE|CANCELLED|TIMED_OUT"; then
155+ echo "Some CI checks failed. Human review required."
156+ echo "SKIP_MERGE=true" >> $GITHUB_ENV
157+ exit 0
158+ fi
159+
136160 break
137161 fi
138- fi
139- done
162+
163+ # Check if we've exceeded the maximum wait time
164+ if (( ELAPSED_TIME >= MAX_WAIT_TIME * 60 )); then
165+ echo "Maximum wait time of $MAX_WAIT_TIME minutes exceeded. Marking for human review."
166+ echo "SKIP_MERGE=true" >> $GITHUB_ENV
167+ exit 0
168+ fi
169+ done
170+ else
171+ echo "No CI checks found after $MAX_ATTEMPTS attempts. Proceeding with merge."
172+ fi
140173
141174 - name : Merge PR and create tag
142- if : ${{ env.SKIP_PR != 'true' }}
175+ if : ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }}
143176 env :
144177 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
145178 run : |
146- # Merge PR
147- gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge
179+ echo "Attempting to merge PR #$PR_NUMBER..."
180+ gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge || MERGE_FAILED=$?
181+
182+ if [ ! -z "$MERGE_FAILED" ]; then
183+ echo "Failed to merge PR. Error code: $MERGE_FAILED"
184+ echo "Manual intervention required."
185+ exit 0
186+ fi
187+
188+ echo "PR merged successfully!"
148189
149190 # Create tag
150191 git fetch origin dev
0 commit comments