Skip to content

Commit

Permalink
Remove hardcoded actions runner version in install snippet
Browse files Browse the repository at this point in the history
the version is extracted and defined as a constant for easier
updating of the version later
  • Loading branch information
anjannath committed Jul 12, 2024
1 parent 1a391ea commit 1f26a45
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions pkg/util/ghactions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ type RunnerArgs struct {
Name string
}

var args *RunnerArgs
const runnerVersion = "2.317.0"

var (
args *RunnerArgs

runnerBaseURLWin = "https://github.com/actions/runner/releases/download/v%s/actions-runner-win-x64-%s.zip"
runnerBaseURLLinux = "https://github.com/actions/runner/releases/download/v%s/actions-runner-linux-x64-%s.tar.gz"
)

func getRunnerDownloadURLWin() string {
return fmt.Sprintf(runnerBaseURLWin, runnerVersion, runnerVersion)
}

func getRunnerDownloadURLLinux() string {
return fmt.Sprintf(runnerBaseURLLinux, runnerVersion, runnerVersion)
}

func InitGHRunnerArgs(token, name, repoURL string) error {
if token == "" || name == "" || repoURL == "" {
Expand All @@ -36,18 +51,16 @@ func GetToken() string {
// $ghToken needs to be set externally before use; it is defined in the platform specific setup scripts
// for aws this is defined in the script and for azure it is passed as an arg to the setup script
const WindowsActionsRunnerInstallSnippet string = `New-Item -Path C:\actions-runner -Type Directory ; cd C:\actions-runner
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.317.0/actions-runner-win-x64-2.317.0.zip -OutFile actions-runner-win-x64-2.317.0.zip
Invoke-WebRequest -Uri %s -OutFile actions-runner-win.zip
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
if((Get-FileHash -Path actions-runner-win-x64-2.317.0.zip -Algorithm SHA256).Hash.ToUpper() -ne 'a74dcd1612476eaf4b11c15b3db5a43a4f459c1d3c1807f8148aeb9530d69826'.ToUpper()){ throw 'Computed checksum did not match' }
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\actions-runner-win-x64-2.317.0.zip", "$PWD")
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\actions-runner-win.zip", "$PWD")
./config.cmd --token $ghToken --url %s --name %s --unattended --runasservice --replace`

// whitespace at the start is required since this is expanded in a cloud-init yaml file
// to start as service need to relable the runsvc.sh file on rhel: https://github.com/actions/runner/issues/3222
const LinuxActionsRunnerInstallSnippet string = ` mkdir ~/actions-runner && cd ~/actions-runner` + "\n" +
` curl -o actions-runner-linux-x64-2.317.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.317.0/actions-runner-linux-x64-2.317.0.tar.gz` + "\n" +
` echo "9e883d210df8c6028aff475475a457d380353f9d01877d51cc01a17b2a91161d actions-runner-linux-x64-2.317.0.tar.gz" | sha256sum -c` + "\n" +
` tar xzf ./actions-runner-linux-x64-2.317.0.tar.gz` + "\n" +
` curl -o actions-runner-linux.tar.gz -L %s` + "\n" +
` tar xzf ./actions-runner-linux.tar.gz` + "\n" +
` sudo ./bin/installdependencies.sh` + "\n" +
` ./config.sh --token %s --url %s --name %s --unattended --replace` + "\n" +
` sudo ./svc.sh install` + "\n" +
Expand All @@ -58,12 +71,14 @@ func GetActionRunnerSnippetWin() string {
if (args == &RunnerArgs{}) {
return ""
}
return fmt.Sprintf(WindowsActionsRunnerInstallSnippet, args.RepoURL, args.Name)
return fmt.Sprintf(WindowsActionsRunnerInstallSnippet,
getRunnerDownloadURLWin(), args.RepoURL, args.Name)
}

func GetActionRunnerSnippetLinux() string {
if (args == &RunnerArgs{}) {
return ""
}
return fmt.Sprintf(LinuxActionsRunnerInstallSnippet, args.Token, args.RepoURL, args.Name)
return fmt.Sprintf(LinuxActionsRunnerInstallSnippet,
getRunnerDownloadURLLinux(), args.Token, args.RepoURL, args.Name)
}

0 comments on commit 1f26a45

Please sign in to comment.