Skip to content

Mirror All Branches to Organization #7

Mirror All Branches to Organization

Mirror All Branches to Organization #7

Workflow file for this run

name: Mirror All Branches to Organization
on:
push:
branches:
- '**'
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.MIRROR_PAT }}
- name: Process mirror ignore and sync
run: |
# Configure Git
git config --global user.name "${{ github.repository_owner }}"
git config --global user.email "${{ github.repository_owner }}@users.noreply.github.com"
# Clean working directory and remove untracked files
git reset --hard
git clean -fd
# Create temporary branch for clean mirror
TEMP_BRANCH="temp-mirror-$(date +%s)"
git checkout -b $TEMP_BRANCH
# Process .mirrorignore if it exists
if [ -f ".mirrorignore" ]; then
echo "Processing .mirrorignore file..."
while IFS= read -r pattern || [ -n "$pattern" ]; do
# Skip empty lines and comments
[[ $pattern =~ ^[[:space:]]*$ || $pattern =~ ^# ]] && continue
# Remove the files that match the pattern
echo "Removing files matching pattern: $pattern"
git rm -rf --cached "$pattern" 2>/dev/null || true
done < ".mirrorignore"
else
echo "No .mirrorignore file found, proceeding with full mirror"
fi
# Always ignore the mirror workflow itself
echo "Removing mirror workflow..."
git rm -rf --cached .github/workflows/mirror.yml 2>/dev/null || true
git rm -rf --cached .github/workflows/mirror_repo.yml 2>/dev/null || true
# Commit changes if any files were removed
git commit -m "Mirror sync: Applied .mirrorignore filters" || true
# Set up mirror remote
git remote remove mirror 2>/dev/null || true
git remote add mirror "https://${{ github.repository_owner }}:${{ secrets.MIRROR_PAT }}@github.com/GD-LevelReqBot/gd-levelreqbot.git"
# Push to mirror repository
echo "Pushing filtered content to mirror..."
git push mirror $TEMP_BRANCH:${GITHUB_REF#refs/heads/} --force
# Clean up with force
git checkout ${GITHUB_REF#refs/heads/} --force
git branch -D $TEMP_BRANCH
# Final cleanup of any leftover files
git reset --hard
git clean -fd
env:
GITHUB_TOKEN: ${{ secrets.MIRROR_PAT }}