name: Push to subrepositories
on:
  push:
    branches:
      - 'main'
jobs:
  push:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        # fetch full Git history, otherwise push-subrepos.sh would fail due to not being able to
        # split the git subtree.
        fetch-depth: 0
    - name: 'Push recent commits to subrepositories'
      env:
        ACCESS_TOKEN: ${{ secrets.HEXOPS_MACH_PUSH_SUBREPOS }}
      run: |
        git config user.name 'Repository synchronization automation'
        git config user.email 'stephen@hexops.com'
        # See https://github.community/t/automating-push-to-public-repo/17742/12
        git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
        ./dev/push-subrepos.sh
