golang-github-enterprise-runners
So, you want to automatically register GitHub Actions Self Hosted Runners for your Orginizatiton. You've probably looked at the docs and thought "why did they make it so difficult?" Well, here's a fully working proof-of-concept using Go that will generate the various tokens and use them to call the APIs needed to (finally) get a Runner registration token.
!!! NOTE !!!
This code logs secret values and should NOT be used in a production environment! It is provided as a proof-of-concept so you can see the various steps needed to get a registration token. Also, the error handling and whole structure needs work before it's used for production workloads.
Prerequisites
- You've created a GitHub application and given it
Read & Write
permissions for Organization > Self-hosted runners
.
- You've installed the app to the orginization for which you want to manage runners.
- You've generated a private key for the app and have a copy of the file.
- You've noted the App ID and its Installation ID.
Now you can update the const
values in the main.go
file and run it to get your runner registration tokens.
go run main.go
You can then use the token generated to register a new Runner.
./config.sh --url https://my.github-enterprise.com/MyOrg --token TOKEN