Skip to content
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
37f5836
ci: add upstream sync
Minh141120 Mar 18, 2025
422520c
chore: test ci
Minh141120 Mar 18, 2025
3cf924e
chore: update ci
Minh141120 Mar 18, 2025
c855cfc
ci: add pat env for add upstream remote step
Minh141120 Mar 18, 2025
26fe7ea
ci: fetch master remote only
Minh141120 Mar 18, 2025
f61ccda
chore: update ci
Minh141120 Mar 18, 2025
92fb00f
ci: rebase dev onto master branch
Minh141120 Mar 18, 2025
034209e
chore: test ci
Minh141120 Mar 18, 2025
c1e8102
chore: update ci
Minh141120 Mar 18, 2025
ba7c6f2
chore: update ci
Minh141120 Mar 18, 2025
8d6bf74
ci: add ref
Minh141120 Mar 18, 2025
7dbd130
ci: add debug step
Minh141120 Mar 18, 2025
7fce78f
ci: update upstream sync
Minh141120 Mar 18, 2025
101f426
ci: update workflow upstream
Minh141120 Mar 18, 2025
688aa03
chore: add pr dev to test ci
Minh141120 Mar 18, 2025
44cc5e5
fix: fetch exist -1
Minh141120 Mar 18, 2025
0e7ccf2
ci: add pr dev branch test ci
Minh141120 Mar 18, 2025
952dc3d
chore: update fetch
Minh141120 Mar 18, 2025
1c6b1fb
refactor: facilitate workflow
Minh141120 Mar 18, 2025
e97dfa0
chore: update ci
Minh141120 Mar 18, 2025
083c3a5
chore: add logic when no difference between dev and master branch
Minh141120 Mar 18, 2025
d869252
chore: update ci
Minh141120 Mar 18, 2025
5c5ca2d
chore: update ci
Minh141120 Mar 18, 2025
b7b74e9
chore: update ci
Minh141120 Mar 18, 2025
eaa2b65
chore: update ci
Minh141120 Mar 18, 2025
c7ddc64
chore: remove extra spaces gh create pr
Minh141120 Mar 18, 2025
877494f
ci: add wait ci complete
Minh141120 Mar 18, 2025
5830f40
chore: update ci
Minh141120 Mar 18, 2025
186f231
chore: finish ci
Minh141120 Mar 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github/workflows/upstream-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Sync Upstream and Update Dev

on:
schedule:
- cron: '0 0 * * *' # Daily at midnight UTC
workflow_dispatch: # Manual trigger
pull_request:
branches: [dev]

jobs:
sync-and-update:
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: master

- 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: Sync with latest release
id: sync
run: |
# 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

# Update master branch
git fetch upstream $LATEST_TAG --depth=1
git checkout -B master FETCH_HEAD
git push origin master --force

# Count commits for tagging
COMMIT_COUNT=$(git rev-list --count HEAD)
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV

- name: Create PR to dev
id: create_pr
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
git fetch origin dev
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

BRANCH_NAME="update-dev-from-master-$(date +'%Y-%m-%d-%H-%M')"
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME --force

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 \
--repo menloresearch/llama.cpp \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--head "$BRANCH_NAME" \
--base dev || PR_FAILED=$?

echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV

if [ ! -z "$PR_FAILED" ]; then
echo "Failed to create PR. Error code: $PR_FAILED"
echo "SKIP_PR=true" >> $GITHUB_ENV
exit 0
fi

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"
echo "SKIP_PR=true" >> $GITHUB_ENV
exit 0
fi

echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV

- name: Wait for CI checks
id: wait_for_ci
if: ${{ env.SKIP_PR != 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
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
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
fi
done

- name: Merge PR and create tag
if: ${{ env.SKIP_PR != 'true' && env.SKIP_MERGE != 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
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
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
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
echo "Tag $TAG_NAME created successfully"
fi