forked from typst/typst
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (135 loc) · 5.13 KB
/
sync-upstream.yml
File metadata and controls
162 lines (135 loc) · 5.13 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Sync Upstream
# Runs weekly on Sunday at midnight UTC, or manually
on:
schedule:
- cron: '0 0 * * *' # Daily at 00:00 UTC
workflow_dispatch: # Allow manual trigger
jobs:
sync-main:
name: Sync main with upstream
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
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 remote
run: git remote add upstream https://github.com/typst/typst.git
- name: Fetch upstream
run: git fetch upstream
- name: Check for upstream changes
id: check-changes
run: |
BEHIND=$(git rev-list --count HEAD..upstream/main)
echo "commits_behind=$BEHIND" >> $GITHUB_OUTPUT
if [ "$BEHIND" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Found $BEHIND new commits from upstream"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "Already up to date with upstream"
fi
- name: Merge upstream into main
if: steps.check-changes.outputs.has_changes == 'true'
run: |
git checkout main
git merge upstream/main --no-edit
git push origin main
- name: Check feature branch for conflicts
if: steps.check-changes.outputs.has_changes == 'true'
id: check-feature
run: |
git checkout feature/text-flow
# Try a test merge to detect conflicts
if git merge main --no-commit --no-ff 2>/dev/null; then
echo "conflict=false" >> $GITHUB_OUTPUT
git merge --abort 2>/dev/null || true
else
echo "conflict=true" >> $GITHUB_OUTPUT
git merge --abort 2>/dev/null || true
fi
- name: Create PR for feature branch update (no conflicts)
if: steps.check-changes.outputs.has_changes == 'true' && steps.check-feature.outputs.conflict == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create a temporary branch with the merge
git checkout feature/text-flow
BRANCH_NAME="sync/feature-text-flow-$(date +%Y%m%d)"
git checkout -b "$BRANCH_NAME"
git merge main --no-edit
git push origin "$BRANCH_NAME"
# Create PR
gh pr create \
--base feature/text-flow \
--head "$BRANCH_NAME" \
--title "Sync feature/text-flow with upstream ($(date +%Y-%m-%d))" \
--body "$(cat <<'EOF'
## Automated Upstream Sync
This PR merges the latest upstream changes into the feature/text-flow branch.
**Commits from upstream:** ${{ steps.check-changes.outputs.commits_behind }}
### Review Checklist
- [ ] Tests pass
- [ ] No regressions in text-flow feature
- [ ] Build succeeds
---
*This PR was automatically created by the sync-upstream workflow.*
EOF
)"
- name: Create issue for conflicts
if: steps.check-changes.outputs.has_changes == 'true' && steps.check-feature.outputs.conflict == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get list of conflicting files
git checkout feature/text-flow
CONFLICTS=$(git merge main --no-commit 2>&1 | grep "CONFLICT" || echo "Unable to determine specific conflicts")
git merge --abort 2>/dev/null || true
gh issue create \
--title "Manual merge required: upstream sync conflicts ($(date +%Y-%m-%d))" \
--body "$(cat <<EOF
## Upstream Sync Conflict
The automated sync found **${{ steps.check-changes.outputs.commits_behind }}** new commits from upstream, but there are merge conflicts with the \`feature/text-flow\` branch.
### Conflicts Detected
\`\`\`
$CONFLICTS
\`\`\`
### Manual Resolution Steps
\`\`\`bash
cd /Users/jrhayward/repositories/typst-fork
git fetch origin
git fetch upstream
# Update main first
git checkout main
git pull origin main
# Now merge into feature branch
git checkout feature/text-flow
git merge main
# Resolve conflicts, then:
git add .
git commit
git push origin feature/text-flow
\`\`\`
---
*This issue was automatically created by the sync-upstream workflow.*
EOF
)"
notify-summary:
name: Summary
runs-on: ubuntu-latest
needs: sync-main
if: always()
steps:
- name: Workflow summary
run: |
echo "## Upstream Sync Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the Actions tab for details." >> $GITHUB_STEP_SUMMARY