Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compareXmlFiles.ps1 « mdoc - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9879aba3bc57a9f63bc3c1647d905b75d987ffa (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
param (
    [string]$paramsJson,
    [string]$githubTokenBase64,
    [string]$githubOptionsAccountName,
    [string]$githubOptionsAccountEmail,
    [string]$vstsTokenBase64
)

function Git-Init([string]$githubAccountName, [string]$githubAccountEmail)
{
	& git config --global --unset-all include.path
	& git config --global --unset-all credential.helper
	& git config --system --unset-all include.path
	& git config --system --unset-all credential.helper
	& git config --global credential.helper store
	& git config --global user.name $githubAccountName
    & git config --global user.email $githubAccountEmail
}

function Git-Clone([string]$repoUrl, [string]$repoPath, [string] $token, [string]$branch = "main") 
{
	Write-Host 'git -c http.extraHeader="Authorization: Basic '$token'" clone -b '$branch' '$repoUrl' '$repoPath' --depth 1 --shallow-submodules'
	& git -c http.extraHeader="Authorization: Basic $token" clone -b $branch $repoUrl $repoPath --depth 1 --shallow-submodules

	Push-Location $repoPath
	Write-Host | & git branch
	Pop-Location
}

function Git-Push([string]$rootPath, [string] $token, [string] $commitMessage, [string]$branch = "main") 
{
	Push-Location $rootPath

	$result = & git status
	if($result.Contains("nothing to commit"))
	{
		Write-Host "$result"
	}
	else
	{
		& git add --all
		& git commit -m $commitMessage
		& git -c http.extraHeader="Authorization: Basic $token" push --set-upstream origin $branch --force-with-lease
	}
} 

function Run-Mdoc([string] $mdocPath, [string] $fwPath, [string] $xmlPath)
{
	Write-Host "$mdocPath fx-bootstrap $fwPath"
	& $mdocPath fx-bootstrap $fwPath

	$dnpath = [System.IO.Path]::GetDirectoryName((get-command dotnet).Source)
	$langs=@("VB.NET","F#","C++/CLI")
	$allArgs = @("update",
	 "-o", "$xmlPath",
	 "-fx", "$fwPath",
	 "-lang", "docid",
	 "-index", "false",
	 "--debug",
	 "--delete",
	 "-L", """C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PublicAssemblies"""
	 "-L", """C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies"""
	 "-L", """C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.0.0.1"""
	 "-L", """$dnpath""");
	if ($langs) {
		foreach ($lang in $langs) {
			$allArgs += "-lang"
			$allArgs += "$lang"
		}
	}
	Write-Host "& $mdocPath $allArgs"
	& $mdocPath $allArgs
}

# Clone binary repo, xml repo
# Generate xml file, push and log commit id
# Again to generate xml file, push and log commit id
# Compare two commits
function Run($source_repo,$target_repo)
{
	if([String]::IsNullOrEmpty($source_repo.url)){
		Write-Host "source repo url is null or empty!"
	}
	if([String]::IsNullOrEmpty($source_repo.branch)){
		Write-Host "source repo branch is null or empty!"
	}
	if([String]::IsNullOrEmpty($source_repo.folder)){
		Write-Host "source repo folder is null or empty!"
	}
	if([String]::IsNullOrEmpty($target_repo.url)){
		Write-Host "target repo url is null or empty!"
	}
	if([String]::IsNullOrEmpty($target_repo.branch)){
		Write-Host "target repo branch is null or empty!"
	}
	if([String]::IsNullOrEmpty($target_repo.folder)){
		Write-Host "target repo folder is null or empty!"
	}

	$sourceRepoUrl = $source_repo.url
	$sourceRepoBranch = $source_repo.branch
	$sourceFolder = $source_repo.folder
	$sourceRepoPath= $source_repo.repo_root
	$targetRepoUrl = $target_repo.url
	$targetRepoBranch = $target_repo.branch
	$targetfolder = $target_repo.folder
	$targetRepoPath= $target_repo.repo_root

	$frameworksPath = Join-Path $sourceRepoPath $sourceFolder
	$xmlPath = Join-Path $targetRepoPath $targetfolder

	Write-Host "==================== Clone source repo: $sourceRepoUrl"
	if($sourceRepoUrl.Contains("github.com/")){
		Git-Clone $sourceRepoUrl $sourceRepoPath $githubTokenBase64 $sourceRepoBranch
	}
	else{
		Git-Clone $sourceRepoUrl $sourceRepoPath $vstsTokenBase64 $sourceRepoBranch
	}
	
	Write-Host "==================== Clone target repo: $targetRepoUrl"
	Git-Clone $targetRepoUrl $targetRepoPath $githubTokenBase64 $targetRepoBranch
	if (Test-Path $xmlPath) 
	{
		Write-Host "Delete files under path: $xmlPath"
		Remove-Item -Recurse -Force $xmlPath\*
		Write-Host "Delete files done."
	}

	Write-Host "==================== Run Mdoc(release version) tool to generated xml files."
	Run-Mdoc $releaseMdocPath $frameworksPath $xmlPath
	if ($lastexitcode -ne 0)
	{
		exit $lastexitcode
	}
	
	Write-Host "==================== First to commit xml files"
	$message = "CI Update 1 with build number " + $env:BUILD_BUILDNUMBER
	Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
	$commitid1 = & git rev-parse HEAD
	Write-Host "Commit Id1: $commitid1"
	Pop-Location
	if (Test-Path $xmlPath) 
	{
		Write-Host "Delete files under path: $xmlPath"
		Remove-Item -Recurse -Force $xmlPath\*
		Write-Host "Delete files done."
	}
	
	Write-Host "==================== Run Mdoc(pr version) tool to generated xml files."
	Run-Mdoc $prMdocPath $frameworksPath $xmlPath
	if ($lastexitcode -ne 0)
	{
		exit $lastexitcode
	}
	
	Write-Host "==================== Sencond to commit xml files"
	$message = "CI Update 2 with build number " + $env:BUILD_BUILDNUMBER
	Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
	$commitid2 = & git rev-parse HEAD
	Write-Host "Commit Id2: $commitid2"
	Pop-Location
	
	Write-Host "==================== Compare two version xml files."
	$shortCommitId1 = $commitid1.Substring(0, 7)
	$shortCommitId2 = $commitid2.Substring(0, 7)
	if($targetRepoUrl.EndsWith(".git"))
	{
		$compareUrl = $targetRepoUrl.Substring(0, $ymlRepoUrl.Length - 4)
	}
	else
	{
		$compareUrl = $targetRepoUrl
	}
	
	$compareUrl = $compareUrl + "/compare/"
	$compareUrl = $compareUrl + "$shortCommitId1...$shortCommitId2/"
	
	Write-Host ("##vso[task.setvariable variable=CompareUrl;]$compareUrl")
	Write-Host "Compare Url: $compareUrl"
}

$params = $paramsJson | ConvertFrom-Json
if([String]::IsNullOrEmpty($githubTokenBase64))
{
	Write-Host "githubTokenBase64 is null or empty!"
}
if([String]::IsNullOrEmpty($vstsTokenBase64))
{
	Write-Host "vstsTokenBase64 is null or empty!"
}

# Set download Paths
$repoRoot = $($MyInvocation.MyCommand.Definition) | Split-Path | Split-Path
$prMdocPath = "$repoRoot\bin\Release\mdoc.exe"

$parentRoot = $repoRoot | Split-Path
$binPath = Join-Path "$parentRoot\TestCI" "\_bin"
New-Item $binPath -Type Directory -Force

# Download nuget tool
$nugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$mdocPackageSource = "https://api.nuget.org/v3/index.json"
$nugetPath = Join-Path $binPath "\nuget.exe"
Invoke-WebRequest -Uri $nugetUrl -OutFile $nugetPath -Verbose

# Download mdoc package
Write-Host "==================== Download Mdoc tool"
$mdocPackageId = "mdoc"

if([String]::IsNullOrEmpty($params.mdoc_Version))
{
	$versionStr = & $nugetPath list $mdocPackageId -Source $mdocPackageSource
	if($versionStr -is [array])
	{
		$lastVersionStr = $versionStr[$versionStr.Count-1]
	}
	else
	{
		$lastVersionStr = $versionStr
	}
	Write-Host "$mdocPackageId last version string: $lastVersionStr"
	$lastVersion = $lastVersionStr.Split(" ")[1]
}
else
{
	$lastVersion = $params.mdoc_Version
}
Write-Host "$nugetPath install $mdocPackageId -Version $lastVersion -Source $mdocPackageSource -OutputDirectory $binPath"
& $nugetPath install $mdocPackageId -Version $lastVersion -Source $mdocPackageSource -OutputDirectory $binPath

$releaseMdocPath = Join-Path $binPath "mdoc.$lastVersion"
dir $releaseMdocPath
$releaseMdocPath = Join-Path $releaseMdocPath "tools\mdoc.exe"
Write-Host "Download $mdocPackageId to path: $releasemdocPath"


# Init git configure
Git-Init $githubOptionsAccountName $githubOptionsAccountEmail

# Generate ecma xml files
$params.source_repo.repo_root = Join-Path "$parentRoot\TestCI" $params.source_repo.repo_root
$params.target_repo.repo_root = Join-Path "$parentRoot\TestCI" $params.target_repo.repo_root
Run $params.source_repo $params.target_repo