Sync upstream #175
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | |
}) |