-
Notifications
You must be signed in to change notification settings - Fork 3
76 lines (63 loc) · 2.45 KB
/
sync-upstream.yml
File metadata and controls
76 lines (63 loc) · 2.45 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
name: Sync upstream
on:
schedule:
- cron: '0 */6 * * *' # Every 6 hours, at minute 0
workflow_dispatch: # allow manual trigger
jobs:
sync:
runs-on: ubuntu-latest
# Only run on forks to prevent running on the original repo
if: github.event.repository.fork
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Fetch full history for proper merging
fetch-depth: 0
# Use a token with appropriate permissions
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Add upstream and sync
run: |
git remote add upstream https://github.com/webmachinelearning/webnn-docs.git
git fetch upstream
# Check if there are actually changes to merge
if git merge-base --is-ancestor upstream/main HEAD; then
echo "Already up to date"
exit 0
fi
git checkout main
# Try to merge, exit gracefully if there are conflicts
if ! git merge upstream/main --no-edit; then
echo "Merge conflicts detected. Manual intervention required."
git merge --abort
exit 1
fi
git push origin main
- name: Clean up
if: always()
run: |
if git remote | grep -q upstream; then
git remote remove upstream
fi
- name: Create issue on conflict
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Upstream sync failed due to merge conflicts',
body: `The automatic upstream sync failed due to merge conflicts.
Please manually resolve the conflicts by:
1. \`git remote add upstream https://github.com/webmachinelearning/webnn-docs.git\`
2. \`git fetch upstream\`
3. \`git merge upstream/main\`
4. Resolve conflicts and commit
5. \`git push origin main\`
Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
})