Job Runner Selection and Labels
What you'll learn: How to choose which type of machine runs your GitHub Actions jobs using runs-on and how to target specific self-hosted runners with custom labels.
The Core Idea
Every job in GitHub Actions needs a physical or virtual machine (a "runner") to execute on. The runs-on key in your workflow file lets you specify which type of runner should handle the job. Think of it like choosing a delivery service: GitHub-hosted runners are like Amazon Prime (maintained by someone else), while self-hosted runners are like your own delivery fleet (you manage them).
Selecting GitHub-Hosted Runners
For GitHub-hosted runners, you use predefined labels that specify the operating system:
jobs:
build:
runs-on: ubuntu-latest # Uses GitHub's Ubuntu runner
Common options include ubuntu-latest, windows-latest, and macos-latest. These are managed, maintained, and scaled automatically by GitHub.
Targeting Self-Hosted Runners
When you register self-hosted runners (machines you manage yourself), you can assign them custom labels like gpu-enabled, production, or high-memory. You then target them using those labels:
jobs:
train-model:
runs-on: [self-hosted, gpu-enabled, linux]
This job only runs on runners that have all three labels. It's like putting specific requirements on a job posting—only runners matching all criteria will pick up the work.
Why This Matters
Different jobs have different needs. Building a Node.js app might need Ubuntu, while testing Windows desktop software requires a Windows runner. Machine learning jobs might need your special GPU-equipped self-hosted runner, while standard builds can use GitHub's free hosted runners.
Key Takeaway: Use runs-on to match jobs with appropriate runners—pick GitHub-hosted labels for convenience or self-hosted labels for specialized hardware and custom environments.