Meter out usage to GitHub hosted runners vs. self-hosted runners?


I was curious if there was a clever way to split a given job run based on whether there were any free credits remaining for GitHub hosted runners.

For example, could I define a job like:

    runs-on: [ubuntu-latest, self-hosted]

… and have the job “prefer” ubuntu-latest hosted by GitHub, but if I’ve reached the free credit limit, prefer “self-hosted”?

interesting. I haven’t tried this at all, but off the top of my head maybe something like:

  • The first job in your workflow could run on a self-hosted runner, and does an API call to see if you have minutes left on your hosted runners
  • Based off the results, you could set an environment variable for use in the future “runs-on” steps. The big question I don’t know the answer to is if you can define environment variables in the “runs-on” steps.

Thanks for the suggestion @mickeygousset.

Believe it or not, this works fine:

    runs-on: self-hosted
    name: Pre-run operations
      runs_on: ${{ steps.runs_on.outputs.runs_on }}
      - name: Get runs on
        id: runs_on
        run: echo ::set-output name=runs_on::`echo self-hosted`

     needs: [prerun]
     runs-on: ${{ needs.prerun.outputs.runs_on }}

The API endpoint of interest to anybody who would like to try this approach is: Billing - GitHub Docs


@AlexDHoffer Good Job!