1+ name : Sync Upstream and Update Dev
2+
3+ on :
4+ schedule :
5+ - cron : ' 0 0 * * *' # Daily at midnight UTC
6+ workflow_dispatch : # Manual trigger
7+ pull_request :
8+ branches : [dev]
9+
10+ jobs :
11+ sync-and-update :
12+ runs-on : ubuntu-latest
13+ permissions :
14+ contents : write
15+ pull-requests : write
16+
17+ steps :
18+ - name : Checkout repository
19+ uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0
22+ token : ${{ secrets.PAT_SERVICE_ACCOUNT }}
23+ ref : master
24+
25+ - name : Setup
26+ run : |
27+ git config --global user.name 'github-actions[bot]'
28+ 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
30+
31+ - name : Sync with latest release
32+ id : sync
33+ run : |
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
37+ echo "No valid release found. Exiting."
38+ exit 1
39+ fi
40+ echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
41+
42+ # Update master branch
43+ git fetch upstream $LATEST_TAG --depth=1
44+ git checkout -B master FETCH_HEAD
45+ git push origin master --force
46+
47+ # Count commits for tagging
48+ COMMIT_COUNT=$(git rev-list --count HEAD)
49+ echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV
50+
51+ - name : Create PR to dev
52+ id : create_pr
53+ env :
54+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
55+ run : |
56+ git fetch origin dev
57+ git diff --quiet master origin/dev || HAS_DIFF=$?
58+
59+ if [ -z "$HAS_DIFF" ]; then
60+ echo "No differences found between master and dev. Skipping PR creation."
61+ echo "SKIP_PR=true" >> $GITHUB_ENV
62+ exit 0
63+ else
64+ echo "Found differences between master and dev. Creating PR..."
65+ fi
66+
67+ BRANCH_NAME="update-dev-from-master-$(date +'%Y-%m-%d-%H-%M')"
68+ git checkout -b $BRANCH_NAME
69+ git push origin $BRANCH_NAME --force
70+
71+ PR_TITLE="Sync master with upstream release $LATEST_TAG"
72+ PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp"
73+
74+ gh pr create \
75+ --repo menloresearch/llama.cpp \
76+ --title "$PR_TITLE" \
77+ --body "$PR_BODY" \
78+ --head "$BRANCH_NAME" \
79+ --base dev || PR_FAILED=$?
80+
81+ echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
82+
83+ if [ ! -z "$PR_FAILED" ]; then
84+ echo "Failed to create PR. Error code: $PR_FAILED"
85+ echo "SKIP_PR=true" >> $GITHUB_ENV
86+ exit 0
87+ fi
88+
89+ PR_NUMBER=$(gh pr list --repo menloresearch/llama.cpp --head "$BRANCH_NAME" --json number --jq '.[0].number')
90+
91+ if [[ -z "$PR_NUMBER" ]]; then
92+ echo "Failed to get PR number"
93+ echo "SKIP_PR=true" >> $GITHUB_ENV
94+ exit 0
95+ fi
96+
97+ echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
98+
99+ - name : Wait for CI checks
100+ id : wait_for_ci
101+ if : ${{ env.SKIP_PR != 'true' }}
102+ env :
103+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
104+ run : |
105+ echo "Waiting for CI checks to complete..."
106+ while true; do
107+ ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt')
108+
109+ # If there are no CI checks, proceed with merge
110+ if [[ -z "$ci_completed" ]]; then
111+ echo "No CI checks detected. Proceeding with merge."
112+ break
113+ fi
114+
115+ # Check if any checks are still running
116+ if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then
117+ echo "CI is still running, waiting..."
118+ sleep 60
119+ else
120+ echo "CI has completed, checking states..."
121+ ci_states=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json state --jq '.[].state')
122+ if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then
123+ echo "CI failed, exiting..."
124+ echo "SKIP_MERGE=true" >> $GITHUB_ENV
125+ exit 0
126+ else
127+ echo "CI passed, proceeding with merge..."
128+ break
129+ fi
130+ fi
131+ done
132+
133+ - name : Merge PR and create tag
134+ if : ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }}
135+ env :
136+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
137+ run : |
138+ echo "Attempting to merge PR #$PR_NUMBER..."
139+ gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge || MERGE_FAILED=$?
140+
141+ if [ ! -z "$MERGE_FAILED" ]; then
142+ echo "Failed to merge PR. Error code: $MERGE_FAILED"
143+ echo "Manual intervention required."
144+ exit 0
145+ fi
146+
147+ echo "PR merged successfully!"
148+
149+ # Create tag
150+ git fetch origin dev
151+ git checkout dev
152+ TAG_NAME="b$COMMIT_COUNT"
153+
154+ # Check if tag exists
155+ if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
156+ echo "Tag $TAG_NAME already exists"
157+ else
158+ git tag "$TAG_NAME"
159+ git push origin "$TAG_NAME"
160+ echo "Tag $TAG_NAME created successfully"
161+ fi
0 commit comments