-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap_windows.ps1
45 lines (39 loc) · 2.22 KB
/
bootstrap_windows.ps1
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
44
45
# Create the work folder and change to it
#mkdir c:/github
cd c:/github
#Get-ChildItem -Recurse | ?{Remove-Item $_.fullname -Recurse -Force}
# Reads variables from a file
Get-Content c:/vagrant/bootstrap_vars_windows | Foreach-Object{
$var = $_.Split('=').Trim()
New-Variable -Name $var[0] -Value $var[1]
}
# Gets the github runner
#$runnerzip = "https://github.com/actions/runner/releases/download/v$GITHUB_RUNNER_VERSION/actions-runner-win-x64-$GITHUB_RUNNER_VERSION.zip"
#Invoke-WebRequest -Uri $runnerzip -OutFile ghrunner.zip
#Expand-Archive ghrunner.zip -DestinationPath .
# Gets the registration token
$registration_url = "https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPOSITORY/actions/runners/registration-token"
$headers = @{"Authorization" = "token $GITHUB_PAT"}
echo "Requesting registration URL at '$registration_url'"
$payload = Invoke-WebRequest -Method POST -Uri $registration_url -Headers $headers
$RUNNER_TOKEN = ($payload.Content | ConvertFrom-Json).token
# Write teardown script
cd c:/users/vagrant
echo 'cd c:/github' > teardown.ps1
echo 'Get-Content c:/vagrant/bootstrap_vars_windows | Foreach-Object{' >> teardown.ps1
echo ' $var = $_.Split("=").Trim()' >> teardown.ps1
echo ' New-Variable -Name $var[0] -Value $var[1] }' >> teardown.ps1
echo '$removal_url="https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPOSITORY/actions/runners/remove-token"' >> teardown.ps1
echo '$headers = @{"Authorization" = "token $GITHUB_PAT"}' >> teardown.ps1
echo '$payload = Invoke-WebRequest -Method POST -Uri $removal_url -Headers $headers' >> teardown.ps1
echo '$RUNNER_TOKEN= ($payload.Content | ConvertFrom-Json).token' >> teardown.ps1
echo './config.cmd remove --unattended --token $RUNNER_TOKEN' >> teardown.ps1
type teardown.ps1
cd c:/github
If ($GITHUB_ID -eq "") { $LABEL="windows_matlab" } Else { $LABEL="windows_"+$GITHUB_ID }
# Register runner and run it
$gh_repo = "https://github.com/$GITHUB_OWNER/$GITHUB_REPOSITORY"
$name = (1..16 | %{ '{0:X}' -f (Get-Random -Max 16)}) -join ''
./config.cmd --token $RUNNER_TOKEN --url $gh_repo --name $name --labels $LABEL --unattended --replace --runasservice
# Unlike in Linux, runner doesn't exit when it starts, so run it as a service in the config step, otherwise hangs
#cmd.exe /c run.cmd