Sync from monorepo: 2025-01-13 05:55:21 - # Korfbal #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync to monorepo | |
on: | |
push: | |
branches: | |
- main | |
env: | |
SOURCE_BRANCH_NAME: ${{ github.ref_name }} | |
TARGET_LOCATION: apps/django_projects/korfbal | |
jobs: | |
sync_changes: | |
if: ${{ !contains(github.event.head_commit.message, 'Sync from monorepo') }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: read | |
steps: | |
# Step 1: Checkout Standalone Repo | |
- name: Checkout Standalone Repo | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
# Step 2: Sparse Checkout of Monorepo Target Directory | |
- name: Sparse Checkout of Monorepo | |
env: | |
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
# Define variables | |
TARGET_LOCATION="${{ env.TARGET_LOCATION }}" | |
echo "Cloning monorepo with sparse checkout for $TARGET_LOCATION..." | |
# Initialize a bare clone of the monorepo | |
git clone --no-checkout --depth=1 -b ${{ vars.SYNC_TARGET_BRANCH_NAME }} https://[email protected]/${{ vars.SYNC_TARGET_REPO }}.git monorepo | |
cd monorepo | |
# Enable sparse checkout and fetch only the target directory | |
git sparse-checkout init --cone | |
git sparse-checkout set $TARGET_LOCATION | |
# Checkout only the target directory | |
git checkout | |
echo "Monorepo target directory structure:" | |
ls -la $TARGET_LOCATION | |
# Step 3: Sync Files to the Target Directory | |
- name: Sync Files to Monorepo | |
run: | | |
# Ensure target directory exists | |
mkdir -p monorepo/${{ env.TARGET_LOCATION }} | |
# Exclude the monorepo/ folder so it doesn't get re-copied into itself | |
echo "Syncing files to monorepo/${{ env.TARGET_LOCATION }}/" | |
rsync -av \ | |
--delete \ | |
--exclude '.git/' \ | |
--exclude 'monorepo/' \ | |
. monorepo/${{ env.TARGET_LOCATION }} | |
# Step 4: Commit and Push Changes | |
- name: Commit and Push Changes | |
env: | |
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
cd monorepo | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add ${{ env.TARGET_LOCATION }} | |
COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
# Commit and push only if there are changes | |
if git diff --cached --exit-code; then | |
echo "No changes to commit." | |
else | |
git commit -m "Sync from korfbal: $(date +'%Y-%m-%d %H:%M:%S') - $COMMIT_MESSAGE" | |
git push https://[email protected]/${{ vars.SYNC_TARGET_REPO }}.git HEAD:${{ vars.SYNC_TARGET_BRANCH_NAME }} | |
fi |