π Sync all branches with main workflow (6Kmfi6HP/EDtunnel)
The π Sync all branches with main workflow from 6Kmfi6HP/EDtunnel, explained and optimized by Latchkey.
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the π Sync all branches with main workflow from the 6Kmfi6HP/EDtunnel repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: "π Sync all branches with main"
on:
workflow_dispatch:
jobs:
sync_branches:
runs-on: ubuntu-latest
name: "π Sync branches with main"
env:
EMAIL: ${{ secrets.GH_EMAIL }}
NAME: ${{ secrets.GH_USERNAME }}
TOKEN: ${{ secrets.TOKEN }}
REMOTE_NAME: origin
BRANCH_BASE_NAME: proxyip
BRANCH_COUNT: 200
steps:
- name: π Set up Git config
run: |
git config --global user.email "${{ env.EMAIL }}"
git config --global user.name "${{ env.NAME }}"
- name: π₯ Clone repository
run: |
git clone https:///${{ env.TOKEN }}@github.com/${{github.repository}}.git
cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
- name: π Sync and push branches
run: |
cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
git checkout main
git pull ${REMOTE_NAME} main
for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do
branch_name="${{ env.BRANCH_BASE_NAME }}${i}"
git checkout $branch_name
git merge main --no-edit
git push ${REMOTE_NAME} $branch_name
git checkout main
done
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: "π Sync all branches with main" on: workflow_dispatch: jobs: sync_branches: timeout-minutes: 30 runs-on: latchkey-small name: "π Sync branches with main" env: EMAIL: ${{ secrets.GH_EMAIL }} NAME: ${{ secrets.GH_USERNAME }} TOKEN: ${{ secrets.TOKEN }} REMOTE_NAME: origin BRANCH_BASE_NAME: proxyip BRANCH_COUNT: 200 steps: - name: π Set up Git config run: | git config --global user.email "${{ env.EMAIL }}" git config --global user.name "${{ env.NAME }}" - name: π₯ Clone repository run: | git clone https:///${{ env.TOKEN }}@github.com/${{github.repository}}.git cd $(echo ${{github.repository}} | awk -F'/' '{print $2}') - name: π Sync and push branches run: | cd $(echo ${{github.repository}} | awk -F'/' '{print $2}') git checkout main git pull ${REMOTE_NAME} main for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do branch_name="${{ env.BRANCH_BASE_NAME }}${i}" git checkout $branch_name git merge main --no-edit git push ${REMOTE_NAME} $branch_name git checkout main done
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.