Github Actions: Self-hosted Runner

Seungyeon Anna Baek
3 min readNov 30, 2022

--

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Github Actions

Github Actions let you run a set of jobs (repeatedly) when certain events happen in your repository. For example, we can set the a workflow which build and test our code, triggered on events like pull request, push commits to github repository. Also we can send greeting message to someone who have done his first commits by setting workflow configuration.

When an event occurs in the repository, runners(server) start executing their jobs which consisted of several steps. A single step can be a shell script or an action(reusable extension).

Workflow.yaml

The configuration of workflow is written in yaml format. We can set the workflow by creating yaml file in .github/workflows folder in our repository. The content of file is intuitive so we can easily understand that the workflow below executes four steps when push event occurs on the repository.

  1. checkout to the current repository so that we can access codes
  2. setting node environment (especially version 14)
  3. installing bats program
  4. checking version of the program
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v

In a real-world projects, we can set multiple workflows to automate CI/CD(build and test, deploy) flows and manage repository(tagging labels to new issue automatically … etc).

CI/CD

Continuous Integration is a software practice that requires frequently committing code to a shared repository which helps detecting errors sooner so that a developer needs less time to debug.

Continuous Deployment is the practice of using automation to publish and deploy software updates. Automating “build ant test” process reduces addtional resources before deployment.

Github Actions help automating CI/CD process by creating workflow listening on push, pull request and executing build & test tasks. Also we can set rules before a job proceed and limit access to secrets. Last but not least, we can use concurrency keyword to control the number of deployments running at a time. For details, we can read Github Docs.

Starter Workflows

GitHub offers starter workflows for a variety of languages and tooling. There are many useful templates regarding to CI/CD, Security, and Automation. Github recommends workflows based on the language and framework in your repository. And you can write your own.

Github Actions in self-hosted runners

Runner is a server that runs your workflows when they’re triggered. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. We can use Github-hosted Runner by simply writing the OS and its version on runs-on section like below.

jobs:
example_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

Self-hosted Runner is a system that you deploy and manage to execute jobs from Github Actions on Github.com. Using self-hosted runners, we can customize OS, hardware, security requirements… etc. And our student club members choose to set self-hosted runner because its free! (Github-hosted runners are freely provided for some limited time)

Internally our local computer listen on Github server. Every 50 seconds local runner get some messages from Github in long-pooling method.

How to use self-hosted runners?

To use self-hosted runners, we have to (1) add a runner to our repository(or an organization/enterprise) and (2) use it! We can easily set the local runners by following guides that Github provides.

https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners

https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners

Reference

Github Docs: Github Actions — https://docs.github.com/en/actions

--

--

Seungyeon Anna Baek
Seungyeon Anna Baek

Written by Seungyeon Anna Baek

Yonsei University dept. of Computer Science

No responses yet