feat: update GitHub mirror workflow to start history from specific commit
Mirror to GitHub / mirror (push) Failing after 34s
Test and Lint / backend-test (push) Has started running
Test and Lint / frontend-test (push) Has been cancelled
continuous-integration/drone/push Build is failing

- 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
This commit is contained in:
2025-07-20 22:08:53 +02:00
parent 481545c37b
commit a1cf6a1156
+89 -73
View File
@@ -10,10 +10,10 @@ jobs:
mirror: mirror:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository with full history
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0 # Full history needed for commit filtering fetch-depth: 0 # Full history needed for finding the commit
- name: Setup Git - name: Setup Git
run: | run: |
@@ -28,91 +28,109 @@ jobs:
git status git status
echo "Remote info:" echo "Remote info:"
git remote -v git remote -v
echo "Target commit exists:" echo "Checking target commit exists:"
git show --oneline cc7ad4b2bc || echo "Commit not found!" git show --oneline 7aca927937 || echo "Target commit not found!"
- name: Create filtered history from specific commit - name: Create filtered history from specific commit
run: | run: |
# Clean up any existing github-mirror branch TARGET_COMMIT="7aca927937"
git branch -D github-mirror || true
# Verify the target commit exists # Verify the target commit exists
if ! git rev-parse --verify cc7ad4b2bc >/dev/null 2>&1; then if ! git cat-file -e $TARGET_COMMIT^{commit}; then
echo "ERROR: Commit cc7ad4b2bc not found!" echo "ERROR: Target commit $TARGET_COMMIT does not exist!"
exit 1 exit 1
fi fi
echo "Creating filtered history starting from commit cc7ad4b2bc..." 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 # Create a new branch starting from the target commit
git checkout -b github-mirror cc7ad4b2bc git checkout -b github-mirror $TARGET_COMMIT
# Get all commits from the target commit to HEAD on main echo "Created github-mirror branch from commit $TARGET_COMMIT"
echo "Rebasing commits from cc7ad4b2bc to main..." echo "Current commit: $(git log --oneline -1)"
git rebase --onto github-mirror cc7ad4b2bc main --exec 'echo "Processing commit: $(git log --oneline -1)"'
# Alternative approach if rebase fails - cherry-pick all commits # Get all commits from target commit to current main
if [ $? -ne 0 ]; then echo "Getting commits from $TARGET_COMMIT to main..."
echo "Rebase failed, trying cherry-pick approach..." COMMITS_TO_APPLY=$(git rev-list --reverse $TARGET_COMMIT..main)
git rebase --abort || true
git checkout github-mirror if [ -n "$COMMITS_TO_APPLY" ]; then
echo "Commits to apply:"
git log --oneline $TARGET_COMMIT..main
# Get list of commits from target commit to main (excluding the target commit itself) # Apply all commits since the target commit
COMMITS=$(git rev-list --reverse cc7ad4b2bc..main) for commit in $COMMITS_TO_APPLY; do
echo "Applying commit: $(git log --oneline -1 $commit)"
if [ -n "$COMMITS" ]; then git cherry-pick $commit || {
echo "Cherry-picking commits:" echo "Cherry-pick failed, trying to resolve..."
echo "$COMMITS" # If cherry-pick fails, try to continue with merge strategy
git cherry-pick --continue || git cherry-pick --skip || {
for commit in $COMMITS; do echo "Failed to apply commit $commit, skipping..."
echo "Cherry-picking: $(git log --oneline -1 $commit)" git cherry-pick --abort
git cherry-pick $commit continue
done }
else }
echo "No commits to cherry-pick (already up to date)" done
fi else
echo "No commits to apply - target commit is up to date with main"
fi fi
echo "Filtered branch created successfully!"
git log --oneline -10
- name: Remove sensitive files from mirror - name: Remove sensitive files and directories
run: | run: |
echo "Removing sensitive files and directories from GitHub mirror..."
# Switch to the github-mirror branch # Switch to the github-mirror branch
git checkout github-mirror git checkout github-mirror
# Remove sensitive files/directories (same as before but now applied to filtered history) echo "Current files before cleanup:"
git rm -r --cached .env* || true find . -name ".*" -o -name "*" | head -20
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 # Remove sensitive files/directories if they exist
if [[ -n $(git status --porcelain) ]]; then rm -rf .env* || true
echo "Files were removed, committing changes..." rm -rf backend/.env* || true
git commit -m "Remove sensitive files for GitHub mirror" 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 else
echo "No sensitive files found to remove" echo "No sensitive files to remove"
fi fi
echo "Sensitive file removal completed!" 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 - name: Check GitHub token
env: env:
@@ -129,6 +147,9 @@ jobs:
env: env:
GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }} GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
run: | run: |
# Switch to github-mirror branch
git checkout github-mirror
# Remove existing github remote if it exists # Remove existing github remote if it exists
git remote remove github || true git remote remove github || true
@@ -139,19 +160,14 @@ jobs:
echo "GitHub remote added:" echo "GitHub remote added:"
git remote -v 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 # Force push the filtered branch to GitHub main
echo "Pushing filtered history to GitHub..." echo "Pushing filtered history to GitHub..."
git push github github-mirror:main --force git push github github-mirror:main --force
echo "Push completed successfully!" echo "Push completed successfully!"
- name: Workflow completed - name: Workflow completed
run: | run: |
echo "✅ Mirror to GitHub workflow completed successfully!" echo "✅ Mirror to GitHub workflow completed successfully!"
echo "📊 History starts from commit: cc7ad4b2bc" echo "📊 History starts from commit: 7aca927937"
echo "🗑️ Sensitive files have been removed from mirror" echo "🔍 Check https://github.com/the-luap/picpeak to verify the mirror"
echo "🔗 Check https://github.com/the-luap/picpeak to verify the mirror." echo "📈 Total commits pushed: $(git rev-list --count github-mirror)"
echo "📈 Total commits in mirror: $(git rev-list --count github-mirror)"