name: Mirror to GitHub on: push: branches: - main workflow_dispatch: # Allow manual triggering jobs: mirror: runs-on: ubuntu-latest steps: - name: Checkout repository with full history uses: actions/checkout@v3 with: fetch-depth: 0 # Full history needed for finding the commit - name: Setup Git run: | git config --global user.name "the-luap" git config --global user.email "paul-nothaft@hotmail.de" - name: Debug - Show current branch and status run: | echo "Current branch:" git branch -a echo "Git status:" git status echo "Remote info:" git remote -v echo "Checking target commit exists:" git show --oneline 7aca927937 || echo "Target commit not found!" - name: Create filtered history from specific commit run: | TARGET_COMMIT="7aca927937" # Verify the target commit exists if ! git cat-file -e $TARGET_COMMIT^{commit}; then echo "ERROR: Target commit $TARGET_COMMIT does not exist!" exit 1 fi echo "✅ Target commit found: $(git log --oneline -1 $TARGET_COMMIT)" # Clean up any existing github-mirror branch git branch -D github-mirror || true # Create a new branch starting from the target commit git checkout -b github-mirror $TARGET_COMMIT echo "Created github-mirror branch from commit $TARGET_COMMIT" echo "Current commit: $(git log --oneline -1)" # Get all commits from target commit to current main (excluding merge commits) echo "Getting non-merge commits from $TARGET_COMMIT to main..." COMMITS_TO_APPLY=$(git rev-list --reverse --no-merges $TARGET_COMMIT..main) if [ -n "$COMMITS_TO_APPLY" ]; then echo "Non-merge commits to apply:" for commit in $COMMITS_TO_APPLY; do git log --oneline -1 $commit done echo "" # Apply all non-merge commits since the target commit for commit in $COMMITS_TO_APPLY; do echo "Applying commit: $(git log --oneline -1 $commit)" if git cherry-pick $commit; then echo "✅ Successfully applied $commit" else echo "⚠️ Cherry-pick failed for $commit, trying to resolve..." # Check if there are conflicts if git status --porcelain | grep -q "^UU\|^AA\|^DD"; then echo "📝 Conflicts detected, trying to auto-resolve..." # Try to resolve by taking the incoming changes git add -A if git cherry-pick --continue; then echo "✅ Resolved conflicts and continued" else echo "❌ Could not resolve conflicts, skipping commit $commit" git cherry-pick --abort continue fi else echo "❌ Cherry-pick failed for other reasons, skipping commit $commit" git cherry-pick --abort continue fi fi done echo "✅ Finished applying commits" else echo "✅ No non-merge commits to apply - target commit is up to date with main" fi # Show what merge commits were skipped MERGE_COMMITS=$(git rev-list --merges $TARGET_COMMIT..main) if [ -n "$MERGE_COMMITS" ]; then echo "" echo "📋 Merge commits that were skipped:" for commit in $MERGE_COMMITS; do git log --oneline -1 $commit done fi - name: Remove sensitive files and directories run: | # Switch to the github-mirror branch git checkout github-mirror echo "Current files before cleanup:" ls -la | head -10 || true echo "..." # Remove sensitive files/directories if they exist echo "Removing sensitive files..." rm -rf .env* || true rm -rf backend/.env* || true rm -rf frontend/.env* || true rm -rf docker-compose.prod.yml || true rm -rf .claudedocs/ || true rm -rf backend/data/ || true rm -rf backend/storage/ || true rm -rf .gitea/ || true rm -rf scripts/install-gitea-runner.sh || true rm -rf .drone* || true rm -rf .github-mirror-exclude || true rm -rf .gitattributes-github || true rm -rf photo-sharing-prd.md || true rm -rf CLAUDE.md || true rm -rf PRODUCTION_DEPLOYMENT_GUIDE.md || true rm -rf logs/ || true rm -rf frontend/.claudedocs/ || true rm -rf test-maintenance.sh || true rm -rf storage/ || true echo "Sensitive files removal completed" # Add and commit the cleanup if there are changes git add -A if ! git diff --cached --quiet; then git commit -m "chore: remove sensitive files for GitHub mirror" echo "✅ Committed cleanup of sensitive files" else echo "✅ No sensitive files to remove" fi echo "Final file structure (top level):" ls -la | head -10 || true - name: Verify clean history run: | git checkout github-mirror echo "=== Final branch status ===" echo "Total commits in github-mirror branch:" git rev-list --count github-mirror echo "" echo "Commit history (last 10):" git log --oneline -10 echo "" echo "Branch comparison with main:" echo "Non-merge commits in main not in github-mirror:" git log --oneline --no-merges main..github-mirror || echo "None" echo "Non-merge commits in github-mirror not in main:" git log --oneline --no-merges github-mirror..main || echo "None" - name: Check GitHub token env: GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }} run: | if [ -z "$GITHUBTOKEN" ]; then echo "ERROR: GITHUBTOKEN secret is not set!" exit 1 else echo "GitHub token is available (length: ${#GITHUBTOKEN})" fi - name: Push to GitHub env: GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }} run: | # Switch to github-mirror branch git checkout github-mirror # Remove existing github remote if it exists git remote remove github || true # Add GitHub remote git remote add github https://x-access-token:${GITHUBTOKEN}@github.com/the-luap/picpeak.git # Verify remote was added echo "GitHub remote added:" git remote -v # Force push the filtered branch to GitHub main echo "Pushing filtered history to GitHub..." git push github github-mirror:main --force echo "✅ Push completed successfully!" - name: Workflow completed run: | echo "✅ Mirror to GitHub workflow completed successfully!" echo "📊 History starts from commit: 7aca927937" echo "🔍 Check https://github.com/the-luap/picpeak to verify the mirror" echo "📈 Total commits pushed: $(git rev-list --count github-mirror)" echo "🔀 Note: Merge commits were automatically filtered out"