Weekly Template Sync #23
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: Weekly Template Sync | |
| on: | |
| schedule: | |
| # Run every Thursday at 9:00 AM UTC | |
| - cron: '0 9 * * 4' | |
| workflow_dispatch: # Allow manual triggering | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| template-sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Full history needed for merge | |
| - name: Check and sync with template | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -e | |
| TEMPLATE_REPO="https://github.com/mloda-ai/mloda-plugin-template.git" | |
| TEMPLATE_BRANCH="main" | |
| TARGET_BRANCH="main" | |
| SYNC_BRANCH="chore/template-sync-$(date +%Y-%m-%d)" | |
| echo "Adding template remote..." | |
| git remote add template "$TEMPLATE_REPO" | |
| git fetch template | |
| TEMPLATE_HEAD=$(git rev-parse template/$TEMPLATE_BRANCH) | |
| echo "Template HEAD: $TEMPLATE_HEAD" | |
| # Check if template is already merged | |
| if git merge-base --is-ancestor "$TEMPLATE_HEAD" origin/$TARGET_BRANCH; then | |
| echo "✅ Already in sync with template. Nothing to do." | |
| exit 0 | |
| fi | |
| echo "⚠️ Template has new commits. Creating sync PR..." | |
| # Check if a sync PR already exists | |
| EXISTING_PR=$(gh pr list --head "chore/template-sync-" --state open --json number --jq '.[0].number // empty') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "ℹ️ Sync PR #$EXISTING_PR already exists. Skipping." | |
| exit 0 | |
| fi | |
| # Configure git for commit | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Create sync branch from main | |
| git checkout -b "$SYNC_BRANCH" origin/$TARGET_BRANCH | |
| # Merge template changes | |
| if ! git merge template/$TEMPLATE_BRANCH --no-edit -m "chore: sync with template repository"; then | |
| echo "❌ Merge conflict detected. Manual resolution required." | |
| echo "Run locally:" | |
| echo " git fetch template" | |
| echo " git merge template/$TEMPLATE_BRANCH" | |
| exit 1 | |
| fi | |
| # Push the branch | |
| git push origin "$SYNC_BRANCH" | |
| # Get list of new commits for PR body | |
| NEW_COMMITS=$(git log --oneline origin/$TARGET_BRANCH..template/$TEMPLATE_BRANCH) | |
| # Create PR | |
| gh pr create \ | |
| --title "chore: sync with template repository" \ | |
| --body "$(cat <<EOF | |
| This PR syncs changes from the template repository. | |
| ## New commits from template | |
| \`\`\` | |
| $NEW_COMMITS | |
| \`\`\` | |
| ## Template repository | |
| $TEMPLATE_REPO | |
| --- | |
| *This PR was automatically created by the template-sync workflow.* | |
| EOF | |
| )" \ | |
| --base "$TARGET_BRANCH" \ | |
| --head "$SYNC_BRANCH" | |
| echo "✅ Sync PR created successfully." |