1- name : Sync with Latest Release
1+ name : Sync with Latest Release & Merge to Dev
22
33on :
44 schedule :
55 - cron : ' 0 0 * * *' # Runs daily at midnight UTC
66 workflow_dispatch : # Allow manual triggering
7- pull_request :
8- branches :
9- - dev
107
118jobs :
12- sync-with-release :
9+ sync-master :
1310 runs-on : ubuntu-latest
11+ permissions :
12+ contents : write
13+ pull-requests : write
14+
15+ outputs :
16+ pr_number : ${{ steps.create-pr.outputs.pr_number }}
17+ pr_created : ${{ steps.create-pr.outputs.pr_created }}
18+ commit_count : ${{ steps.commit-count.outputs.commit_count }}
19+
1420 steps :
15- - name : Checkout repo
21+ - name : Checkout repository
1622 uses : actions/checkout@v4
1723 with :
18- fetch-depth : 0 # Get full history for commit count
24+ fetch-depth : 0
1925 token : ${{ secrets.PAT_SERVICE_ACCOUNT }}
2026 ref : master
2127
@@ -24,78 +30,113 @@ jobs:
2430 git config --global user.name 'github-actions[bot]'
2531 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
2632
27- - name : Add upstream remote and fetch master
33+ - name : Add upstream remote and fetch latest release
2834 env :
2935 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
3036 run : |
3137 git remote add upstream https://github.com/ggml-org/llama.cpp.git
32- git fetch upstream master:refs/remotes/upstream/master --no-tags
33-
34- - name : Determine target commit
35- id : target
36- run : |
37- RELEASE_INFO=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest)
38- LATEST_TAG=$(echo "$RELEASE_INFO" | jq -r '.tag_name')
39- LATEST_COMMIT=$(echo "$RELEASE_INFO" | jq -r '.target_commitish')
38+ git fetch upstream --tags
39+
40+ LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name')
4041
41- if [ -n "$LATEST_TAG" ] && [ "$LATEST_TAG" != "null" ]; then
42- echo "Latest release tag: $LATEST_TAG (will use upstream/master)"
43- echo "target=upstream/master" >> $GITHUB_OUTPUT
44- else
45- echo "Using upstream/master as target"
46- echo "target=upstream/master" >> $GITHUB_OUTPUT
42+ if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
43+ echo "No valid release found. Exiting."
44+ exit 1
4745 fi
4846
49- - name : Sync master with latest release
47+ echo "Latest release tag: $LATEST_RELEASE_TAG"
48+ git fetch upstream $LATEST_RELEASE_TAG
49+ git checkout $LATEST_RELEASE_TAG
50+
51+ git reset --hard upstream/$LATEST_RELEASE_TAG
52+ git push origin HEAD:master --force
53+
54+ - name : Create PR to merge master into dev
55+ id : create-pr
5056 env :
5157 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
5258 run : |
53- CURRENT_COMMIT=$(git rev-parse HEAD)
54- TARGET="${{ steps.target.outputs.target }}"
55-
56- echo "Resetting master to $TARGET"
57- git reset --hard $TARGET
58-
59- NEW_COMMIT=$(git rev-parse HEAD)
59+ git checkout -b update-dev-from-master
60+ git push origin update-dev-from-master --force
61+
62+ PR_TITLE="Sync master (latest release) → dev"
63+ PR_BODY="This PR updates the dev branch with the latest release from ggml-org/llama.cpp"
64+
65+ gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev || echo "PR already exists."
66+
67+ PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number')
68+ echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV
69+ echo "::set-output name=pr_number::$PR_NUMBER"
70+ echo "::set-output name=pr_created::true"
71+
72+ - name : Count commits for tagging
73+ id : commit-count
74+ run : |
75+ COMMIT_COUNT=$(git rev-list --count HEAD)
76+ echo "::set-output name=commit_count::$COMMIT_COUNT"
77+
78+ merge-pr :
79+ needs : sync-master
80+ if : needs.sync-master.outputs.pr_created == 'true'
81+ runs-on : ubuntu-latest
82+ permissions :
83+ contents : write
84+ pull-requests : write
85+
86+ steps :
87+ - name : Checkout repository
88+ uses : actions/checkout@v4
89+ with :
90+ fetch-depth : 0
91+ token : ${{ secrets.PAT_SERVICE_ACCOUNT }}
92+ ref : dev
93+
94+ - name : Check PR mergeability
95+ env :
96+ GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
97+ run : |
98+ PR_NUMBER=${{ needs.sync-master.outputs.pr_number }}
99+ MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable')
60100
61- if [ "$CURRENT_COMMIT " = "$NEW_COMMIT" ]; then
62- echo "No new changes found, master is already up to date "
101+ if [[ "$MERGE_STATUS " == "MERGEABLE" ] ]; then
102+ echo "PR is mergeable, proceeding with merge. "
63103 else
64- echo "Pushing updates to master"
65- git push origin HEAD:master --force
66- echo "MASTER_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
104+ echo "PR is not mergeable due to conflicts. Manual resolution required."
105+ exit 1
67106 fi
68107
69- - name : Rebase dev onto master
108+ - name : Merge PR
70109 env :
71110 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
72111 run : |
73- git fetch origin dev:refs/remotes/origin/dev --no-tags
74- git checkout -b temp-dev origin/dev
75-
76- echo "Attempting to rebase dev onto master..."
77- if ! git rebase master; then
78- echo "⚠️ Rebase conflict detected, aborting"
79- git rebase --abort
80- exit 1
81- fi
82-
83- echo "Rebase successful, force pushing to dev..."
84- git push origin HEAD:dev --force
112+ PR_NUMBER=${{ needs.sync-master.outputs.pr_number }}
113+ gh pr merge $PR_NUMBER --merge --admin
85114
86- - name : Create version tag
115+ tag-dev :
116+ needs : merge-pr
117+ runs-on : ubuntu-latest
118+ steps :
119+ - name : Checkout repository
120+ uses : actions/checkout@v4
121+ with :
122+ fetch-depth : 0
123+ token : ${{ secrets.PAT_SERVICE_ACCOUNT }}
124+ ref : dev
125+
126+ - name : Configure Git
127+ run : |
128+ git config --global user.name 'github-actions[bot]'
129+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
130+
131+ - name : Create and push tag
87132 env :
88133 GITHUB_TOKEN : ${{ secrets.PAT_SERVICE_ACCOUNT }}
89134 run : |
90- git checkout master
91- COMMIT_COUNT=$(git rev-list --count HEAD)
92- NEW_TAG="b${COMMIT_COUNT}"
93-
94- if git ls-remote --tags origin | grep -q "refs/tags/${NEW_TAG}$"; then
95- echo "Tag $NEW_TAG already exists on remote, skipping tag creation"
135+ TAG_NAME="b${{ needs.sync-master.outputs.commit_count }}"
136+ if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
137+ echo "Tag $TAG_NAME already exists, skipping."
96138 else
97- echo "Creating new tag: $NEW_TAG"
98- git tag "$NEW_TAG"
99- git push origin "$NEW_TAG"
100- echo "Successfully created and pushed tag $NEW_TAG"
139+ echo "Creating and pushing tag $TAG_NAME"
140+ git tag "$TAG_NAME"
141+ git push origin "$TAG_NAME"
101142 fi
0 commit comments