-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
03-generate-renovate-data-builtin.ps1
68 lines (57 loc) · 2.15 KB
/
03-generate-renovate-data-builtin.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$ErrorActionPreference = "Stop"
$skipCommit = $env:SKIP_COMMIT -eq "true"
$org = $env:AZURE_DEVOPS_ORG
$pat = $env:AZURE_DEVOPS_PAT
$url = "https://dev.azure.com/$org"
$header = @{authorization = "Basic $([Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(".:$pat")))"}
function add-version
{
param (
$name,
$version
)
$name = $name.ToLowerInvariant()
[string[]]$currentversions = $renovateData."$name"
$currentversions += $version
$renovateData."$name" = $currentversions
}
if (Test-Path -Path "azure-pipelines-builtin-tasks-base.json")
{
$renovateData = get-content -raw "azure-pipelines-builtin-tasks-base.json" | ConvertFrom-Json -AsHashtable
}
else
{
$renovateData = @{}
}
# Add the data needed for the unit tests.
add-version -name "automatedanalysis" -version "0.198.0"
add-version -name "automatedanalysis" -version "0.171.0"
$tasksResponse = Invoke-RestMethod -Uri "$url/_apis/distributedtask/tasks?allversions=true" -Method Get -ContentType "application/json" -Headers $header | ConvertFrom-Json -AsHashtable
$tasks = $tasksResponse.value
foreach ($task in $tasks)
{
$majorVersion = $task.version.major
$minorVersion = $task.version.minor
$patchVersion = $task.version.patch
$versionString = ([System.Version]"0$majorVersion.0$minorVersion.0$patchVersion").ToString()
add-version -name "$($task.name)" -version $versionString
add-version -name "$($task.id)" -version $versionString
}
# Sort the data to prevent unnecessary commits
$renovateDataSorted = [ordered]@{}
$renovateData.Keys | Sort-Object | foreach-object {
$renovateDataSorted."$_" = [string[]]($renovateData."$_" | Sort-Object -Unique -Property @{ Exp = { [System.Version]$_ } })
}
ConvertTo-Json $renovateDataSorted | Set-Content -Path "azure-pipelines-builtin-tasks.json"
if (-not $skipCommit)
{
& git config --local user.email "[email protected]"
& git config --local user.name "Jesse Houwing"
& git add azure-pipelines-builtin-tasks.json
& git diff HEAD --exit-code | Out-Null
if ($LASTEXITCODE -ne 0)
{
& git commit -m "azure-pipelines-builtin-tasks.json"
& git push
}
}