Skip to content
Latchkey

🌲 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.

Grade your own workflow free or run it on Latchkey →
Source: 6Kmfi6HP/EDtunnel.github/workflows/create.ymlLicense MITView source

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

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.