. .gh-api-examples.conf

set -x

# Get the registration token for the runner before we cd into the runner download
# directory.
registration_token=$(./create-a-registration-token-for-a-repository.sh | jq -r '.token')

rm -rf actions-runner
mkdir actions-runner && cd actions-runner

curl -O -L https://github.com/actions/runner/releases/download/${runner_version}/actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

tar zxf actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

# This is a gnarly thing to do but saves rewriting how the config file
# gets populated for this one script that uses github.com the runner tarball download
if [ $hostname == "api.github.com" ];
then
  hostname="github.com"
fi

./config.sh --url https://${hostname}/${org}/${repo} --token ${registration_token} --unattended --name ${runner_name} --labels ${runner_labels} --replace 
