Skip to content

Commit 1c6b1fb

Browse files
committed
refactor: facilitate workflow
1 parent 952dc3d commit 1c6b1fb

File tree

1 file changed

+41
-103
lines changed

1 file changed

+41
-103
lines changed
Lines changed: 41 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,94 @@
1-
name: Sync with Latest Release & Merge to Dev
1+
name: Sync Upstream and Update Dev Branch
22

33
on:
44
schedule:
55
- cron: '0 0 * * *' # Runs daily at midnight UTC
6-
workflow_dispatch: # Allow manual triggering
6+
workflow_dispatch: # Allows manual trigger
77
pull_request:
88
branches:
99
- dev
1010

1111
jobs:
12-
sync-master:
12+
sync-and-merge:
1313
runs-on: ubuntu-latest
1414
permissions:
1515
contents: write
1616
pull-requests: write
17-
18-
outputs:
19-
pr_number: ${{ steps.create-pr.outputs.pr_number }}
20-
pr_created: ${{ steps.create-pr.outputs.pr_created }}
21-
commit_count: ${{ steps.commit-count.outputs.commit_count }}
22-
17+
2318
steps:
2419
- name: Checkout repository
2520
uses: actions/checkout@v4
2621
with:
27-
fetch-depth: 1 # Fetch only the latest commit
22+
fetch-depth: 0 # Full history for commit counting
2823
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
29-
ref: master
3024

3125
- name: Configure Git
3226
run: |
3327
git config --global user.name 'github-actions[bot]'
3428
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
3529
36-
- name: Add upstream remote
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
30+
- name: Add upstream remote and fetch latest release
3931
run: |
4032
git remote add upstream https://github.com/ggml-org/llama.cpp.git || true
41-
git fetch upstream --prune --tags --depth=1 # Fetch only necessary tags
42-
43-
- name: Get Latest Release Tag
44-
env:
45-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
46-
run: |
4733
LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | jq -r '.tag_name')
48-
34+
4935
if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
5036
echo "No valid release found. Exiting."
5137
exit 1
5238
fi
53-
54-
echo "Latest release tag: $LATEST_RELEASE_TAG"
39+
5540
echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV
41+
git fetch upstream $LATEST_RELEASE_TAG
5642
57-
- name: Sync Master with Latest Release
43+
- name: Update master branch with latest release
5844
run: |
59-
LATEST_RELEASE_TAG=${{ env.LATEST_RELEASE_TAG }}
60-
git fetch upstream $LATEST_RELEASE_TAG --depth=1
61-
git checkout -B master $LATEST_RELEASE_TAG
45+
git checkout -B master FETCH_HEAD
6246
git push origin master --force
47+
# Count total commits for tagging
48+
COMMIT_COUNT=$(git rev-list --count HEAD)
49+
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV
6350
64-
- name: Create PR to merge master into dev
51+
- name: Create PR to dev branch
6552
id: create-pr
66-
env:
67-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
6853
run: |
6954
git checkout -b update-dev-from-master
7055
git push origin update-dev-from-master --force
7156
72-
PR_TITLE="Sync master (latest release) → dev"
73-
PR_BODY="This PR updates the dev branch with the latest release from ggml-org/llama.cpp"
57+
PR_TITLE="Sync master with upstream release $LATEST_RELEASE_TAG"
58+
PR_BODY="This PR updates the dev branch with the latest release ($LATEST_RELEASE_TAG) from ggml-org/llama.cpp"
7459
7560
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 "")
7661
7762
if [[ -z "$PR_NUMBER" ]]; then
78-
echo "PR already exists or failed to create."
79-
echo "::set-output name=pr_created::false"
63+
echo "PR_CREATED=false" >> $GITHUB_ENV
64+
echo "PR_NUMBER=0" >> $GITHUB_ENV
8065
else
8166
echo "PR created: #$PR_NUMBER"
82-
echo "::set-output name=pr_number::$PR_NUMBER"
83-
echo "::set-output name=pr_created::true"
67+
echo "PR_CREATED=true" >> $GITHUB_ENV
68+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
8469
fi
8570
86-
- name: Count Commits for Tagging
87-
id: commit-count
88-
run: |
89-
COMMIT_COUNT=$(git rev-list --count HEAD)
90-
echo "::set-output name=commit_count::$COMMIT_COUNT"
91-
92-
merge-pr:
93-
needs: sync-master
94-
if: needs.sync-master.outputs.pr_created == 'true'
95-
runs-on: ubuntu-latest
96-
permissions:
97-
contents: write
98-
pull-requests: write
99-
100-
steps:
101-
- name: Checkout repository
102-
uses: actions/checkout@v4
103-
with:
104-
fetch-depth: 1
105-
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
106-
ref: dev
107-
108-
- name: Check PR Mergeability
109-
env:
110-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
71+
- name: Check and merge PR if no conflicts
72+
if: env.PR_CREATED == 'true'
11173
run: |
112-
PR_NUMBER=${{ needs.sync-master.outputs.pr_number }}
113-
MERGE_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable')
114-
115-
if [[ "$MERGE_STATUS" == "MERGEABLE" ]]; then
74+
PR_STATUS=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable')
75+
76+
if [[ "$PR_STATUS" == "MERGEABLE" ]]; then
11677
echo "PR is mergeable, proceeding with merge."
78+
gh pr merge $PR_NUMBER --merge --admin
79+
80+
# Create and push tag after successful merge
81+
git fetch origin dev
82+
git checkout dev
83+
TAG_NAME="b$COMMIT_COUNT"
84+
85+
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
86+
echo "Tag $TAG_NAME already exists, skipping."
87+
else
88+
git tag "$TAG_NAME"
89+
git push origin "$TAG_NAME"
90+
fi
11791
else
11892
echo "PR is not mergeable due to conflicts. Manual resolution required."
119-
exit 1
120-
fi
121-
122-
- name: Merge PR
123-
env:
124-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
125-
run: |
126-
PR_NUMBER=${{ needs.sync-master.outputs.pr_number }}
127-
gh pr merge $PR_NUMBER --merge --admin
128-
129-
tag-dev:
130-
needs: merge-pr
131-
runs-on: ubuntu-latest
132-
steps:
133-
- name: Checkout repository
134-
uses: actions/checkout@v4
135-
with:
136-
fetch-depth: 1
137-
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
138-
ref: dev
139-
140-
- name: Configure Git
141-
run: |
142-
git config --global user.name 'github-actions[bot]'
143-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
144-
145-
- name: Create and Push Tag
146-
env:
147-
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
148-
run: |
149-
TAG_NAME="b${{ needs.sync-master.outputs.commit_count }}"
150-
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
151-
echo "Tag $TAG_NAME already exists, skipping."
152-
else
153-
echo "Creating and pushing tag $TAG_NAME"
154-
git tag "$TAG_NAME"
155-
git push origin "$TAG_NAME"
156-
fi
93+
exit 0 # Don't fail the workflow
94+
fi

0 commit comments

Comments
 (0)