Skip to content

Commit

Permalink
Update mirror_repo.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Supernova3339 authored Jan 7, 2025
1 parent 37eeab8 commit e7acb9c
Showing 1 changed file with 37 additions and 50 deletions.
87 changes: 37 additions & 50 deletions .github/workflows/mirror_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,53 @@ on:
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

- name: Configure Git
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
- name: Fetch all branches
run: |
git fetch --all
- name: Set up mirror remote
run: |
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 fetch mirror --prune
- name: Process each branch
run: |
for branch in $(git branch -r | grep -v 'origin/HEAD' | sed 's/origin\///'); do
echo "Processing branch: $branch"
git checkout $branch
echo "Processing .mirrorignore (if exists)..."
if [ -f ".mirrorignore" ]; then
while IFS= read -r pattern || [ -n "$pattern" ]; do
[[ $pattern =~ ^[[:space:]]*$ || $pattern =~ ^# ]] && continue
echo "Removing files matching pattern: $pattern"
git rm -rf --cached "$pattern" 2>/dev/null || true
done < ".mirrorignore"
fi
echo "Removing mirror workflow files..."
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
git commit -m "Mirror sync: Applied .mirrorignore filters" || true
git push mirror $branch:$branch --force
done
- name: Final cleanup
run: |
git reset --hard
git clean -fd
env:
GITHUB_TOKEN: ${{ secrets.MIRROR_PAT }}

0 comments on commit e7acb9c

Please sign in to comment.