workflows/sync-default-branches: speed up with partial clone.

Let's avoid doing a full clone and instead use a partial clone and a
`git ls-remote` to get the target SHA and just push that without needing
 to fully fetch it.
This commit is contained in:
Mike McQuaid 2025-06-24 11:46:49 +01:00
parent d661cffc1f
commit f83c5ee2ed
No known key found for this signature in database

View File

@ -45,19 +45,20 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with: with:
fetch-depth: 0 fetch-depth: 1
persist-credentials: true persist-credentials: true
- name: Setup target branch - name: Get target SHA
id: sha
run: | run: |
git checkout "${TARGET_BRANCH}" || git checkout -b "${TARGET_BRANCH}" TARGET_SHA=$(git ls-remote origin "refs/heads/${SOURCE_BRANCH}" | cut -f1)
git reset --hard "origin/${SOURCE_BRANCH}" echo "target=${TARGET_SHA}" >> "$GITHUB_OUTPUT"
env: env:
SOURCE_BRANCH: ${{ steps.branches.outputs.source }} SOURCE_BRANCH: ${{ steps.branches.outputs.source }}
TARGET_BRANCH: ${{ steps.branches.outputs.target }}
- name: Push target branch - name: Push target branch
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: git push origin "${TARGET_BRANCH}" --force-with-lease run: git push origin "${TARGET_SHA}:refs/heads/${TARGET_BRANCH}" --force-with-lease
env: env:
TARGET_SHA: ${{ steps.sha.outputs.target }}
TARGET_BRANCH: ${{ steps.branches.outputs.target }} TARGET_BRANCH: ${{ steps.branches.outputs.target }}