-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDKAutoTest.ps1
148 lines (131 loc) · 4.13 KB
/
SDKAutoTest.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
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
#requires -version 2.0
[cmdletbinding()]
$file="c:\TrackV2Validation.xlsx"
function AutoTextFunction($path){
$Obj = "what"| Select-Object -Property HasSpecConfiguration,Generate,Build
$mainpath= 'C:\AME\azure-sdk-for-net\sdk'
cd $mainpath
#get current path from excel
$currentpath= $path
$loadEnvPath
cd $currentpath
$fileList =ls -Name
foreach($file in $fileList)
{
if($file.startswith('Azure.Management'))
{
$loadEnvPath= $file + '\src'
break
}
}
#then comfirm the path
if (-Not (Test-Path -Path $loadEnvPath)) {
#obj can not be find,end
$Obj.HasSpecConfiguration="NO"
cd ../../..
}else
{
#obj can be find,continue
$Obj.HasSpecConfiguration="YES"
#enter the foldfile
cd $loadEnvPath
$generateString = dotnet msbuild /t:GenerateCode |Out-string
$isGenSuccess = $generateString.contains("EXEC : error") -or $generateString.contains("): error")
#if not exist then continue 'build'
if(!$isGenSuccess)
{
#write 'Yes' in line 'Generated' of excel
$Obj.Generate="YES"
#run 'dotnet msbuild'
dotnet restore
$buildString = dotnet msbuild |Out-string
$isBuildSuccess = $buildString.contains("): error")
#if not exist then write 'Yes' in line 'Generated' of excel
if(!$isBuildSuccess)
{
#write 'Yes' in line 'Build' of excel
$Obj.Build="YES"
}else
{
#write 'NO' in line 'Build' of excel
$Obj.Build="NO"
dotnet msbuild > C:\AME\ErrorLogs\$currentpath-Build.log
}
}else
{
#write 'NO' in line 'Generated' of excel
$Obj.Generate="NO"
#log
dotnet msbuild /t:GenerateCode > C:\AME\ErrorLogs\$currentpath-generate.log
}
cd ../../../../../..
}
return $Obj
}
#excel软件本身
$Excel=New-Object -ComObject "Excel.Application"
#打开excel文件
$Workbook=$Excel.Workbooks.Open($file)
#选中工作表
$Sheet = $Workbook.Worksheets.Item('generator-v0326')
#添加工作表并重命名为当前日期
$newSheet = $Workbook.Worksheets.Add()
$newSheet.Name = "generator-v$(Get-date -Format 'MMdd')"
#初始化第一行
$newSheet.Cells.Item(1,1) = 'Service Name'
$newSheet.Cells.Item(1,2) = 'Has Spec Configuration'
$newSheet.Cells.Item(1,3) = 'Can Generate'
$newSheet.Cells.Item(1,4) = 'Can Build'
#excel是否可见
$Excel.visible=$true
#excel内容变更时,警告是否可见
$Excel.displayAlerts=$true
$Row=2
$hasSpecConfiguration=$Null
$generateMessage=$Null
$buildMessage=$Null
do {
#循环获取A2~A100单元格的内容
$serviceName=$Sheet.Range("A$Row").Text
if ($serviceName) {
#调用方法,获取执行结果返回值
$message = "what"| Select-Object -Property HasSpecConfiguration,Generate,Build
$message = AutoTextFunction($serviceName)
if($message.HasSpecConfiguration){
$hasSpecConfiguration=$message.HasSpecConfiguration
}else{
$hasSpecConfiguration=$Null
}
if($message.Generate){
$generateMessage=$message.Generate
}else{
$generateMessage=$Null
}
if($message.Build){
$buildMessage=$message.Build
}
else{
$buildMessage=$Null
}
#添加serviceName
$newSheet.Cells.Item($Row,1) = $serviceName
#修改单元格B2~B101的内容
$newSheet.Cells.Item($Row,2) = $hasSpecConfiguration
#修改单元格C2~C101的内容
$newSheet.Cells.Item($Row,3) = $generateMessage
#如果$generateMessage的值是no,则改变单元格颜色为 红
if($generateMessage -eq "NO"){
$newSheet.cells.item($Row,3).Interior.ColorIndex = 3
}
#修改单元格D2~D101的内容
$newSheet.Cells.Item($Row,4) = $buildMessage
#如果$buildMessage的值是no,则改变单元格颜色为 黄
if($buildMessage -eq "NO"){
$newSheet.cells.item($Row,4).Interior.ColorIndex = 6
}
}
$Row++
} While ($Row -le 101)
$Workbook.Close()
$Excel.Quit()
Write-Verbose "Finished"