Skip to content

Commit 8105b46

Browse files
authored
Merge pull request #11 from ibelem/main
Add github actions for syncing upstream code
2 parents 9444dc0 + 3a97287 commit 8105b46

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Sync upstream
2+
3+
on:
4+
schedule:
5+
- cron: '0 */6 * * *' # Every 6 hours, at minute 0
6+
workflow_dispatch: # allow manual trigger
7+
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
# Only run on forks to prevent running on the original repo
12+
if: github.event.repository.fork
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
# Fetch full history for proper merging
19+
fetch-depth: 0
20+
# Use a token with appropriate permissions
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Set up Git
24+
run: |
25+
git config --global user.name 'github-actions[bot]'
26+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
27+
28+
- name: Add upstream and sync
29+
run: |
30+
git remote add upstream https://github.com/webmachinelearning/webnn-docs.git
31+
git fetch upstream
32+
33+
# Check if there are actually changes to merge
34+
if git merge-base --is-ancestor upstream/main HEAD; then
35+
echo "Already up to date"
36+
exit 0
37+
fi
38+
39+
git checkout main
40+
41+
# Try to merge, exit gracefully if there are conflicts
42+
if ! git merge upstream/main --no-edit; then
43+
echo "Merge conflicts detected. Manual intervention required."
44+
git merge --abort
45+
exit 1
46+
fi
47+
48+
git push origin main
49+
50+
- name: Clean up
51+
if: always()
52+
run: |
53+
if git remote | grep -q upstream; then
54+
git remote remove upstream
55+
fi
56+
57+
- name: Create issue on conflict
58+
if: failure()
59+
uses: actions/github-script@v7
60+
with:
61+
script: |
62+
github.rest.issues.create({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
title: 'Upstream sync failed due to merge conflicts',
66+
body: `The automatic upstream sync failed due to merge conflicts.
67+
68+
Please manually resolve the conflicts by:
69+
1. \`git remote add upstream https://github.com/webmachinelearning/webnn-docs.git\`
70+
2. \`git fetch upstream\`
71+
3. \`git merge upstream/main\`
72+
4. Resolve conflicts and commit
73+
5. \`git push origin main\`
74+
75+
Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
76+
})

0 commit comments

Comments
 (0)