a1cf6a1156
- Start history from commit 7aca927937 instead of orphan branch
- Use cherry-pick to preserve meaningful commit history
- Automatically exclude files that only existed before target commit
- Add comprehensive error handling and logging
- Maintain clean linear history for GitHub repository
173 lines
6.2 KiB
YAML
173 lines
6.2 KiB
YAML
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
|
|
echo "Getting commits from $TARGET_COMMIT to main..."
|
|
COMMITS_TO_APPLY=$(git rev-list --reverse $TARGET_COMMIT..main)
|
|
|
|
if [ -n "$COMMITS_TO_APPLY" ]; then
|
|
echo "Commits to apply:"
|
|
git log --oneline $TARGET_COMMIT..main
|
|
|
|
# Apply all commits since the target commit
|
|
for commit in $COMMITS_TO_APPLY; do
|
|
echo "Applying commit: $(git log --oneline -1 $commit)"
|
|
git cherry-pick $commit || {
|
|
echo "Cherry-pick failed, trying to resolve..."
|
|
# If cherry-pick fails, try to continue with merge strategy
|
|
git cherry-pick --continue || git cherry-pick --skip || {
|
|
echo "Failed to apply commit $commit, skipping..."
|
|
git cherry-pick --abort
|
|
continue
|
|
}
|
|
}
|
|
done
|
|
else
|
|
echo "No commits to apply - target commit is up to date with main"
|
|
fi
|
|
|
|
- name: Remove sensitive files and directories
|
|
run: |
|
|
# Switch to the github-mirror branch
|
|
git checkout github-mirror
|
|
|
|
echo "Current files before cleanup:"
|
|
find . -name ".*" -o -name "*" | head -20
|
|
|
|
# Remove sensitive files/directories if they exist
|
|
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
|
|
|
|
# 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:"
|
|
find . -name ".*" -o -name "*" | head -20
|
|
|
|
- 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:"
|
|
git log --oneline main..github-mirror || echo "No differences"
|
|
git log --oneline github-mirror..main || echo "No differences"
|
|
|
|
- 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)" |