This commit is contained in:
freddydk 2023-02-03 06:46:43 +01:00
Родитель 9986332ecb
Коммит 2be7dde0b4
1 изменённых файлов: 52 добавлений и 16 удалений

68
.github/workflows/CreateAgents.yaml поставляемый
Просмотреть файл

@ -45,19 +45,19 @@ jobs:
$repo = $env:GITHUB_REPOSITORY
Write-Host "Resource Group is $resGroup"
Write-Host
#$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
#if ($resourceGroup) {
# Write-Host "Removing Resource Group $resGroup"
# Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
# Write-Host "Done"
#}
#$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
#$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
# Write-host "Unregistering runner $($_.name)"
# $id = $_.id
# gh api -X DELETE /repos/$repo/actions/runners/$id
# Write-Host "Done"
#}
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
Write-Host "Done"
}
$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
Write-host "Unregistering runner $($_.name)"
$id = $_.id
gh api -X DELETE /repos/$repo/actions/runners/$id
Write-Host "Done"
}
- name: Create Resource Group
uses: azure/powershell@v1
@ -69,7 +69,7 @@ jobs:
$resGroup = $env:resGroup
$resLocation = $env:resLocation
Write-Host "Creating resource group $resGroup in $resLocation"
#$resourceGroup = New-AzResourceGroup -Name $resGroup -Location $resLocation -Force
$resourceGroup = New-AzResourceGroup -Name $resGroup -Location $resLocation -Force
Write-Host "Done"
- name: Calculate Matrix
@ -96,11 +96,47 @@ jobs:
- name: Create Azure VM
uses: azure/powershell@v1
if: github.event.inputs.CreateAgents == 'Y'
env:
machine: ${{ matrix.machine }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
with:
azPSVersion: "latest"
inlineScript: |
Write-Host $env:machine
$resGroup = $env:resGroup
$repo = $env:GITHUB_REPOSITORY
$no = $env:machine
$templateUri = "https://raw.githubusercontent.com/microsoft/nav-arm-templates/$($env:ARMbranch)/$($env:ARMtemplate).json"
$registrationToken = (gh api -X POST /repos/$repo/actions/runners/registration-token | ConvertFrom-Json).token
$headers = @{
"Accept" = "application/json"
}
$uri = "https://api.github.com/repos/actions/runner/releases"
$result = Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $uri
$releases = $result.Content | ConvertFrom-Json
$asset = $releases[0].assets | Where-Object { $_.name -like "actions-runner-win-x64-*.*.?.zip" }
$Parameters = @{
"VmName" = "$resgroup$no"
"Remotedesktopaccess" = "-"
"OperatingSystem" = "Windows Server 2022"
"VmSize" = "Standard_D4as_v5"
"OSDiskSize" = 128
"StorageAccountType" = "Premium_LRS"
"AdminPassword" = [SecureString](ConvertTo-SecureString -String $env:GH_TOKEN -AsPlainText -Force)
"Count" = 1
"Token" = $registrationToken
"Organization" = "https://github.com/$repo"
"LabelsOrPool" = "buildgeneric"
"AgentUrl" = $asset.browser_download_url
"InstallHyperV" = "Yes"
"RunInsideDocker" = "No"
"FinalSetupScriptUrl" = "additional-installforbuildagent.ps1"
}
$err = $resourceGroup | Test-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters
if ($err) {
$err
throw "stop"
}
Write-Host "Creating Azure VM $($parameters.VmName)"
$resourceGroup | New-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters -Name $Parameters.vmName -ErrorAction Ignore
Write-Host "Done"
}