BobAi 7d2fe8bacd Create comprehensive GitHub template system with auto-update
🚀 Complete GitHub Template System:
• GitHub Actions workflows (CI, release, template-sync)
• Auto-update system integration for all projects
• Privacy-first approach (private repos by default)
• One-command setup script for easy migration
• Template synchronization for keeping repos updated

🔧 Components Added:
• .github/workflows/ - Complete CI/CD pipeline
• scripts/setup-github-template.py - Template setup automation
• scripts/quick-github-setup.sh - One-command project setup
• Comprehensive documentation and security guidelines

🔒 Privacy & Security:
• Private repositories by default
• Minimal permissions for workflows
• Local-only data processing
• No telemetry or tracking
• User consent for all operations

🎯 Perfect for Gitea → GitHub migration:
• Preserves auto-update functionality
• Professional development workflows
• Easy team collaboration
• Automated release management

Usage: ./scripts/quick-github-setup.sh . -o username -n project-name
2025-08-15 15:37:16 +10:00

156 lines
5.5 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Template Synchronization
on:
schedule:
# Run weekly on Sundays at 2 AM UTC
- cron: '0 2 * * 0'
workflow_dispatch:
inputs:
force_sync:
description: 'Force sync even if no changes detected'
required: false
type: boolean
default: false
jobs:
sync-template:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout current repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Check if repository was created from template
id: template_check
run: |
# Check if this repo has template metadata
TEMPLATE_REPO=$(gh api repos/${{ github.repository }} --jq '.template_repository.full_name' 2>/dev/null || echo "")
if [ -n "$TEMPLATE_REPO" ]; then
echo "template_repo=$TEMPLATE_REPO" >> $GITHUB_OUTPUT
echo "is_template_derived=true" >> $GITHUB_OUTPUT
echo "✅ Repository created from template: $TEMPLATE_REPO"
else
echo "is_template_derived=false" >> $GITHUB_OUTPUT
echo " Repository not created from template"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch template updates
if: steps.template_check.outputs.is_template_derived == 'true'
id: fetch_updates
run: |
TEMPLATE_REPO="${{ steps.template_check.outputs.template_repo }}"
# Add template as remote
git remote add template https://github.com/$TEMPLATE_REPO.git || true
git fetch template main
# Check for changes in template files
TEMPLATE_FILES=$(git diff --name-only HEAD template/main -- .github/ scripts/ | head -20)
if [ -n "$TEMPLATE_FILES" ] || [ "${{ github.event.inputs.force_sync }}" = "true" ]; then
echo "updates_available=true" >> $GITHUB_OUTPUT
echo "template_files<<EOF" >> $GITHUB_OUTPUT
echo "$TEMPLATE_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "🔄 Template updates available"
else
echo "updates_available=false" >> $GITHUB_OUTPUT
echo "✅ No template updates needed"
fi
- name: Create update branch
if: steps.fetch_updates.outputs.updates_available == 'true'
run: |
BRANCH_NAME="template-sync-$(date +%Y%m%d-%H%M%S)"
echo "sync_branch=$BRANCH_NAME" >> $GITHUB_ENV
git checkout -b $BRANCH_NAME
# Merge template changes for specific directories only
git checkout template/main -- .github/workflows/ || true
git checkout template/main -- scripts/ || true
# Don't overwrite project-specific files
git reset HEAD -- .github/workflows/template-sync.yml || true
git checkout HEAD -- .github/workflows/template-sync.yml || true
- name: Commit template updates
if: steps.fetch_updates.outputs.updates_available == 'true'
run: |
git config user.name "Template Sync Bot"
git config user.email "noreply@github.com"
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "🔄 Sync template updates
Updated files:
${{ steps.fetch_updates.outputs.template_files }}
Source: ${{ steps.template_check.outputs.template_repo }}
Sync date: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
This is an automated template synchronization.
Review changes before merging."
git push origin ${{ env.sync_branch }}
fi
- name: Create pull request
if: steps.fetch_updates.outputs.updates_available == 'true'
run: |
gh pr create \
--title "🔄 Template Updates Available" \
--body "## Template Synchronization
This PR contains updates from the template repository.
### 📋 Changed Files:
\`\`\`
${{ steps.fetch_updates.outputs.template_files }}
\`\`\`
### 📊 What's Updated:
- GitHub Actions workflows
- Project scripts and automation
- Template-specific configurations
### ⚠️ Review Notes:
- **Carefully review** all changes before merging
- **Test workflows** in a branch if needed
- **Preserve** any project-specific customizations
- **Check** that auto-update system still works
### 🔗 Source:
Template: [${{ steps.template_check.outputs.template_repo }}](https://github.com/${{ steps.template_check.outputs.template_repo }})
Sync Date: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
---
🤖 This is an automated template synchronization. Review carefully before merging!" \
--head "${{ env.sync_branch }}" \
--base main \
--label "template-sync,automation"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
if [ "${{ steps.template_check.outputs.is_template_derived }}" = "true" ]; then
if [ "${{ steps.fetch_updates.outputs.updates_available }}" = "true" ]; then
echo "🎉 Template sync completed - PR created for review"
else
echo "✅ Template is up to date - no action needed"
fi
else
echo " Repository not created from template - skipping sync"
fi