-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathcreate-manifest-file.ps1
More file actions
124 lines (109 loc) · 4.68 KB
/
Copy pathcreate-manifest-file.ps1
File metadata and controls
124 lines (109 loc) · 4.68 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param (
[Parameter (Mandatory=$true)][string] $BuildConfiguration,
[Parameter (Mandatory=$true)][string] $BuildOutputDir,
[Parameter (Mandatory=$true)][string] $DabVersion,
[Parameter (Mandatory=$true)][string] $isReleaseBuild
)
$versionId = $DabVersion
$versionTag = "untagged" #untagged. non-release build will have no tag
$releaseType = "development"
$releaseDate = (Get-Date).ToUniversalTime().ToString('u')
$maxVersionCount = 100
if ($isReleaseBuild -eq 'true')
{
$versionTag = "v" + $versionId
$releaseType = "released"
}
# Generating hash for DAB packages
# TODO: Release-engineering - confirm the net10.0_{linux,win,osx}-x64 download
# URLs and SHA hashes referenced downstream still resolve after the .NET 10
# publish cycle runs. (Add a tracking issue number/link here once created.)
$dotnetTargetFrameworks = "net10.0"
$RIDs = "win-x64", "linux-x64", "osx-x64"
[hashtable]$frameworkPlatformDownloadMetadata = @{}
[hashtable]$frameworkPlatformFileHashMetadata = @{}
foreach ($targetFramework in $dotnetTargetFrameworks)
{
foreach ($RID in $RIDs) {
$fileName = "dab_${targetFramework}_${RID}-${DabVersion}.zip"
$filePath = "$BuildOutputDir/publish/$BuildConfiguration/$targetFramework/$RID/$fileName"
$download_url = "https://github.com/Azure/data-api-builder/releases/download/$versionTag/$fileName"
$fileHashInfo = Get-FileHash $filePath
$hash = $fileHashInfo.Hash
$frameworkPlatformDownloadMetadata.Add("${targetFramework}_${RID}", $download_url)
$frameworkPlatformFileHashMetadata.Add("${targetFramework}_${RID}", $hash)
}
}
# Generating hash for nuget
$nugetCliFileName = "Microsoft.DataApiBuilder.$DabVersion.nupkg"
$nugetCliFilePath = "$BuildOutputDir/nupkg/$nugetCliFileName"
$fileCliHashInfo = Get-FileHash $nugetCliFilePath
$nuget_cli_file_hash = $fileCliHashInfo.Hash
$download_url_nuget_cli = "https://github.com/Azure/data-api-builder/releases/download/$versionTag/$nugetCliFileName"
$nugetCoreFileName = "Microsoft.DataApiBuilder.Core.$DabVersion.nupkg"
$nugetCoreFilePath = "$BuildOutputDir/nupkg/$nugetCoreFileName"
$fileCoreHashInfo = Get-FileHash $nugetCoreFilePath
$nuget_core_file_hash = $fileCoreHashInfo.Hash
$download_url_nuget_core = "https://github.com/Azure/data-api-builder/releases/download/$versionTag/$nugetCoreFileName"
# Creating new block to insert latest version
# String substitution requires hashtable to be wrapped in $( $hashtable['key'] ) to avoid parsing issues.
$latestBlock = @'
{
"version": "latest",
"versionId": "${versionId}",
"releaseType": "${releaseType}",
"releaseDate": "${releaseDate}",
"files": {
"linux-x64":{
"url": "$($frameworkPlatformDownloadMetadata["net10.0_linux-x64"])",
"sha": "$($frameworkPlatformFileHashMetadata["net10.0_linux-x64"])"
},
"win-x64":{
"url": "$($frameworkPlatformDownloadMetadata["net10.0_win-x64"])",
"sha": "$($frameworkPlatformFileHashMetadata["net10.0_win-x64"])"
},
"osx-x64":{
"url": "$($frameworkPlatformDownloadMetadata["net10.0_osx-x64"])",
"sha": "$($frameworkPlatformFileHashMetadata["net10.0_osx-x64"])"
},
"nuget": {
"url": "${download_url_nuget_cli}",
"sha": "${nuget_cli_file_hash}"
},
"nuget-core": {
"url": "${download_url_nuget_core}",
"sha": "${nuget_core_file_hash}"
}
}
}
'@
$latestBlock = $ExecutionContext.InvokeCommand.ExpandString($latestBlock) | ConvertFrom-Json
# Get file content of the last released manifest file
$manifestFilePath = "$BuildOutputDir/dab-manifest.json"
$lastReleasedData = @()
if (Test-Path $manifestFilePath) {
$lastReleasedData = Get-Content $manifestFilePath -raw | ConvertFrom-Json
}
# marking previous versions as old
# there will always be only 1 "latest" version
foreach($data in $lastReleasedData) {
if($data.version -eq "latest") {
$data.version = "old"
break
}
}
# Adding new block to the top of the list of released versions.
# Add the data from the last released manifest file.
$versionArray = @()
$versionArray += $latestBlock
$versionArray += $lastReleasedData
# Removing the oldest version if total count exceeds the max permissible count
if($versionArray.Length -gt $maxVersionCount){
$versionArray = [System.Collections.ArrayList]$versionArray
$versionArray.RemoveAt($versionArray.Count-1)
}
# Updating the manifest file
# Keeping Depth as 4, as by default ConvertTo-Json only support conversion till depth 2.
ConvertTo-Json -Depth 4 $versionArray | Out-File $BuildOutputDir/dab-manifest.json