This shell script is used to set up a GitHub Actions runner on a Linux machine. A GitHub Actions runner is a server that GitHub uses to run your CI/CD jobs. This script automates the process of downloading, installing, and configuring the runner.
The script takes two arguments: the name of the repository where the runner will be added (repo_to_add_runner), and a GitHub bearer PAT token (github_token) that has the necessary permissions to setup a runner to the repository.
-
First, the script creates a directory named
actions-runnerand navigates into it. It then downloads the latest version of the GitHub Actions runner package forx64in "Linux" systems or "MacOS" from GitHub's servers using thecurlcommand. Optionally, you can validate the hash of the downloaded file to ensure its integrity. -
Next, the script creates another directory named
runner-fileswithin theactions-runnerdirectory and navigates into it. It then extracts the downloaded runner package using the tar command. -
The script then uses
curlto make aPOSTrequest to the GitHub API to create aregistration tokenfor the runner. This token is necessary to register the runner with the specified repository. Thejqcommand is used to extract the token from theJSONresponse. -
The script then runs the
config.shscript that comes with the runner package located in extracted package. This script configures the runner, specifying the repository URL and the registration token. The--unattendedflag means that the script runs without requiring user input. -
Finally, the script runs the
svc.shscript, also included in the runner package, to install the runner as a service and start it. This means that the runner will automatically start running jobs as soon as they are available in the repository's Actions queue.