Skip to content

Instantly share code, notes, and snippets.

@swinton
Created February 25, 2020 17:08
Show Gist options
  • Save swinton/35d90d0b9dd5c8075b5ac24dd718d204 to your computer and use it in GitHub Desktop.
Save swinton/35d90d0b9dd5c8075b5ac24dd718d204 to your computer and use it in GitHub Desktop.
Programmatically create a self-hosted runner

self-hosted-runners-playground

Programmatically create a self-hosted runner

Download

# Get the tarball URL
curl --request GET \
  --url https://api.github.com/repos/swinton/self-hosted-runners-playground/actions/runners/downloads \
  --header 'accept: application/vnd.github.jane-hopper-preview+json,application/vnd.github.machine-man-preview+json' \
  --header 'authorization: Bearer $TOKEN'

# Download the tarball
curl -O -L $TARBALL

# Extract the installer
tar xzf ./actions-runner-osx-x64-2.165.2.tar.gz

Configure

# Generate a registration token
curl --request POST \
  --url https://api.github.com/repos/swinton/self-hosted-runners-playground/actions/runners/registration-token \
  --header 'accept: application/vnd.github.jane-hopper-preview+json,application/vnd.github.machine-man-preview+json' \
  --header 'authorization: Bearer $TOKEN'

# Create the runner and start the configuration experience
./config.sh --url https://github.com/swinton/self-hosted-runners-playground --token $REGISTRATION_TOKEN

Run

./run.sh

Remove

# Create a remove token
curl --request POST \
  --url https://api.github.com/repos/swinton/self-hosted-runners-playground/actions/runners/remove-token \
  --header 'accept: application/vnd.github.jane-hopper-preview+json,application/vnd.github.machine-man-preview+json' \
  --header 'authorization: Bearer $TOKEN'

./config.sh remove --token $REMOVAL_TOKEN

# OPTIONAL: Force-remove the self-hosted runner
curl --request DELETE \
  --url https://api.github.com/repos/swinton/self-hosted-runners-playground/actions/runners/2 \
  --header 'accept: application/vnd.github.jane-hopper-preview+json,application/vnd.github.machine-man-preview+json' \
  --header 'authorization: Bearer $TOKEN'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment