-
Notifications
You must be signed in to change notification settings - Fork 274
92 lines (80 loc) · 3.08 KB
/
Copy pathsync-to-private.yaml
File metadata and controls
92 lines (80 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Synchronize to Private Repository
on:
push:
branches:
- main
permissions:
contents: write
jobs:
cherry-pick-commits:
runs-on: ubuntu-latest
if: github.repository == 'nunchaku-ai/nunchaku'
steps:
- name: Clone private repository
run: |
git clone -b oss https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/nunchaku-ai/nunchaku-dev.git
- name: Add public remote and fetch
run: |
cd nunchaku-dev
git remote add public https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/nunchaku-ai/nunchaku.git
git fetch public main
- name: Cherry-pick latest commit from public/main
run: |
set -e
cd nunchaku-dev
COMMIT=$(git rev-parse public/main)
COMMIT_MSG=$(git log -1 --pretty=%B $COMMIT)
echo "Latest commit: $COMMIT"
echo "Commit message: $COMMIT_MSG"
if [[ "$COMMIT_MSG" == "[Auto Sync]"* ]]; then
echo "Skipping [Auto Sync] commit."
exit 0
fi
if [[ "$COMMIT_MSG" == *"[Dont Sync]"* ]]; then
echo "Skipping [Dont Sync] commit."
exit 0
fi
# Preserve original author and amend commit message
GIT_AUTHOR_NAME=$(git log --format='%aN' -n 1 $COMMIT)
GIT_AUTHOR_EMAIL=$(git log --format='%aE' -n 1 $COMMIT)
git config --global user.name "$GIT_AUTHOR_NAME"
git config --global user.email "$GIT_AUTHOR_EMAIL"
NEW_MSG="[Auto Sync] ${COMMIT_MSG}"
PARENTS=$(git rev-list --parents -n 1 $COMMIT)
NUM_PARENTS=$(echo $PARENTS | wc -w)
IGNORED_FILES=(
".github/workflows/sync-to-private.yml"
)
echo "Attempting cherry-pick..."
if [ "$NUM_PARENTS" -gt 2 ]; then
echo "Merge commit detected. Using -m 1"
git cherry-pick --allow-empty -m 1 $COMMIT || (
echo "Cherry-pick failed. Removing ignored files and continuing..."
for file in "${IGNORED_FILES[@]}"; do
git rm -rf "$file" || true
rm -rf "$file" || true
done
git commit --allow-empty -m "$COMMIT_MSG"
echo "Conflict resolved."
)
else
echo "Normal commit. Cherry-picking directly."
git cherry-pick --allow-empty $COMMIT || (
echo "Cherry-pick failed. Removing ignored files and continuing..."
for file in "${IGNORED_FILES[@]}"; do
git rm -rf "$file" || true
rm -rf "$file" || true
done
git commit --allow-empty -m "$COMMIT_MSG"
echo "Conflict resolved."
)
fi
for file in "${IGNORED_FILES[@]}"; do
git rm -rf "$file" || true
rm -rf "$file" || true
done
git commit --amend --allow-empty -m "$NEW_MSG" --author="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
- name: Push to the private oss branch
run: |
cd nunchaku-dev
git push origin oss