From 1db08b1e9b06437635ec58272b4e1da4c960fdac Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 14 Jul 2025 14:13:15 +0200 Subject: [PATCH] feat: add Gitea workflows for selective GitHub mirroring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add three different approaches for mirroring to GitHub - Approach 1: Filter out sensitive files on a separate branch - Approach 2: Use git archive with .gitattributes exclusions - Approach 3: Use rsync for flexible file filtering - Add exclusion lists for sensitive files and directories - Protect production configs, environment files, and private data This allows maintaining a public GitHub mirror while keeping sensitive configuration and data private on the Gitea instance. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .gitattributes-github | 12 ++++++ .gitea/workflows/mirror-github-archive.yml | 39 ++++++++++++++++++ .gitea/workflows/mirror-github-rsync.yml | 42 +++++++++++++++++++ .gitea/workflows/mirror-to-github.yml | 48 ++++++++++++++++++++++ .github-mirror-exclude | 20 +++++++++ 5 files changed, 161 insertions(+) create mode 100644 .gitattributes-github create mode 100644 .gitea/workflows/mirror-github-archive.yml create mode 100644 .gitea/workflows/mirror-github-rsync.yml create mode 100644 .gitea/workflows/mirror-to-github.yml create mode 100644 .github-mirror-exclude diff --git a/.gitattributes-github b/.gitattributes-github new file mode 100644 index 0000000..9da591d --- /dev/null +++ b/.gitattributes-github @@ -0,0 +1,12 @@ +# Files to exclude from GitHub mirror +.env* export-ignore +docker-compose.prod.yml export-ignore +.claudedocs/ export-ignore +backend/data/ export-ignore +backend/storage/ export-ignore +backend/.env* export-ignore +frontend/.env* export-ignore +secrets/ export-ignore +*.key export-ignore +*.pem export-ignore +.gitea/ export-ignore \ No newline at end of file diff --git a/.gitea/workflows/mirror-github-archive.yml b/.gitea/workflows/mirror-github-archive.yml new file mode 100644 index 0000000..73c5bbf --- /dev/null +++ b/.gitea/workflows/mirror-github-archive.yml @@ -0,0 +1,39 @@ +name: Mirror to GitHub (Archive Method) + +on: + push: + branches: + - main + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Mirror using git archive + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Configure git + git config --global user.name "Gitea Mirror Bot" + git config --global user.email "bot@noreply.gitea.local" + + # Copy gitattributes + cp .gitattributes-github .gitattributes + + # Create archive excluding files + git archive --format=tar HEAD | tar -x -C /tmp/export + + # Initialize new repo in export directory + cd /tmp/export + git init + git add . + git commit -m "Mirror from Gitea: $(date '+%Y-%m-%d %H:%M:%S')" + + # Push to GitHub + git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git + git push -f origin main \ No newline at end of file diff --git a/.gitea/workflows/mirror-github-rsync.yml b/.gitea/workflows/mirror-github-rsync.yml new file mode 100644 index 0000000..d8f0848 --- /dev/null +++ b/.gitea/workflows/mirror-github-rsync.yml @@ -0,0 +1,42 @@ +name: Mirror to GitHub (Rsync Method) + +on: + push: + branches: + - main + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Prepare mirror directory + run: | + # Create mirror directory + mkdir -p /tmp/github-mirror + + # Use rsync to copy files, excluding sensitive ones + rsync -av --exclude-from='.github-mirror-exclude' ./ /tmp/github-mirror/ + + - name: Push to GitHub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd /tmp/github-mirror + + # Initialize git repo + git init + git config user.name "Gitea Mirror Bot" + git config user.email "bot@noreply.gitea.local" + + # Add all files and commit + git add . + git commit -m "Mirror from Gitea: $(git --git-dir=$GITHUB_WORKSPACE/.git log -1 --format='%h %s')" + + # Push to GitHub + git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git + git push -f origin main \ No newline at end of file diff --git a/.gitea/workflows/mirror-to-github.yml b/.gitea/workflows/mirror-to-github.yml new file mode 100644 index 0000000..56ab409 --- /dev/null +++ b/.gitea/workflows/mirror-to-github.yml @@ -0,0 +1,48 @@ +name: Mirror to GitHub + +on: + push: + branches: + - main + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Full history needed for mirroring + + - name: Setup Git + run: | + git config --global user.name "Gitea Mirror Bot" + git config --global user.email "bot@noreply.gitea.local" + + - name: Create filtered branch + run: | + # Create a new branch for GitHub + git checkout -b github-mirror + + # Remove sensitive files/directories + # Example: Remove .env files, private configs, etc. + 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 + + # Commit the changes + git commit -m "Remove sensitive files for GitHub mirror" || true + + - name: Push to GitHub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Add GitHub remote + git remote add github https://x-access-token:${GITHUB_TOKEN}@github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git + + # Force push the filtered branch to GitHub main + git push github github-mirror:main --force \ No newline at end of file diff --git a/.github-mirror-exclude b/.github-mirror-exclude new file mode 100644 index 0000000..9739c8f --- /dev/null +++ b/.github-mirror-exclude @@ -0,0 +1,20 @@ +# Exclude patterns for GitHub mirror +.env +.env.* +.env* +docker-compose.prod.yml +docker-compose.traefik.yml +.claudedocs/ +backend/data/ +backend/storage/ +backend/.env* +frontend/.env* +secrets/ +*.key +*.pem +.gitea/ +node_modules/ +dist/ +build/ +*.log +.DS_Store \ No newline at end of file