Skip to content

Sync Upstream

Sync Upstream #26

Workflow file for this run

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