-
Notifications
You must be signed in to change notification settings - Fork 0
/
gha-runner.sh
43 lines (31 loc) · 1.29 KB
/
gha-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# url for github api endpoint
base_api_url="https://api.github.com"
# Username or Org name
owner=$1
# Name of the repository to create a runner for
repo=$2
# Access token
token=$3
# Runner Name
name=$(uuidgen)
# Runner platform
runner_plat=linux
# Get a authorized token for your repo/org
export RUNNER_TOKEN=$(curl -s -X POST ${base_api_url}/orgs/${owner}/actions/runners/registration-token -H "accept: application/vnd.github.everest-preview+json" -H "authorization: token ${token}" | jq -r '.token')
# Find the latest version of the runner software
latest_version_label=$(curl -s -X GET 'https://api.github.com/repos/actions/runner/releases/latest' | jq -r '.tag_name')
latest_version=$(echo ${latest_version_label:1})
# Assemble the string-value for the runner application archive
runner_file="actions-runner-${runner_plat}-x64-${latest_version}.tar.gz"
# Assemble the download URL
runner_url="https://github.com/actions/runner/releases/download/${latest_version_label}/${runner_file}"
# Download and extract the archive
sudo wget -O ${runner_file} ${runner_url}
sudo tar xzf "./${runner_file}"
# Install and configure the application without prompting for user-input
./config.sh --url https://github.com/${owner} \
--token ${RUNNER_TOKEN} \
--unattended \
--ephemeral \
--name $name