1- name : Sync Upstream and Update Dev Branch
1+ name : Sync Upstream and Update Dev
22
33on :
44 schedule :
5- - cron : ' 0 0 * * *' # Runs daily at midnight UTC
6- workflow_dispatch : # Allows manual trigger
5+ - cron : ' 0 0 * * *' # Daily at midnight UTC
6+ workflow_dispatch : # Manual trigger
77 pull_request :
8- branches :
9- - dev
8+ branches : [dev]
109
1110jobs :
12- sync-and-merge :
11+ sync-and-update :
1312 runs-on : ubuntu-latest
1413 permissions :
1514 contents : write
@@ -19,76 +18,108 @@ jobs:
1918 - name : Checkout repository
2019 uses : actions/checkout@v4
2120 with :
22- fetch-depth : 0 # Full history for commit counting
21+ fetch-depth : 0
2322 token : ${{ secrets.PAT_SERVICE_ACCOUNT }}
23+ ref : master
2424
25- - name : Configure Git
25+ - name : Setup
2626 run : |
2727 git config --global user.name 'github-actions[bot]'
2828 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
29+ git remote add upstream https://github.com/ggml-org/llama.cpp.git || true
2930
30- - name : Add upstream remote and fetch latest release
31+ - name : Sync with latest release
32+ id : sync
3133 run : |
32- git remote add upstream https://github.com/ggml-org/llama.cpp.git || true
33- LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name')
34-
35- if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
34+ # Get latest release tag
35+ LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name')
36+ if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then
3637 echo "No valid release found. Exiting."
3738 exit 1
3839 fi
40+ echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
3941
40- echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV
41- git fetch upstream $LATEST_RELEASE_TAG
42-
43- - name : Update master branch with latest release
44- run : |
42+ # Update master branch
43+ git fetch upstream $LATEST_TAG --depth=1
4544 git checkout -B master FETCH_HEAD
4645 git push origin master --force
47- # Count total commits for tagging
46+
47+ # Count commits for tagging
4848 COMMIT_COUNT=$(git rev-list --count HEAD)
4949 echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV
5050
51- - name : Create PR to dev branch
52- id : create-pr
51+ - name : Create PR to dev
52+ id : create_pr
53+ env :
54+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
5355 run : |
56+ # Create branch for PR
5457 git checkout -b update-dev-from-master
5558 git push origin update-dev-from-master --force
56-
57- PR_TITLE="Sync master with upstream release $LATEST_RELEASE_TAG"
58- PR_BODY="This PR updates the dev branch with the latest release ($LATEST_RELEASE_TAG) from ggml-org/llama.cpp"
59-
60- PR_NUMBER=$(gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev --json number --jq '.number' || echo "")
59+
60+ # Create PR
61+ PR_TITLE="Sync master with upstream release $LATEST_TAG"
62+ PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp"
63+
64+ gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev
65+ PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number')
6166
6267 if [[ -z "$PR_NUMBER" ]]; then
63- echo "PR_CREATED=false" >> $GITHUB_ENV
64- echo "PR_NUMBER=0" >> $GITHUB_ENV
65- else
66- echo "PR created: #$PR_NUMBER"
67- echo "PR_CREATED=true" >> $GITHUB_ENV
68- echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
68+ echo "Failed to create PR"
69+ exit 0
6970 fi
71+
72+ echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
7073
71- - name : Check and merge PR if no conflicts
72- if : env.PR_CREATED == 'true'
74+ - name : Check PR status
75+ id : check_pr
76+ env :
77+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
7378 run : |
74- PR_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable')
79+ # Check if PR can be merged
80+ MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeStateStatus --jq '.mergeStateStatus')
81+ if [[ "$MERGE_STATUS" != "CLEAN" ]]; then
82+ echo "PR has conflicts and needs manual review"
83+ exit 0
84+ fi
7585
76- if [[ "$PR_STATUS" == "MERGEABLE" ]]; then
77- echo "PR is mergeable, proceeding with merge."
78- gh pr merge $PR_NUMBER --merge --admin
79-
80- # Create and push tag after successful merge
81- git fetch origin dev
82- git checkout dev
83- TAG_NAME="b$COMMIT_COUNT"
84-
85- if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
86- echo "Tag $TAG_NAME already exists, skipping."
86+ # Wait for CI checks without hardcoded attempts
87+ echo "Waiting for CI checks to complete..."
88+ while true; do
89+ ci_completed=$(gh pr checks $PR_NUMBER --json completedAt --jq '.[].completedAt')
90+ if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then
91+ echo "CI is still running, waiting..."
92+ sleep 60
8793 else
88- git tag "$TAG_NAME"
89- git push origin "$TAG_NAME"
94+ echo "CI has completed, checking states..."
95+ ci_states=$(gh pr checks $PR_NUMBER --json state --jq '.[].state')
96+ if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then
97+ echo "CI failed, exiting..."
98+ exit 1
99+ else
100+ echo "CI passed, proceeding with merge..."
101+ break
102+ fi
90103 fi
104+ done
105+
106+ - name : Merge PR and create tag
107+ env :
108+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
109+ run : |
110+ # Merge PR
111+ gh pr merge $PR_NUMBER --merge
112+
113+ # Create tag
114+ git fetch origin dev
115+ git checkout dev
116+ TAG_NAME="b$COMMIT_COUNT"
117+
118+ # Check if tag exists
119+ if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
120+ echo "Tag $TAG_NAME already exists"
91121 else
92- echo "PR is not mergeable due to conflicts. Manual resolution required."
93- exit 0 # Don't fail the workflow
122+ git tag "$TAG_NAME"
123+ git push origin "$TAG_NAME"
124+ echo "Tag $TAG_NAME created successfully"
94125 fi
0 commit comments