Bring your own (self-hosted) environment for GitHub Action Workflows
Tags: github, devops
Published: 2021-02-23 00:04:43

You can self-host your runners with customized environments in your GitHub Actions workflows. These runners are available thanks to the fact that GitHub open-sourced their runners on GitHub of course. 

{% github https://github.com/actions/runner %}

[Self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners#about-self-hosted-runners) offer more control of hardware, operating system, and software tools than GitHub-hosted runners provide. With self-hosted runners, you can choose to create a custom hardware configuration with more processing power or memory to run larger jobs, install software available on your local network, and choose an operating system not offered by GitHub-hosted runners. Self-hosted runners can be physical, virtual, in a container, on-premises, or in a cloud.

You can add self-hosted runners at various levels in the management hierarchy:

- Repository-level runners are dedicated to a single repository.
- Organization-level runners can process jobs for multiple repositories in an organization.
- Enterprise-level runners can be assigned to multiple organizations in an enterprise account.

## 3 Steps to add your own runner

1: Head over to GitHub repo's settings and scroll down to the to add a runner.

![add a runner](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzwt1p1h0vo574q0llv0.png)
 
2: Here you will find instructions that can be copy and pasted into a virtual or on-premise environment. 
 
![runner setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbaopyum31blwua4xc0q.png)

I will be using a 2018 Macbook Pro (touchbar) and show how to install self-hosted runners to leverage in a workflow in the demo. 

![running self-hosted runner](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fm3h7keu82pw7pizkryd.gif)
  
3: Finally, replace the `runs-on: self-hosted` to your action workflow.

## Some things to consider

There are some limits on GitHub Actions usage when using self-hosted runners. These limits are subject to change.

- **Workflow run time** - Each workflow run is limited to 72 hours. If a workflow run reaches this limit, the workflow run is canceled.
- **Job queue time** - Each job for self-hosted runners can be queued for a maximum of 24 hours. If a self-hosted runner does not start executing the job within this limit, the job is terminated and fails to complete.
- **API requests** - You can execute up to 1000 API requests in an hour across all actions within a repository. If exceeded, additional API calls will fail, which might cause jobs to fail.
- **Job matrix** - A job matrix can generate a maximum of 256 jobs per workflow run. This limit also applies to self-hosted runners.

To learn more about self-hosted runners, check out the [GitHub Documentation](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners)

_This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev. Learn how to build action with Node.js_

{% link https://dev.to/github/sending-pr-notifications-through-sms-and-github-actions-bb3 %}