name: Mirror to GitHub on: push: branches: - main workflow_dispatch: # Allow manual triggering jobs: mirror: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 with: fetch-depth: 0 # Full history needed for commit filtering - 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 "Target commit exists:" git show --oneline cfa29ad5cb || echo "Commit not found!" - name: Create filtered history from specific commit run: | # Clean up any existing github-mirror branch git branch -D github-mirror || true # Verify the target commit exists if ! git rev-parse --verify cfa29ad5cb >/dev/null 2>&1; then echo "ERROR: Commit cfa29ad5cb not found!" exit 1 fi echo "Creating filtered history starting from commit cfa29ad5cb..." # Create a new branch starting from the target commit git checkout -b github-mirror cfa29ad5cb # Get all commits from the target commit to HEAD on main echo "Rebasing commits from cfa29ad5cb to main..." git rebase --onto github-mirror cfa29ad5cb main --exec 'echo "Processing commit: $(git log --oneline -1)"' # Alternative approach if rebase fails - cherry-pick all commits if [ $? -ne 0 ]; then echo "Rebase failed, trying cherry-pick approach..." git rebase --abort || true git checkout github-mirror # Get list of commits from target commit to main (excluding the target commit itself) COMMITS=$(git rev-list --reverse cfa29ad5cb..main) if [ -n "$COMMITS" ]; then echo "Cherry-picking commits:" echo "$COMMITS" for commit in $COMMITS; do echo "Cherry-picking: $(git log --oneline -1 $commit)" git cherry-pick $commit done else echo "No commits to cherry-pick (already up to date)" fi fi echo "Filtered branch created successfully!" git log --oneline -10 - name: Remove sensitive files from mirror run: | echo "Removing sensitive files and directories from GitHub mirror..." # Switch to the github-mirror branch git checkout github-mirror # Remove sensitive files/directories (same as before but now applied to filtered history) git rm -r --cached .env* || true git rm -r --cached backend/.env* || true git rm -r --cached frontend/.env* || true git rm -r --cached docker-compose.prod.yml || true git rm -r --cached .claudedocs/ || true git rm -r --cached backend/data/ || true git rm -r --cached backend/storage/ || true git rm -r --cached .gitea/ || true git rm -r --cached scripts/install-gitea-runner.sh || true git rm -r --cached .drone* || true git rm -r --cached .github-mirror-exclude || true git rm -r --cached .gitattributes-github || true git rm -r --cached photo-sharing-prd.md || true git rm -r --cached CLAUDE.md || true git rm -r --cached PRODUCTION_DEPLOYMENT_GUIDE.md || true git rm -r --cached logs/ || true git rm -r --cached frontend/.claudedocs/ || true git rm -r --cached test-maintenance.sh || true git rm -r --cached storage/ || true # Check if any files were actually removed if [[ -n $(git status --porcelain) ]]; then echo "Files were removed, committing changes..." git commit -m "Remove sensitive files for GitHub mirror" else echo "No sensitive files found to remove" fi echo "Sensitive file removal completed!" - 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: | # 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 # Show what we're about to push echo "Commits to be pushed:" git log --oneline github-mirror # 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: cfa29ad5cb" echo "🗑️ Sensitive files have been removed from mirror" echo "🔗 Check https://github.com/the-luap/picpeak to verify the mirror." echo "📈 Total commits in mirror: $(git rev-list --count github-mirror)"