From 37f58365a4c5bdd53448fead9524a549fa2f6489 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 12:04:06 +0700 Subject: [PATCH 01/29] ci: add upstream sync --- .github/workflows/upstream-sync.yml | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/upstream-sync.yml diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml new file mode 100644 index 0000000000000..98bc4c055e6ad --- /dev/null +++ b/.github/workflows/upstream-sync.yml @@ -0,0 +1,67 @@ +name: Sync with Latest Release + +on: + schedule: + - cron: '0 0 * * *' # Runs daily at midnight UTC + workflow_dispatch: # Allow manual triggering + +jobs: + sync-with-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Get full history for commit count + token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Add upstream remote + run: | + git remote add upstream https://github.com/ggml-org/llama.cpp.git + git fetch upstream --tags # Fetch tags from upstream + + - name: Sync master with latest release + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + git checkout master + LATEST_RELEASE=$(git describe --tags --abbrev=0 upstream/master) + git reset --hard $LATEST_RELEASE + git push origin master --force + + - name: Rebase dev onto master + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + git checkout dev + echo "Attempting to rebase dev onto master..." + if ! git rebase master; then + echo "⚠️ Rebase conflict detected, aborting" + git rebase --abort + exit 1 + fi + echo "Rebase successful, force pushing to dev..." + git push origin dev --force-with-lease + + - name: Create version tag + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + git checkout master + COMMIT_COUNT=$(git rev-list --count HEAD) + NEW_TAG="b${COMMIT_COUNT}" + echo "Creating new tag: $NEW_TAG" + + # Check if tag already exists + if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then + echo "Tag $NEW_TAG already exists, skipping tag creation" + else + git checkout dev + git tag "$NEW_TAG" + git push origin tag "$NEW_TAG" + fi \ No newline at end of file From 422520ced36f9dffc5626a83ef323e90b9da7196 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 12:36:32 +0700 Subject: [PATCH 02/29] chore: test ci --- .github/workflows/upstream-sync.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 98bc4c055e6ad..55b7d32ed7632 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -4,6 +4,10 @@ on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering + pull_request: + types: [opened] + branches: + - dev jobs: sync-with-release: From 3cf924e8cdc489c211baf93316a9b25a13bf9e61 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 12:39:10 +0700 Subject: [PATCH 03/29] chore: update ci --- .github/workflows/upstream-sync.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 55b7d32ed7632..7cde6ceddd28c 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -5,7 +5,6 @@ on: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering pull_request: - types: [opened] branches: - dev From c855cfc43170915530410b6bf830281342a15d37 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 12:41:21 +0700 Subject: [PATCH 04/29] ci: add pat env for add upstream remote step --- .github/workflows/upstream-sync.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 7cde6ceddd28c..7b8a284853708 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -24,13 +24,15 @@ jobs: git config --global user.email 'github-actions[bot]@users.noreply.github.com' - name: Add upstream remote + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git git fetch upstream --tags # Fetch tags from upstream - name: Sync master with latest release env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout master LATEST_RELEASE=$(git describe --tags --abbrev=0 upstream/master) @@ -39,7 +41,7 @@ jobs: - name: Rebase dev onto master env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout dev echo "Attempting to rebase dev onto master..." @@ -53,7 +55,7 @@ jobs: - name: Create version tag env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout master COMMIT_COUNT=$(git rev-list --count HEAD) From 26fe7ea78e2a93efec2a0c9916cc785df84fdd73 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:06:30 +0700 Subject: [PATCH 05/29] ci: fetch master remote only --- .github/workflows/upstream-sync.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 7b8a284853708..23009bf337ade 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -28,14 +28,26 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream --tags # Fetch tags from upstream + git fetch upstream master:refs/remotes/upstream/master + # Fetch the latest release tag + LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + if [ -n "$LATEST_TAG" ]; then + git fetch upstream refs/tags/$LATEST_TAG:refs/tags/$LATEST_TAG + fi + - name: Sync master with latest release env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout master - LATEST_RELEASE=$(git describe --tags --abbrev=0 upstream/master) + LATEST_RELEASE=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + + if [ -z "$LATEST_RELEASE" ]; then + echo "Could not get latest release tag, using upstream master" + LATEST_RELEASE="upstream/master" + fi + git reset --hard $LATEST_RELEASE git push origin master --force From f61ccdaefc64d709ef687099172c82c9eb31e81a Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:20:34 +0700 Subject: [PATCH 06/29] chore: update ci --- .github/workflows/upstream-sync.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 23009bf337ade..fb6c9f2fcba5a 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -17,6 +17,7 @@ jobs: with: fetch-depth: 0 # Get full history for commit count token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: master - name: Configure Git run: | @@ -40,7 +41,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout master LATEST_RELEASE=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') if [ -z "$LATEST_RELEASE" ]; then @@ -49,21 +49,22 @@ jobs: fi git reset --hard $LATEST_RELEASE - git push origin master --force + git push origin HEAD:master --force - name: Rebase dev onto master env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout dev + git checkout -b temp-dev origin/dev echo "Attempting to rebase dev onto master..." - if ! git rebase master; then + # Use the HEAD reference since we're currently on master branch + if ! git rebase HEAD; then echo "⚠️ Rebase conflict detected, aborting" git rebase --abort exit 1 fi echo "Rebase successful, force pushing to dev..." - git push origin dev --force-with-lease + git push origin HEAD:dev --force-with-lease - name: Create version tag env: @@ -78,7 +79,7 @@ jobs: if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then echo "Tag $NEW_TAG already exists, skipping tag creation" else - git checkout dev + git checkout -b temp-dev origin/dev git tag "$NEW_TAG" git push origin tag "$NEW_TAG" fi \ No newline at end of file From 92fb00f8008fa7c0809ed6233350e1aaa7806321 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:37:59 +0700 Subject: [PATCH 07/29] ci: rebase dev onto master branch --- .github/workflows/upstream-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index fb6c9f2fcba5a..b68d8efd3cff6 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -58,7 +58,7 @@ jobs: git checkout -b temp-dev origin/dev echo "Attempting to rebase dev onto master..." # Use the HEAD reference since we're currently on master branch - if ! git rebase HEAD; then + if ! git rebase $MASTER_COMMIT; then echo "⚠️ Rebase conflict detected, aborting" git rebase --abort exit 1 From 034209ed07c1ed8d205c7f939c41ecb3311e6101 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:49:00 +0700 Subject: [PATCH 08/29] chore: test ci --- .github/workflows/upstream-sync.yml | 46 ++++----------- .github/workflows/upstream-sync2.yml | 85 ++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/upstream-sync2.yml diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index b68d8efd3cff6..e4484a48a1f08 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -17,54 +17,38 @@ jobs: with: fetch-depth: 0 # Get full history for commit count token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - ref: master - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream master:refs/remotes/upstream/master + git fetch upstream --tags # Fetch tags from upstream - # Fetch the latest release tag - LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') - if [ -n "$LATEST_TAG" ]; then - git fetch upstream refs/tags/$LATEST_TAG:refs/tags/$LATEST_TAG - fi - - name: Sync master with latest release env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - LATEST_RELEASE=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') - - if [ -z "$LATEST_RELEASE" ]; then - echo "Could not get latest release tag, using upstream master" - LATEST_RELEASE="upstream/master" - fi - + git checkout master + LATEST_RELEASE=$(git describe --tags --abbrev=0 upstream/master) git reset --hard $LATEST_RELEASE - git push origin HEAD:master --force + git push origin master --force - name: Rebase dev onto master env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout -b temp-dev origin/dev - echo "Attempting to rebase dev onto master..." - # Use the HEAD reference since we're currently on master branch - if ! git rebase $MASTER_COMMIT; then - echo "⚠️ Rebase conflict detected, aborting" + git checkout dev + if ! git rebase master; then + echo "Rebase conflict detected, aborting" git rebase --abort exit 1 fi - echo "Rebase successful, force pushing to dev..." - git push origin HEAD:dev --force-with-lease + git push origin dev --force-with-lease - name: Create version tag env: @@ -72,14 +56,6 @@ jobs: run: | git checkout master COMMIT_COUNT=$(git rev-list --count HEAD) - NEW_TAG="b${COMMIT_COUNT}" - echo "Creating new tag: $NEW_TAG" - - # Check if tag already exists - if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then - echo "Tag $NEW_TAG already exists, skipping tag creation" - else - git checkout -b temp-dev origin/dev - git tag "$NEW_TAG" - git push origin tag "$NEW_TAG" - fi \ No newline at end of file + git checkout dev + git tag "b${COMMIT_COUNT}" + git push origin tag "b${COMMIT_COUNT}" \ No newline at end of file diff --git a/.github/workflows/upstream-sync2.yml b/.github/workflows/upstream-sync2.yml new file mode 100644 index 0000000000000..1c619e183d879 --- /dev/null +++ b/.github/workflows/upstream-sync2.yml @@ -0,0 +1,85 @@ +# name: Sync with Latest Release + +# on: +# schedule: +# - cron: '0 0 * * *' # Runs daily at midnight UTC +# workflow_dispatch: # Allow manual triggering +# pull_request: +# branches: +# - dev + +# jobs: +# sync-with-release: +# runs-on: ubuntu-latest +# steps: +# - name: Checkout repo +# uses: actions/checkout@v4 +# with: +# fetch-depth: 0 # Get full history for commit count +# token: ${{ secrets.PAT_SERVICE_ACCOUNT }} +# ref: master + +# - name: Configure Git +# run: | +# git config --global user.name 'github-actions[bot]' +# git config --global user.email 'github-actions[bot]@users.noreply.github.com' + +# - name: Add upstream remote +# env: +# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} +# run: | +# git remote add upstream https://github.com/ggml-org/llama.cpp.git +# git fetch upstream master:refs/remotes/upstream/master + +# # Fetch the latest release tag +# LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') +# if [ -n "$LATEST_TAG" ]; then +# git fetch upstream refs/tags/$LATEST_TAG:refs/tags/$LATEST_TAG +# fi + +# - name: Sync master with latest release +# env: +# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} +# run: | +# LATEST_RELEASE=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + +# if [ -z "$LATEST_RELEASE" ]; then +# echo "Could not get latest release tag, using upstream master" +# LATEST_RELEASE="upstream/master" +# fi + +# git reset --hard $LATEST_RELEASE +# git push origin HEAD:master --force + +# - name: Rebase dev onto master +# env: +# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} +# run: | +# git checkout -b temp-dev origin/dev +# echo "Attempting to rebase dev onto master..." +# # Use the HEAD reference since we're currently on master branch +# if ! git rebase $MASTER_COMMIT; then +# echo "⚠️ Rebase conflict detected, aborting" +# git rebase --abort +# exit 1 +# fi +# echo "Rebase successful, force pushing to dev..." +# git push origin HEAD:dev --force-with-lease + +# - name: Create version tag +# env: +# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} +# run: | +# git checkout master +# COMMIT_COUNT=$(git rev-list --count HEAD) +# NEW_TAG="b${COMMIT_COUNT}" +# echo "Creating new tag: $NEW_TAG" + +# # Check if tag already exists +# if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then +# echo "Tag $NEW_TAG already exists, skipping tag creation" +# else +# git checkout -b temp-dev origin/dev +# git tag "$NEW_TAG" +# git push origin tag "$NEW_TAG" +# fi \ No newline at end of file From c1e8102974a17bec29c9cfb8e73ca4e9232e81a8 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:52:24 +0700 Subject: [PATCH 09/29] chore: update ci --- .github/workflows/upstream-sync.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index e4484a48a1f08..78a4511a00ce5 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -34,8 +34,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout master - LATEST_RELEASE=$(git describe --tags --abbrev=0 upstream/master) - git reset --hard $LATEST_RELEASE + git fetch upstream master + git reset --hard upstream/master git push origin master --force - name: Rebase dev onto master @@ -46,6 +46,8 @@ jobs: if ! git rebase master; then echo "Rebase conflict detected, aborting" git rebase --abort + git status + git diff exit 1 fi git push origin dev --force-with-lease From ba7c6f2c3f31fb8f4f264fe2add99c1418b37492 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 13:58:42 +0700 Subject: [PATCH 10/29] chore: update ci --- .github/workflows/upstream-sync.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 78a4511a00ce5..b3f20788040ff 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -22,19 +22,13 @@ jobs: run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote + - name: Add upstream remote and sync master with latest release env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream --tags # Fetch tags from upstream - - - name: Sync master with latest release - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} - run: | + git fetch upstream master --tags # Fetch tags from upstream git checkout master - git fetch upstream master git reset --hard upstream/master git push origin master --force @@ -46,8 +40,6 @@ jobs: if ! git rebase master; then echo "Rebase conflict detected, aborting" git rebase --abort - git status - git diff exit 1 fi git push origin dev --force-with-lease From 8d6bf74a4a1d9df3b5f60f1fa227aa1186ea6763 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 14:34:55 +0700 Subject: [PATCH 11/29] ci: add ref --- .github/workflows/upstream-sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index b3f20788040ff..226078b44fed7 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -17,6 +17,7 @@ jobs: with: fetch-depth: 0 # Get full history for commit count token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: master - name: Configure Git run: | From 7dbd130caa663b458388b56a2c255825088d2b2c Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 14:36:47 +0700 Subject: [PATCH 12/29] ci: add debug step --- .github/workflows/upstream-sync.yml | 67 +++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 226078b44fed7..3d2610822acb8 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -17,33 +17,74 @@ jobs: with: fetch-depth: 0 # Get full history for commit count token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - ref: master - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote and sync master with latest release + + - name: Add upstream remote env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream master --tags # Fetch tags from upstream - git checkout master + git fetch upstream master + echo "Upstream fetch completed successfully" + + - name: Fetch tags + run: | + git fetch upstream --tags + echo "Tags fetch completed successfully" + + - name: Debug branch info + run: | + echo "Local branches:" + git branch -a + echo "Remote branches:" + git ls-remote --heads origin + + - name: Sync master with latest release + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + git checkout -B master + echo "Checked out master branch" git reset --hard upstream/master + echo "Reset master to upstream/master" git push origin master --force + echo "Pushed master to origin" + - name: Debug before dev checkout + run: | + echo "Current branch:" + git branch --show-current + - name: Rebase dev onto master env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout dev + # First check if dev branch exists locally + if git show-ref --verify --quiet refs/heads/dev; then + echo "Local dev branch exists, checking out" + git checkout dev + elif git show-ref --verify --quiet refs/remotes/origin/dev; then + echo "Remote dev branch exists, creating local tracking branch" + git checkout -b dev origin/dev + else + echo "No dev branch exists, creating from master" + git checkout -b dev + fi + + echo "On branch $(git branch --show-current)" + if ! git rebase master; then echo "Rebase conflict detected, aborting" git rebase --abort exit 1 fi - git push origin dev --force-with-lease + + echo "Rebase successful, pushing to origin" + git push origin dev --force-with-lease || git push origin dev --force - name: Create version tag env: @@ -51,6 +92,16 @@ jobs: run: | git checkout master COMMIT_COUNT=$(git rev-list --count HEAD) + echo "Commit count: $COMMIT_COUNT" git checkout dev - git tag "b${COMMIT_COUNT}" - git push origin tag "b${COMMIT_COUNT}" \ No newline at end of file + + # Check if tag already exists + if git rev-parse "b${COMMIT_COUNT}" >/dev/null 2>&1; then + echo "Tag b${COMMIT_COUNT} already exists, force updating" + git tag -f "b${COMMIT_COUNT}" + else + echo "Creating new tag b${COMMIT_COUNT}" + git tag "b${COMMIT_COUNT}" + fi + + git push origin "b${COMMIT_COUNT}" --force \ No newline at end of file From 7fce78f2f6320cc8d1f080167355db57952189d8 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 15:16:50 +0700 Subject: [PATCH 13/29] ci: update upstream sync --- .github/workflows/upstream-sync.yml | 94 +++++++++++++--------------- .github/workflows/upstream-sync2.yml | 85 ------------------------- 2 files changed, 44 insertions(+), 135 deletions(-) delete mode 100644 .github/workflows/upstream-sync2.yml diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 3d2610822acb8..36fe73923d57a 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -17,74 +17,71 @@ jobs: with: fetch-depth: 0 # Get full history for commit count token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: master - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Add upstream remote + + - name: Add upstream remote and fetch master env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream master - echo "Upstream fetch completed successfully" + git fetch upstream master:refs/remotes/upstream/master --no-tags - - name: Fetch tags + - name: Determine target commit + id: target run: | - git fetch upstream --tags - echo "Tags fetch completed successfully" + RELEASE_INFO=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest) + LATEST_TAG=$(echo "$RELEASE_INFO" | jq -r '.tag_name') + LATEST_COMMIT=$(echo "$RELEASE_INFO" | jq -r '.target_commitish') - - name: Debug branch info - run: | - echo "Local branches:" - git branch -a - echo "Remote branches:" - git ls-remote --heads origin + if [ -n "$LATEST_TAG" ] && [ "$LATEST_TAG" != "null" ]; then + echo "Latest release tag: $LATEST_TAG (will use upstream/master)" + echo "target=upstream/master" >> $GITHUB_OUTPUT + else + echo "Using upstream/master as target" + echo "target=upstream/master" >> $GITHUB_OUTPUT + fi - name: Sync master with latest release env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout -B master - echo "Checked out master branch" - git reset --hard upstream/master - echo "Reset master to upstream/master" - git push origin master --force - echo "Pushed master to origin" - - - name: Debug before dev checkout - run: | - echo "Current branch:" - git branch --show-current + CURRENT_COMMIT=$(git rev-parse HEAD) + TARGET="${{ steps.target.outputs.target }}" + + echo "Resetting master to $TARGET" + git reset --hard $TARGET + NEW_COMMIT=$(git rev-parse HEAD) + + if [ "$CURRENT_COMMIT" = "$NEW_COMMIT" ]; then + echo "No new changes found, master is already up to date" + else + echo "Pushing updates to master" + git push origin HEAD:master --force + echo "MASTER_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV + fi + - name: Rebase dev onto master env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # First check if dev branch exists locally - if git show-ref --verify --quiet refs/heads/dev; then - echo "Local dev branch exists, checking out" - git checkout dev - elif git show-ref --verify --quiet refs/remotes/origin/dev; then - echo "Remote dev branch exists, creating local tracking branch" - git checkout -b dev origin/dev - else - echo "No dev branch exists, creating from master" - git checkout -b dev - fi - - echo "On branch $(git branch --show-current)" + git fetch origin dev:refs/remotes/origin/dev --no-tags + git checkout -b temp-dev origin/dev + echo "Attempting to rebase dev onto master..." if ! git rebase master; then - echo "Rebase conflict detected, aborting" + echo "⚠️ Rebase conflict detected, aborting" git rebase --abort exit 1 fi - echo "Rebase successful, pushing to origin" - git push origin dev --force-with-lease || git push origin dev --force + echo "Rebase successful, force pushing to dev..." + git push origin HEAD:dev --force - name: Create version tag env: @@ -92,16 +89,13 @@ jobs: run: | git checkout master COMMIT_COUNT=$(git rev-list --count HEAD) - echo "Commit count: $COMMIT_COUNT" - git checkout dev + NEW_TAG="b${COMMIT_COUNT}" - # Check if tag already exists - if git rev-parse "b${COMMIT_COUNT}" >/dev/null 2>&1; then - echo "Tag b${COMMIT_COUNT} already exists, force updating" - git tag -f "b${COMMIT_COUNT}" + if git ls-remote --tags origin | grep -q "refs/tags/${NEW_TAG}$"; then + echo "Tag $NEW_TAG already exists on remote, skipping tag creation" else - echo "Creating new tag b${COMMIT_COUNT}" - git tag "b${COMMIT_COUNT}" + echo "Creating new tag: $NEW_TAG" + git tag "$NEW_TAG" + git push origin "$NEW_TAG" + echo "Successfully created and pushed tag $NEW_TAG" fi - - git push origin "b${COMMIT_COUNT}" --force \ No newline at end of file diff --git a/.github/workflows/upstream-sync2.yml b/.github/workflows/upstream-sync2.yml deleted file mode 100644 index 1c619e183d879..0000000000000 --- a/.github/workflows/upstream-sync2.yml +++ /dev/null @@ -1,85 +0,0 @@ -# name: Sync with Latest Release - -# on: -# schedule: -# - cron: '0 0 * * *' # Runs daily at midnight UTC -# workflow_dispatch: # Allow manual triggering -# pull_request: -# branches: -# - dev - -# jobs: -# sync-with-release: -# runs-on: ubuntu-latest -# steps: -# - name: Checkout repo -# uses: actions/checkout@v4 -# with: -# fetch-depth: 0 # Get full history for commit count -# token: ${{ secrets.PAT_SERVICE_ACCOUNT }} -# ref: master - -# - name: Configure Git -# run: | -# git config --global user.name 'github-actions[bot]' -# git config --global user.email 'github-actions[bot]@users.noreply.github.com' - -# - name: Add upstream remote -# env: -# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} -# run: | -# git remote add upstream https://github.com/ggml-org/llama.cpp.git -# git fetch upstream master:refs/remotes/upstream/master - -# # Fetch the latest release tag -# LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') -# if [ -n "$LATEST_TAG" ]; then -# git fetch upstream refs/tags/$LATEST_TAG:refs/tags/$LATEST_TAG -# fi - -# - name: Sync master with latest release -# env: -# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} -# run: | -# LATEST_RELEASE=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') - -# if [ -z "$LATEST_RELEASE" ]; then -# echo "Could not get latest release tag, using upstream master" -# LATEST_RELEASE="upstream/master" -# fi - -# git reset --hard $LATEST_RELEASE -# git push origin HEAD:master --force - -# - name: Rebase dev onto master -# env: -# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} -# run: | -# git checkout -b temp-dev origin/dev -# echo "Attempting to rebase dev onto master..." -# # Use the HEAD reference since we're currently on master branch -# if ! git rebase $MASTER_COMMIT; then -# echo "⚠️ Rebase conflict detected, aborting" -# git rebase --abort -# exit 1 -# fi -# echo "Rebase successful, force pushing to dev..." -# git push origin HEAD:dev --force-with-lease - -# - name: Create version tag -# env: -# GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} -# run: | -# git checkout master -# COMMIT_COUNT=$(git rev-list --count HEAD) -# NEW_TAG="b${COMMIT_COUNT}" -# echo "Creating new tag: $NEW_TAG" - -# # Check if tag already exists -# if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then -# echo "Tag $NEW_TAG already exists, skipping tag creation" -# else -# git checkout -b temp-dev origin/dev -# git tag "$NEW_TAG" -# git push origin tag "$NEW_TAG" -# fi \ No newline at end of file From 101f426feaed8ef70846ba8637b9d96570d63d3f Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 15:37:23 +0700 Subject: [PATCH 14/29] ci: update workflow upstream --- .github/workflows/upstream-sync.yml | 159 +++++++++++++++++----------- 1 file changed, 100 insertions(+), 59 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 36fe73923d57a..5943a686bcac0 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -1,21 +1,27 @@ -name: Sync with Latest Release +name: Sync with Latest Release & Merge to Dev on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering - pull_request: - branches: - - dev jobs: - sync-with-release: + sync-master: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + outputs: + pr_number: ${{ steps.create-pr.outputs.pr_number }} + pr_created: ${{ steps.create-pr.outputs.pr_created }} + commit_count: ${{ steps.commit-count.outputs.commit_count }} + steps: - - name: Checkout repo + - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Get full history for commit count + fetch-depth: 0 token: ${{ secrets.PAT_SERVICE_ACCOUNT }} ref: master @@ -24,78 +30,113 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote and fetch master + - name: Add upstream remote and fetch latest release env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream master:refs/remotes/upstream/master --no-tags - - - name: Determine target commit - id: target - run: | - RELEASE_INFO=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest) - LATEST_TAG=$(echo "$RELEASE_INFO" | jq -r '.tag_name') - LATEST_COMMIT=$(echo "$RELEASE_INFO" | jq -r '.target_commitish') + git fetch upstream --tags + + LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') - if [ -n "$LATEST_TAG" ] && [ "$LATEST_TAG" != "null" ]; then - echo "Latest release tag: $LATEST_TAG (will use upstream/master)" - echo "target=upstream/master" >> $GITHUB_OUTPUT - else - echo "Using upstream/master as target" - echo "target=upstream/master" >> $GITHUB_OUTPUT + if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then + echo "No valid release found. Exiting." + exit 1 fi - - name: Sync master with latest release + echo "Latest release tag: $LATEST_RELEASE_TAG" + git fetch upstream $LATEST_RELEASE_TAG + git checkout $LATEST_RELEASE_TAG + + git reset --hard upstream/$LATEST_RELEASE_TAG + git push origin HEAD:master --force + + - name: Create PR to merge master into dev + id: create-pr env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - CURRENT_COMMIT=$(git rev-parse HEAD) - TARGET="${{ steps.target.outputs.target }}" - - echo "Resetting master to $TARGET" - git reset --hard $TARGET - - NEW_COMMIT=$(git rev-parse HEAD) + git checkout -b update-dev-from-master + git push origin update-dev-from-master --force + + PR_TITLE="Sync master (latest release) → dev" + PR_BODY="This PR updates the dev branch with the latest release from ggml-org/llama.cpp" + + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev || echo "PR already exists." + + PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number') + echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV + echo "::set-output name=pr_number::$PR_NUMBER" + echo "::set-output name=pr_created::true" + + - name: Count commits for tagging + id: commit-count + run: | + COMMIT_COUNT=$(git rev-list --count HEAD) + echo "::set-output name=commit_count::$COMMIT_COUNT" + + merge-pr: + needs: sync-master + if: needs.sync-master.outputs.pr_created == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: dev + + - name: Check PR mergeability + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + PR_NUMBER=${{ needs.sync-master.outputs.pr_number }} + MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable') - if [ "$CURRENT_COMMIT" = "$NEW_COMMIT" ]; then - echo "No new changes found, master is already up to date" + if [[ "$MERGE_STATUS" == "MERGEABLE" ]]; then + echo "PR is mergeable, proceeding with merge." else - echo "Pushing updates to master" - git push origin HEAD:master --force - echo "MASTER_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV + echo "PR is not mergeable due to conflicts. Manual resolution required." + exit 1 fi - - name: Rebase dev onto master + - name: Merge PR env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git fetch origin dev:refs/remotes/origin/dev --no-tags - git checkout -b temp-dev origin/dev - - echo "Attempting to rebase dev onto master..." - if ! git rebase master; then - echo "⚠️ Rebase conflict detected, aborting" - git rebase --abort - exit 1 - fi - - echo "Rebase successful, force pushing to dev..." - git push origin HEAD:dev --force + PR_NUMBER=${{ needs.sync-master.outputs.pr_number }} + gh pr merge $PR_NUMBER --merge --admin - - name: Create version tag + tag-dev: + needs: merge-pr + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: dev + + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Create and push tag env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git checkout master - COMMIT_COUNT=$(git rev-list --count HEAD) - NEW_TAG="b${COMMIT_COUNT}" - - if git ls-remote --tags origin | grep -q "refs/tags/${NEW_TAG}$"; then - echo "Tag $NEW_TAG already exists on remote, skipping tag creation" + TAG_NAME="b${{ needs.sync-master.outputs.commit_count }}" + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then + echo "Tag $TAG_NAME already exists, skipping." else - echo "Creating new tag: $NEW_TAG" - git tag "$NEW_TAG" - git push origin "$NEW_TAG" - echo "Successfully created and pushed tag $NEW_TAG" + echo "Creating and pushing tag $TAG_NAME" + git tag "$TAG_NAME" + git push origin "$TAG_NAME" fi From 688aa038c2f0c7eea78f138afab43f16cdb27bfc Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 15:38:55 +0700 Subject: [PATCH 15/29] chore: add pr dev to test ci --- .github/workflows/upstream-sync.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 5943a686bcac0..83751ea820b91 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -4,6 +4,9 @@ on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering + pull_request: + branches: + - dev jobs: sync-master: From 44cc5e5cda8a61504c9f224f2a59839b437b28c7 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 15:52:52 +0700 Subject: [PATCH 16/29] fix: fetch exist -1 --- .github/workflows/upstream-sync.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 83751ea820b91..413c289031409 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -4,9 +4,6 @@ on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering - pull_request: - branches: - - dev jobs: sync-master: @@ -38,7 +35,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream --tags + git fetch upstream --prune --unshallow --tags LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') From 0e7ccf2801658090caf77d5592065bdf39f472b2 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 15:55:01 +0700 Subject: [PATCH 17/29] ci: add pr dev branch test ci --- .github/workflows/upstream-sync.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 413c289031409..b331c9eadfa81 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -4,6 +4,9 @@ on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC workflow_dispatch: # Allow manual triggering + pull_request: + branches: + - dev jobs: sync-master: From 952dc3d0a57fdd2b8aa9735a85d957fb1532dd22 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 16:06:53 +0700 Subject: [PATCH 18/29] chore: update fetch --- .github/workflows/upstream-sync.yml | 55 +++++++++++++++++------------ 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index b331c9eadfa81..37c1d3f0afbad 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 # Fetch only the latest commit token: ${{ secrets.PAT_SERVICE_ACCOUNT }} ref: master @@ -33,26 +33,33 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote and fetch latest release + - name: Add upstream remote env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - git remote add upstream https://github.com/ggml-org/llama.cpp.git - git fetch upstream --prune --unshallow --tags + git remote add upstream https://github.com/ggml-org/llama.cpp.git || true + git fetch upstream --prune --tags --depth=1 # Fetch only necessary tags + - name: Get Latest Release Tag + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') - + if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then echo "No valid release found. Exiting." exit 1 fi - + echo "Latest release tag: $LATEST_RELEASE_TAG" - git fetch upstream $LATEST_RELEASE_TAG - git checkout $LATEST_RELEASE_TAG + echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV - git reset --hard upstream/$LATEST_RELEASE_TAG - git push origin HEAD:master --force + - name: Sync Master with Latest Release + run: | + LATEST_RELEASE_TAG=${{ env.LATEST_RELEASE_TAG }} + git fetch upstream $LATEST_RELEASE_TAG --depth=1 + git checkout -B master $LATEST_RELEASE_TAG + git push origin master --force - name: Create PR to merge master into dev id: create-pr @@ -65,14 +72,18 @@ jobs: PR_TITLE="Sync master (latest release) → dev" PR_BODY="This PR updates the dev branch with the latest release from ggml-org/llama.cpp" - gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev || echo "PR already exists." - - PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number') - echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV - echo "::set-output name=pr_number::$PR_NUMBER" - echo "::set-output name=pr_created::true" + 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 "") + + if [[ -z "$PR_NUMBER" ]]; then + echo "PR already exists or failed to create." + echo "::set-output name=pr_created::false" + else + echo "PR created: #$PR_NUMBER" + echo "::set-output name=pr_number::$PR_NUMBER" + echo "::set-output name=pr_created::true" + fi - - name: Count commits for tagging + - name: Count Commits for Tagging id: commit-count run: | COMMIT_COUNT=$(git rev-list --count HEAD) @@ -90,17 +101,17 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 token: ${{ secrets.PAT_SERVICE_ACCOUNT }} ref: dev - - name: Check PR mergeability + - name: Check PR Mergeability env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | PR_NUMBER=${{ needs.sync-master.outputs.pr_number }} MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable') - + if [[ "$MERGE_STATUS" == "MERGEABLE" ]]; then echo "PR is mergeable, proceeding with merge." else @@ -122,7 +133,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 token: ${{ secrets.PAT_SERVICE_ACCOUNT }} ref: dev @@ -131,7 +142,7 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Create and push tag + - name: Create and Push Tag env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | From 1c6b1fbd44eaab89d1c6ccfe4b7184ca6a4eb82d Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 16:28:21 +0700 Subject: [PATCH 19/29] refactor: facilitate workflow --- .github/workflows/upstream-sync.yml | 144 ++++++++-------------------- 1 file changed, 41 insertions(+), 103 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 37c1d3f0afbad..e0e95c05fe8cd 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -1,156 +1,94 @@ -name: Sync with Latest Release & Merge to Dev +name: Sync Upstream and Update Dev Branch on: schedule: - cron: '0 0 * * *' # Runs daily at midnight UTC - workflow_dispatch: # Allow manual triggering + workflow_dispatch: # Allows manual trigger pull_request: branches: - dev jobs: - sync-master: + sync-and-merge: runs-on: ubuntu-latest permissions: contents: write pull-requests: write - - outputs: - pr_number: ${{ steps.create-pr.outputs.pr_number }} - pr_created: ${{ steps.create-pr.outputs.pr_created }} - commit_count: ${{ steps.commit-count.outputs.commit_count }} - + steps: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 1 # Fetch only the latest commit + fetch-depth: 0 # Full history for commit counting token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - ref: master - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Add upstream remote - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + - name: Add upstream remote and fetch latest release run: | git remote add upstream https://github.com/ggml-org/llama.cpp.git || true - git fetch upstream --prune --tags --depth=1 # Fetch only necessary tags - - - name: Get Latest Release Tag - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} - run: | LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') - + if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then echo "No valid release found. Exiting." exit 1 fi - - echo "Latest release tag: $LATEST_RELEASE_TAG" + echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV + git fetch upstream $LATEST_RELEASE_TAG - - name: Sync Master with Latest Release + - name: Update master branch with latest release run: | - LATEST_RELEASE_TAG=${{ env.LATEST_RELEASE_TAG }} - git fetch upstream $LATEST_RELEASE_TAG --depth=1 - git checkout -B master $LATEST_RELEASE_TAG + git checkout -B master FETCH_HEAD git push origin master --force + # Count total commits for tagging + COMMIT_COUNT=$(git rev-list --count HEAD) + echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV - - name: Create PR to merge master into dev + - name: Create PR to dev branch id: create-pr - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | git checkout -b update-dev-from-master git push origin update-dev-from-master --force - PR_TITLE="Sync master (latest release) → dev" - PR_BODY="This PR updates the dev branch with the latest release from ggml-org/llama.cpp" + PR_TITLE="Sync master with upstream release $LATEST_RELEASE_TAG" + PR_BODY="This PR updates the dev branch with the latest release ($LATEST_RELEASE_TAG) from ggml-org/llama.cpp" 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 "") if [[ -z "$PR_NUMBER" ]]; then - echo "PR already exists or failed to create." - echo "::set-output name=pr_created::false" + echo "PR_CREATED=false" >> $GITHUB_ENV + echo "PR_NUMBER=0" >> $GITHUB_ENV else echo "PR created: #$PR_NUMBER" - echo "::set-output name=pr_number::$PR_NUMBER" - echo "::set-output name=pr_created::true" + echo "PR_CREATED=true" >> $GITHUB_ENV + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV fi - - name: Count Commits for Tagging - id: commit-count - run: | - COMMIT_COUNT=$(git rev-list --count HEAD) - echo "::set-output name=commit_count::$COMMIT_COUNT" - - merge-pr: - needs: sync-master - if: needs.sync-master.outputs.pr_created == 'true' - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1 - token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - ref: dev - - - name: Check PR Mergeability - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + - name: Check and merge PR if no conflicts + if: env.PR_CREATED == 'true' run: | - PR_NUMBER=${{ needs.sync-master.outputs.pr_number }} - MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable') - - if [[ "$MERGE_STATUS" == "MERGEABLE" ]]; then + PR_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable') + + if [[ "$PR_STATUS" == "MERGEABLE" ]]; then echo "PR is mergeable, proceeding with merge." + gh pr merge $PR_NUMBER --merge --admin + + # Create and push tag after successful merge + git fetch origin dev + git checkout dev + TAG_NAME="b$COMMIT_COUNT" + + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then + echo "Tag $TAG_NAME already exists, skipping." + else + git tag "$TAG_NAME" + git push origin "$TAG_NAME" + fi else echo "PR is not mergeable due to conflicts. Manual resolution required." - exit 1 - fi - - - name: Merge PR - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} - run: | - PR_NUMBER=${{ needs.sync-master.outputs.pr_number }} - gh pr merge $PR_NUMBER --merge --admin - - tag-dev: - needs: merge-pr - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1 - token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - ref: dev - - - name: Configure Git - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Create and Push Tag - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} - run: | - TAG_NAME="b${{ needs.sync-master.outputs.commit_count }}" - if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then - echo "Tag $TAG_NAME already exists, skipping." - else - echo "Creating and pushing tag $TAG_NAME" - git tag "$TAG_NAME" - git push origin "$TAG_NAME" - fi + exit 0 # Don't fail the workflow + fi \ No newline at end of file From e97dfa085bdd8f655dc7521057cf00d6780520f9 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 16:46:34 +0700 Subject: [PATCH 20/29] chore: update ci --- .github/workflows/upstream-sync.yml | 131 +++++++++++++++++----------- 1 file changed, 81 insertions(+), 50 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index e0e95c05fe8cd..f1d6054f48f1c 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -1,15 +1,14 @@ -name: Sync Upstream and Update Dev Branch +name: Sync Upstream and Update Dev on: schedule: - - cron: '0 0 * * *' # Runs daily at midnight UTC - workflow_dispatch: # Allows manual trigger + - cron: '0 0 * * *' # Daily at midnight UTC + workflow_dispatch: # Manual trigger pull_request: - branches: - - dev + branches: [dev] jobs: - sync-and-merge: + sync-and-update: runs-on: ubuntu-latest permissions: contents: write @@ -19,76 +18,108 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Full history for commit counting + fetch-depth: 0 token: ${{ secrets.PAT_SERVICE_ACCOUNT }} + ref: master - - name: Configure Git + - name: Setup run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git remote add upstream https://github.com/ggml-org/llama.cpp.git || true - - name: Add upstream remote and fetch latest release + - name: Sync with latest release + id: sync run: | - git remote add upstream https://github.com/ggml-org/llama.cpp.git || true - LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') - - if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then + # Get latest release tag + LATEST_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name') + if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then echo "No valid release found. Exiting." exit 1 fi + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV - echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV - git fetch upstream $LATEST_RELEASE_TAG - - - name: Update master branch with latest release - run: | + # Update master branch + git fetch upstream $LATEST_TAG --depth=1 git checkout -B master FETCH_HEAD git push origin master --force - # Count total commits for tagging + + # Count commits for tagging COMMIT_COUNT=$(git rev-list --count HEAD) echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV - - name: Create PR to dev branch - id: create-pr + - name: Create PR to dev + id: create_pr + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | + # Create branch for PR git checkout -b update-dev-from-master git push origin update-dev-from-master --force - - PR_TITLE="Sync master with upstream release $LATEST_RELEASE_TAG" - PR_BODY="This PR updates the dev branch with the latest release ($LATEST_RELEASE_TAG) from ggml-org/llama.cpp" - - 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 "") + + # Create PR + PR_TITLE="Sync master with upstream release $LATEST_TAG" + PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp" + + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev + PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number') if [[ -z "$PR_NUMBER" ]]; then - echo "PR_CREATED=false" >> $GITHUB_ENV - echo "PR_NUMBER=0" >> $GITHUB_ENV - else - echo "PR created: #$PR_NUMBER" - echo "PR_CREATED=true" >> $GITHUB_ENV - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + echo "Failed to create PR" + exit 0 fi + + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - - name: Check and merge PR if no conflicts - if: env.PR_CREATED == 'true' + - name: Check PR status + id: check_pr + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - PR_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable') + # Check if PR can be merged + MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeStateStatus --jq '.mergeStateStatus') + if [[ "$MERGE_STATUS" != "CLEAN" ]]; then + echo "PR has conflicts and needs manual review" + exit 0 + fi - if [[ "$PR_STATUS" == "MERGEABLE" ]]; then - echo "PR is mergeable, proceeding with merge." - gh pr merge $PR_NUMBER --merge --admin - - # Create and push tag after successful merge - git fetch origin dev - git checkout dev - TAG_NAME="b$COMMIT_COUNT" - - if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then - echo "Tag $TAG_NAME already exists, skipping." + # Wait for CI checks without hardcoded attempts + echo "Waiting for CI checks to complete..." + while true; do + ci_completed=$(gh pr checks $PR_NUMBER --json completedAt --jq '.[].completedAt') + if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then + echo "CI is still running, waiting..." + sleep 60 else - git tag "$TAG_NAME" - git push origin "$TAG_NAME" + echo "CI has completed, checking states..." + ci_states=$(gh pr checks $PR_NUMBER --json state --jq '.[].state') + if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then + echo "CI failed, exiting..." + exit 1 + else + echo "CI passed, proceeding with merge..." + break + fi fi + done + + - name: Merge PR and create tag + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} + run: | + # Merge PR + gh pr merge $PR_NUMBER --merge + + # Create tag + git fetch origin dev + git checkout dev + TAG_NAME="b$COMMIT_COUNT" + + # Check if tag exists + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then + echo "Tag $TAG_NAME already exists" else - echo "PR is not mergeable due to conflicts. Manual resolution required." - exit 0 # Don't fail the workflow + git tag "$TAG_NAME" + git push origin "$TAG_NAME" + echo "Tag $TAG_NAME created successfully" fi \ No newline at end of file From 083c3a5057a5d1304d36bf4bee8c01f17945acd0 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 16:49:37 +0700 Subject: [PATCH 21/29] chore: add logic when no difference between dev and master branch --- .github/workflows/upstream-sync.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index f1d6054f48f1c..1a026a1cb94e5 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -53,6 +53,17 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | + # Fetch dev branch to compare + git fetch origin dev + + # Check if there are differences between master and dev + git diff --quiet master origin/dev + if [ $? -eq 0 ]; then + echo "No differences found between master and dev. Skipping PR creation." + echo "SKIP_PR=true" >> $GITHUB_ENV + exit 0 + fi + # Create branch for PR git checkout -b update-dev-from-master git push origin update-dev-from-master --force @@ -66,6 +77,7 @@ jobs: if [[ -z "$PR_NUMBER" ]]; then echo "Failed to create PR" + echo "SKIP_PR=true" >> $GITHUB_ENV exit 0 fi @@ -73,6 +85,7 @@ jobs: - name: Check PR status id: check_pr + if: ${{ env.SKIP_PR != 'true' }} env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | @@ -104,11 +117,12 @@ jobs: done - name: Merge PR and create tag + if: ${{ env.SKIP_PR != 'true' }} env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | # Merge PR - gh pr merge $PR_NUMBER --merge + gh pr merge $PR_NUMBER --merge --admin # Create tag git fetch origin dev From d86925240c73a7795a3e4da500b6ffab5f44c527 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 16:51:31 +0700 Subject: [PATCH 22/29] chore: update ci --- .github/workflows/upstream-sync.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 1a026a1cb94e5..f2ee7bc9a98b0 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -57,11 +57,15 @@ jobs: git fetch origin dev # Check if there are differences between master and dev - git diff --quiet master origin/dev - if [ $? -eq 0 ]; then + # Exit code 0 means no differences, exit code 1 means there are differences + git diff --quiet master origin/dev || HAS_DIFF=$? + + if [ -z "$HAS_DIFF" ]; then echo "No differences found between master and dev. Skipping PR creation." echo "SKIP_PR=true" >> $GITHUB_ENV exit 0 + else + echo "Found differences between master and dev. Creating PR..." fi # Create branch for PR @@ -72,11 +76,18 @@ jobs: PR_TITLE="Sync master with upstream release $LATEST_TAG" PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp" - gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev || PR_FAILED=$? + + if [ ! -z "$PR_FAILED" ]; then + echo "Failed to create PR. A PR may already exist or branches may be identical." + echo "SKIP_PR=true" >> $GITHUB_ENV + exit 0 + fi + PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number') if [[ -z "$PR_NUMBER" ]]; then - echo "Failed to create PR" + echo "Failed to get PR number" echo "SKIP_PR=true" >> $GITHUB_ENV exit 0 fi From 5c5ca2da47ce83406845f394c8cdd4dfe03cdf0a Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:01:17 +0700 Subject: [PATCH 23/29] chore: update ci --- .github/workflows/upstream-sync.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index f2ee7bc9a98b0..4905bc06c02e7 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -68,15 +68,17 @@ jobs: echo "Found differences between master and dev. Creating PR..." fi - # Create branch for PR - git checkout -b update-dev-from-master - git push origin update-dev-from-master --force + # Create branch for PR with timestamp + BRANCH_NAME="update-dev-from-master-$(date +'%Y-%m-%d-%H-%M')" + git checkout -b $BRANCH_NAME + git push origin $BRANCH_NAME --force # Create PR PR_TITLE="Sync master with upstream release $LATEST_TAG" PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp" - gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head update-dev-from-master --base dev --reviewer vansangpfiev || PR_FAILED=$? + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base dev --reviewer vansangpfiev || PR_FAILED=$? + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV if [ ! -z "$PR_FAILED" ]; then echo "Failed to create PR. A PR may already exist or branches may be identical." @@ -84,7 +86,7 @@ jobs: exit 0 fi - PR_NUMBER=$(gh pr list --head update-dev-from-master --json number --jq '.[0].number') + PR_NUMBER=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number') if [[ -z "$PR_NUMBER" ]]; then echo "Failed to get PR number" @@ -133,7 +135,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | # Merge PR - gh pr merge $PR_NUMBER --merge --admin + gh pr merge $PR_NUMBER --merge # Create tag git fetch origin dev From b7b74e976fa95b9f63f0617361223bfcf3d95078 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:07:01 +0700 Subject: [PATCH 24/29] chore: update ci --- .github/workflows/upstream-sync.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 4905bc06c02e7..2be2c39986929 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -73,20 +73,29 @@ jobs: git checkout -b $BRANCH_NAME git push origin $BRANCH_NAME --force - # Create PR + # Create PR using GitHub CLI with explicit repo PR_TITLE="Sync master with upstream release $LATEST_TAG" PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp" - gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base dev --reviewer vansangpfiev || PR_FAILED=$? + # Create PR with explicit repository specification + gh pr create \ + --repo menloresearch/llama.cpp \ + --title "$PR_TITLE" \ + --body "$PR_BODY" \ + --head "$BRANCH_NAME" \ + --base dev \ + --reviewer vansangpfiev || PR_FAILED=$? + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV if [ ! -z "$PR_FAILED" ]; then - echo "Failed to create PR. A PR may already exist or branches may be identical." + echo "Failed to create PR. Error code: $PR_FAILED" echo "SKIP_PR=true" >> $GITHUB_ENV exit 0 fi - PR_NUMBER=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number') + # Get PR number + PR_NUMBER=$(gh pr list --repo menloresearch/llama.cpp --head "$BRANCH_NAME" --json number --jq '.[0].number') if [[ -z "$PR_NUMBER" ]]; then echo "Failed to get PR number" @@ -103,7 +112,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | # Check if PR can be merged - MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeStateStatus --jq '.mergeStateStatus') + MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') if [[ "$MERGE_STATUS" != "CLEAN" ]]; then echo "PR has conflicts and needs manual review" exit 0 @@ -112,13 +121,13 @@ jobs: # Wait for CI checks without hardcoded attempts echo "Waiting for CI checks to complete..." while true; do - ci_completed=$(gh pr checks $PR_NUMBER --json completedAt --jq '.[].completedAt') + ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt') if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then echo "CI is still running, waiting..." sleep 60 else echo "CI has completed, checking states..." - ci_states=$(gh pr checks $PR_NUMBER --json state --jq '.[].state') + ci_states=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json state --jq '.[].state') if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then echo "CI failed, exiting..." exit 1 @@ -135,7 +144,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | # Merge PR - gh pr merge $PR_NUMBER --merge + gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge # Create tag git fetch origin dev From eaa2b65ddfba653ada148f60aad6763ed24fadd5 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:20:38 +0700 Subject: [PATCH 25/29] chore: update ci --- .github/workflows/upstream-sync.yml | 103 +++++++++++++++++++--------- 1 file changed, 72 insertions(+), 31 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 2be2c39986929..02802977a37fc 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -53,11 +53,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # Fetch dev branch to compare git fetch origin dev - - # Check if there are differences between master and dev - # Exit code 0 means no differences, exit code 1 means there are differences git diff --quiet master origin/dev || HAS_DIFF=$? if [ -z "$HAS_DIFF" ]; then @@ -68,23 +64,19 @@ jobs: echo "Found differences between master and dev. Creating PR..." fi - # Create branch for PR with timestamp BRANCH_NAME="update-dev-from-master-$(date +'%Y-%m-%d-%H-%M')" git checkout -b $BRANCH_NAME git push origin $BRANCH_NAME --force - # Create PR using GitHub CLI with explicit repo PR_TITLE="Sync master with upstream release $LATEST_TAG" PR_BODY="Updates dev branch with latest release ($LATEST_TAG) from ggml-org/llama.cpp" - # Create PR with explicit repository specification gh pr create \ --repo menloresearch/llama.cpp \ --title "$PR_TITLE" \ --body "$PR_BODY" \ --head "$BRANCH_NAME" \ - --base dev \ - --reviewer vansangpfiev || PR_FAILED=$? + --base dev \ || PR_FAILED=$? echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV @@ -94,7 +86,6 @@ jobs: exit 0 fi - # Get PR number PR_NUMBER=$(gh pr list --repo menloresearch/llama.cpp --head "$BRANCH_NAME" --json number --jq '.[0].number') if [[ -z "$PR_NUMBER" ]]; then @@ -111,40 +102,90 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # Check if PR can be merged MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') + echo "PR merge status: $MERGE_STATUS" + if [[ "$MERGE_STATUS" != "CLEAN" ]]; then - echo "PR has conflicts and needs manual review" + echo "PR has conflicts and needs manual review. Stopping automatic merge." + echo "SKIP_MERGE=true" >> $GITHUB_ENV exit 0 fi - # Wait for CI checks without hardcoded attempts - echo "Waiting for CI checks to complete..." - while true; do - ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt') - if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then - echo "CI is still running, waiting..." - sleep 60 - else - echo "CI has completed, checking states..." - ci_states=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json state --jq '.[].state') - if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then - echo "CI failed, exiting..." - exit 1 + # Check if there are any CI checks + CI_CHECKS_EXIST=false + MAX_ATTEMPTS=5 + + for i in $(seq 1 $MAX_ATTEMPTS); do + echo "Checking for CI checks (attempt $i of $MAX_ATTEMPTS)..." + CI_CHECK_COUNT=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json name --jq 'length') + + if [[ "$CI_CHECK_COUNT" -gt 0 ]]; then + CI_CHECKS_EXIST=true + echo "Found $CI_CHECK_COUNT CI checks" + break + fi + + echo "No CI checks found yet, waiting 10 seconds..." + sleep 10 + done + + # Only wait for CI if checks exist + if [[ "$CI_CHECKS_EXIST" == "true" ]]; then + echo "Waiting for CI checks to complete..." + MAX_WAIT_TIME=10 # Maximum wait time in minutes + WAIT_INTERVAL=30 # Check interval in seconds + ELAPSED_TIME=0 + + while (( ELAPSED_TIME < MAX_WAIT_TIME * 60 )); do + # Get CI check details + CI_STATUS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json status,conclusion --jq '.[].status') + + # If any are still in progress, wait + if echo "$CI_STATUS" | grep -q "IN_PROGRESS"; then + echo "CI is still running, waiting... ($ELAPSED_TIME seconds elapsed of $(( MAX_WAIT_TIME * 60 )) max)" + sleep $WAIT_INTERVAL + ELAPSED_TIME=$((ELAPSED_TIME + WAIT_INTERVAL)) else - echo "CI passed, proceeding with merge..." + # All checks are complete + echo "All CI checks completed!" + + # Check for failures + CI_CONCLUSIONS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json conclusion --jq '.[].conclusion') + if echo "$CI_CONCLUSIONS" | grep -qE "FAILURE|CANCELLED|TIMED_OUT"; then + echo "Some CI checks failed. Human review required." + echo "SKIP_MERGE=true" >> $GITHUB_ENV + exit 0 + fi + break fi - fi - done + + # Check if we've exceeded the maximum wait time + if (( ELAPSED_TIME >= MAX_WAIT_TIME * 60 )); then + echo "Maximum wait time of $MAX_WAIT_TIME minutes exceeded. Marking for human review." + echo "SKIP_MERGE=true" >> $GITHUB_ENV + exit 0 + fi + done + else + echo "No CI checks found after $MAX_ATTEMPTS attempts. Proceeding with merge." + fi - name: Merge PR and create tag - if: ${{ env.SKIP_PR != 'true' }} + if: ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }} env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # Merge PR - gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge + echo "Attempting to merge PR #$PR_NUMBER..." + gh pr merge $PR_NUMBER --repo menloresearch/llama.cpp --merge || MERGE_FAILED=$? + + if [ ! -z "$MERGE_FAILED" ]; then + echo "Failed to merge PR. Error code: $MERGE_FAILED" + echo "Manual intervention required." + exit 0 + fi + + echo "PR merged successfully!" # Create tag git fetch origin dev From c7ddc646a32edf656d435a2eb8132102064feeac Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:28:11 +0700 Subject: [PATCH 26/29] chore: remove extra spaces gh create pr --- .github/workflows/upstream-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 02802977a37fc..e6b38b2926426 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -76,7 +76,7 @@ jobs: --title "$PR_TITLE" \ --body "$PR_BODY" \ --head "$BRANCH_NAME" \ - --base dev \ || PR_FAILED=$? + --base dev || PR_FAILED=$? echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV From 877494f4e781c677c43f98202300b1221ed965a4 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:35:20 +0700 Subject: [PATCH 27/29] ci: add wait ci complete --- .github/workflows/upstream-sync.yml | 76 ++++++++--------------------- 1 file changed, 19 insertions(+), 57 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index e6b38b2926426..21c44ba0395c4 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -96,12 +96,13 @@ jobs: echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - - name: Check PR status + - name: Check PR status and wait for CI id: check_pr if: ${{ env.SKIP_PR != 'true' }} env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | + # Check if PR can be merged MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') echo "PR merge status: $MERGE_STATUS" @@ -111,65 +112,26 @@ jobs: exit 0 fi - # Check if there are any CI checks - CI_CHECKS_EXIST=false - MAX_ATTEMPTS=5 - - for i in $(seq 1 $MAX_ATTEMPTS); do - echo "Checking for CI checks (attempt $i of $MAX_ATTEMPTS)..." - CI_CHECK_COUNT=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json name --jq 'length') - - if [[ "$CI_CHECK_COUNT" -gt 0 ]]; then - CI_CHECKS_EXIST=true - echo "Found $CI_CHECK_COUNT CI checks" - break - fi - - echo "No CI checks found yet, waiting 10 seconds..." - sleep 10 - done - - # Only wait for CI if checks exist - if [[ "$CI_CHECKS_EXIST" == "true" ]]; then - echo "Waiting for CI checks to complete..." - MAX_WAIT_TIME=10 # Maximum wait time in minutes - WAIT_INTERVAL=30 # Check interval in seconds - ELAPSED_TIME=0 - - while (( ELAPSED_TIME < MAX_WAIT_TIME * 60 )); do - # Get CI check details - CI_STATUS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json status,conclusion --jq '.[].status') - - # If any are still in progress, wait - if echo "$CI_STATUS" | grep -q "IN_PROGRESS"; then - echo "CI is still running, waiting... ($ELAPSED_TIME seconds elapsed of $(( MAX_WAIT_TIME * 60 )) max)" - sleep $WAIT_INTERVAL - ELAPSED_TIME=$((ELAPSED_TIME + WAIT_INTERVAL)) - else - # All checks are complete - echo "All CI checks completed!" - - # Check for failures - CI_CONCLUSIONS=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json conclusion --jq '.[].conclusion') - if echo "$CI_CONCLUSIONS" | grep -qE "FAILURE|CANCELLED|TIMED_OUT"; then - echo "Some CI checks failed. Human review required." - echo "SKIP_MERGE=true" >> $GITHUB_ENV - exit 0 - fi - - break - fi - - # Check if we've exceeded the maximum wait time - if (( ELAPSED_TIME >= MAX_WAIT_TIME * 60 )); then - echo "Maximum wait time of $MAX_WAIT_TIME minutes exceeded. Marking for human review." + # Wait for CI checks using the more reliable method + echo "Waiting for CI checks to complete..." + while true; do + ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt') + if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then + echo "CI is still running, waiting..." + sleep 60 + else + echo "CI has completed, checking states..." + ci_states=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json state --jq '.[].state') + if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then + echo "CI failed, exiting..." echo "SKIP_MERGE=true" >> $GITHUB_ENV exit 0 + else + echo "CI passed, proceeding with merge..." + break fi - done - else - echo "No CI checks found after $MAX_ATTEMPTS attempts. Proceeding with merge." - fi + fi + done - name: Merge PR and create tag if: ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }} From 5830f409b0a1f74f564a6886a222c334f83a16d8 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:41:35 +0700 Subject: [PATCH 28/29] chore: update ci --- .github/workflows/upstream-sync.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 21c44ba0395c4..f4fb00036a26c 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -102,16 +102,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # Check if PR can be merged - MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') - echo "PR merge status: $MERGE_STATUS" - - if [[ "$MERGE_STATUS" != "CLEAN" ]]; then - echo "PR has conflicts and needs manual review. Stopping automatic merge." - echo "SKIP_MERGE=true" >> $GITHUB_ENV - exit 0 - fi - # Wait for CI checks using the more reliable method echo "Waiting for CI checks to complete..." while true; do @@ -132,6 +122,16 @@ jobs: fi fi done + # Check if PR can be merged + MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') + echo "PR merge status: $MERGE_STATUS" + + if [[ "$MERGE_STATUS" != "CLEAN" ]]; then + echo "PR has conflicts and needs manual review. Stopping automatic merge." + echo "SKIP_MERGE=true" >> $GITHUB_ENV + exit 0 + fi + - name: Merge PR and create tag if: ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }} From 186f231da761de28501a56a4fd45d7f177620ca8 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 18 Mar 2025 17:59:49 +0700 Subject: [PATCH 29/29] chore: finish ci --- .github/workflows/upstream-sync.yml | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index f4fb00036a26c..f40e9983bdebf 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -96,16 +96,23 @@ jobs: echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - - name: Check PR status and wait for CI - id: check_pr + - name: Wait for CI checks + id: wait_for_ci if: ${{ env.SKIP_PR != 'true' }} env: GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} run: | - # Wait for CI checks using the more reliable method echo "Waiting for CI checks to complete..." while true; do ci_completed=$(gh pr checks $PR_NUMBER --repo menloresearch/llama.cpp --json completedAt --jq '.[].completedAt') + + # If there are no CI checks, proceed with merge + if [[ -z "$ci_completed" ]]; then + echo "No CI checks detected. Proceeding with merge." + break + fi + + # Check if any checks are still running if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then echo "CI is still running, waiting..." sleep 60 @@ -122,16 +129,6 @@ jobs: fi fi done - # Check if PR can be merged - MERGE_STATUS=$(gh pr view $PR_NUMBER --repo menloresearch/llama.cpp --json mergeStateStatus --jq '.mergeStateStatus') - echo "PR merge status: $MERGE_STATUS" - - if [[ "$MERGE_STATUS" != "CLEAN" ]]; then - echo "PR has conflicts and needs manual review. Stopping automatic merge." - echo "SKIP_MERGE=true" >> $GITHUB_ENV - exit 0 - fi - - name: Merge PR and create tag if: ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }}