GitHub Self Hosted Runner Setup
GitHub Actions are a newer feature in GitHub that I just found to help with my development of python packages. The setup is incredibly easy and allows you to have automated tests/builds with your code as you develop it (CI).
Prerequisites
The only requirement is to have a server that you want to use to build and test your code. I will be using Ubuntu but you can use almost anything including Windows and Mac OS. A cool thing to note is that the GitHub runner doesn’t require any ports open because it reaches out to GitHub. This means that any VM with a NAT network setup, which is the default, can be used as a server.
Initial Setup
We need a user to run the service.
sudo useradd -m git-runner
Now follow the instructions for installation for your OS from here:
https://github.com/actions/runner/releases/tag/v2.283.2
I will show Ubuntu as an example. I run the following commands as our new user git-runner
.
# Create a folder
mkdir actions-runner && cd actions-runner
# Download the latest runner package
curl -O -L https://github.com/actions/runner/releases/download/v2.283.2/actions-runner-linux-x64-2.283.2.tar.gz
# Extract the installer
tar xzf ./actions-runner-linux-x64-2.283.2.tar.gz
Now set the config for your repository. To do this go to Settings > Actions > Runners > New Self Hosted Runner.
Here you will see commands to set the config for this install to your repository.
# Create the runner and start the configuration experience
$ ./config.sh --url <repo_url> --token <secret_token>
Installing Service
This should run at startup as well so that we won’t need to interactively work with it. As root navigate to our directory and run the command for the service.
sudo -iu root
cd /home/git-runner/actions-runner
./svc.sh install git-runner
Specifying git-runner sets that user and the runtime user for the service.
Then start your new service.
./svc.sh start
Now from the same screen where you clicked New Self Hosted Runner you should see your runner with a state of Idle.
Setup for Multiple Repositories
When you have more than one repository you won’t be able to use the same install for each due to the configuration step. The only way around this is to follow the same steps again but with a different folder. Our original install is in ~git-runner/actions-runner
so we will setup a new folder ~git-runner/actions-runner-reponame
and go through the same steps as before. This method will allow you to use the same server/user for GitHub self hosted runners.
Action Requirements
The only requirement to use this new runner is to put runs-on: self-hosted
for every job in your action workflow. See the following as an example:
name: Python application
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
check-standards:
runs-on: self-hosted
steps:
...