Repository navigation
Mirror Sync #196
This file contains hidden or 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: Mirror Sync | |
| on: | |
| schedule: | |
| - cron: '0 3 * * *' # nightly at 03:00 UTC | |
| workflow_dispatch: # allow manual runs | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up SSH deploy key | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: ${{ secrets.MIRROR_DEPLOY_KEY }} | |
| - name: Sync sourceware → GitHub mirror | |
| run: | | |
| # Seed from the GitHub mirror so we only fetch the delta from sourceware | |
| git clone --mirror git@github.com:memfault/binutils-gdb.git repo.git | |
| cd repo.git | |
| # Remove the github-mirror branch so it is never overwritten by the | |
| # sourceware fetch and never accidentally pushed back to sourceware. | |
| git update-ref -d refs/heads/github-mirror || true | |
| git remote add upstream git://sourceware.org/git/binutils-gdb.git | |
| # Fetch only what changed since the last sync | |
| git fetch --prune upstream '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' | |
| # Push updates back; force-push handles any upstream rebases | |
| git remote add mirror git@github.com:memfault/binutils-gdb.git | |
| git push mirror +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/* | |
| # Prune branches deleted upstream, but preserve github-mirror | |
| git ls-remote mirror 'refs/heads/*' \ | |
| | awk '{print $2}' \ | |
| | grep -v '^refs/heads/github-mirror$' \ | |
| | while read ref; do | |
| branch="${ref#refs/heads/}" | |
| if ! git show-ref --quiet "refs/heads/$branch"; then | |
| git push mirror --delete "$branch" || true | |
| fi | |
| done | |
| # Prune tags deleted upstream | |
| git ls-remote mirror 'refs/tags/*' \ | |
| | awk '{print $2}' \ | |
| | while read ref; do | |
| if ! git show-ref --quiet "$ref"; then | |
| git push mirror --delete "${ref#refs/tags/}" || true | |
| fi | |
| done |