Repository navigation
131 lines (114 loc) · 4.16 KB
/
Copy pathsync-upstream.yml
File metadata and controls
131 lines (114 loc) · 4.16 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Sync Upstream
on:
schedule:
- cron: '20 16 * * *' # UTC 16:20 = Beijing 00:20, daily
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Add upstream and fetch
run: |
git remote add upstream https://github.com/openai/codex.git || true
git fetch upstream main
- name: Check for updates
id: check
run: |
LOCAL=$(git rev-parse HEAD)
UPSTREAM=$(git rev-parse upstream/main)
if [ "$LOCAL" = "$UPSTREAM" ]; then
echo "No updates from upstream"
echo "has_updates=false" >> $GITHUB_OUTPUT
else
echo "Upstream has new commits"
echo "has_updates=true" >> $GITHUB_OUTPUT
fi
- name: Attempt merge
id: merge
if: steps.check.outputs.has_updates == 'true'
run: |
# Files that should always keep our version (ours strategy)
OURS_FILES=(
"codex-rs/common/src/model_presets.rs"
)
if git merge upstream/main --no-edit; then
echo "status=success" >> $GITHUB_OUTPUT
git push origin main
else
echo "Merge conflict detected, attempting auto-resolution..."
# Get list of conflicted files
CONFLICTED=$(git diff --name-only --diff-filter=U)
UNRESOLVED=""
for file in $CONFLICTED; do
KEEP_OURS=false
for ours_file in "${OURS_FILES[@]}"; do
if [ "$file" = "$ours_file" ]; then
KEEP_OURS=true
break
fi
done
if [ "$KEEP_OURS" = true ]; then
echo "Auto-resolving conflict in $file (keeping ours)"
git checkout --ours "$file"
git add "$file"
else
UNRESOLVED="$UNRESOLVED $file"
fi
done
# Check if all conflicts are resolved
REMAINING=$(git diff --name-only --diff-filter=U)
if [ -z "$REMAINING" ]; then
echo "All conflicts auto-resolved"
git commit --no-edit
echo "status=success" >> $GITHUB_OUTPUT
git push origin main
else
echo "Unresolved conflicts remain: $REMAINING"
echo "status=conflict" >> $GITHUB_OUTPUT
git merge --abort
fi
fi
- name: Create PR on conflict
if: steps.merge.outputs.status == 'conflict'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="sync/upstream-$(date +%Y-%m-%d)"
git checkout -b "$BRANCH"
git merge upstream/main --no-commit || true
git add -A
git commit -m "chore: sync upstream (conflicts need resolution)" || true
git push -u origin "$BRANCH" --force
# Check if PR already exists
EXISTING_PR=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number')
if [ -z "$EXISTING_PR" ]; then
gh pr create \
--title "🔄 Sync upstream $(date +%Y-%m-%d) - CONFLICTS" \
--body "自动同步上游更新时发现冲突,需要手动解决。
## 冲突文件
请检查并解决以下冲突后合并此 PR。
---
*This PR was automatically created by the sync-upstream workflow.*" \
--head "$BRANCH" \
--base main
else
echo "PR #$EXISTING_PR already exists for branch $BRANCH"
fi
- name: Trigger release on success
if: steps.merge.outputs.status == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run 88code-release.yml --repo ${{ github.repository }}