π² Create many branches workflow (6Kmfi6HP/EDtunnel)
The π² Create many branches workflow from 6Kmfi6HP/EDtunnel, explained and optimized by Latchkey.
A
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 π² Create many branches 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
workflow (.yml)
name: "π² Create many branches"
on:
workflow_dispatch:
jobs:
create_branches:
runs-on: ubuntu-latest
name: "π² Create and push branches"
env:
EMAIL: ${{ secrets.GH_EMAIL }}
NAME: ${{ secrets.GH_USERNAME }}
TOKEN: ${{ secrets.TOKEN }}
REMOTE_NAME: origin
BRANCH_BASE_NAME: proxyip
BRANCH_COUNT: 300
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: πΏ Create and push branches
run: |
cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do
branch_name="${{ env.BRANCH_BASE_NAME }}${i}"
git branch $branch_name
git checkout $branch_name
git commit --allow-empty -m "Create branch ${branch_name}"
git push ${{ env.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: "π² Create many branches" on: workflow_dispatch: jobs: create_branches: timeout-minutes: 30 runs-on: latchkey-small name: "π² Create and push branches" env: EMAIL: ${{ secrets.GH_EMAIL }} NAME: ${{ secrets.GH_USERNAME }} TOKEN: ${{ secrets.TOKEN }} REMOTE_NAME: origin BRANCH_BASE_NAME: proxyip BRANCH_COUNT: 300 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: πΏ Create and push branches run: | cd $(echo ${{github.repository}} | awk -F'/' '{print $2}') for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do branch_name="${{ env.BRANCH_BASE_NAME }}${i}" git branch $branch_name git checkout $branch_name git commit --allow-empty -m "Create branch ${branch_name}" git push ${{ env.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.