Created
          May 17, 2024 16:27 
        
      - 
      
 - 
        
Save albertodebortoli/25c749e1c7fdb917a1700f975896aba7 to your computer and use it in GitHub Desktop.  
    GitHub Actions dev-hosted runners PoC
  
        
  
    
      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: dev-hoster runner PoC | |
| on: | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| generate-runs-on-info: | |
| name: Generate runs-on info | |
| runs-on: | |
| group: CI | |
| labels: [ self-hosted, ubuntu-latest ] | |
| outputs: | |
| runner-group: ${{ steps.fetch-runners.outputs.runner_group }} | |
| runner-labels: ${{ steps.fetch-runners.outputs.runner_labels }} | |
| steps: | |
| - name: Fetch runners in 'Devs' group | |
| id: fetch-runners | |
| run: | | |
| BRANCH_NAME=${{ github.ref_name }} | |
| echo "Branch Name: $BRANCH_NAME" | |
| # GitHub Enterprise: http(s)://HOSTNAME/api/v3/orgs/${{ github.repository_owner }}/actions/runners | |
| MATCHING_LABEL=$(curl -s -H "Authorization: token ${{ secrets.GH_PAT }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| https://api.github.com/orgs/${{ github.repository_owner }}/actions/runners | jq -r --arg branch "$BRANCH_NAME" '[.runners[] | select(.status == "online") | select(.labels[].name == $branch)] | length') | |
| echo "Matching Label Count: $MATCHING_LABEL" | |
| if [ "$MATCHING_LABEL" -gt 0 ]; then | |
| echo "runner_group=Devs" >> $GITHUB_OUTPUT | |
| echo "runner_labels=['dev-hosted','bare-metal','Xcode-15.2.0','macOS-14.2.1','$BRANCH_NAME']" >> $GITHUB_OUTPUT | |
| else | |
| echo "runner_group=Shared" >> $GITHUB_OUTPUT | |
| echo "runner_labels=['self-hosted','bare-metal','Xcode-15.2.0','macOS-14.2.1']" >> $GITHUB_OUTPUT | |
| fi | |
| do-stuff: | |
| name: Do stuff | |
| needs: [ generate-runs-on-info ] | |
| runs-on: | |
| group: ${{ needs.generate-runs-on-info.outputs.runner-group }} | |
| labels: ${{ fromJson(needs.generate-runs-on-info.outputs.runner-labels) }} | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Sleep | |
| run: | | |
| sleep 1 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Idea based on the controversial https://world.hey.com/dhh/we-re-moving-continuous-integration-back-to-developer-machines-3ac6c611
Pros:
Cons: