-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.ps1
213 lines (182 loc) · 8.62 KB
/
build.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
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
# A function that checks exit codes and fails script if an error is found
function StopOnFailedExecution {
if ($LastExitCode)
{
exit $LastExitCode
}
}
# Clone and install function maven archetype
git clone https://github.com/Microsoft/azure-maven-archetypes.git -b develop
Push-Location -Path "./azure-maven-archetypes/azure-functions-archetype" -StackName libraryDir
Write-Host "Build and install azure-maven-archetypes"
cmd.exe /c '.\..\..\mvnBuildSkipTests.bat'
StopOnFailedExecution
Pop-Location -StackName "libraryDir"
$archetypePom = Get-Content ".\azure-maven-archetypes\azure-functions-archetype\pom.xml" -Raw
$archetypePom -match "<version>(.*)</version>"
$archetypeVersion = $matches[1]
Write-Host "archetypeVersion: " $archetypeVersion
# Clone and install function maven plugin
git clone https://github.com/Microsoft/azure-maven-plugins.git -b develop
Push-Location -Path "./azure-maven-plugins" -StackName libraryDir
Write-Host "Build and install azure-functions-maven-plugins"
cmd.exe /c '.\..\mvnBuildFunctionPluginsSkipTests.bat'
StopOnFailedExecution
Pop-Location -StackName "libraryDir"
$pluginPom = Get-Content ".\azure-maven-plugins\azure-functions-maven-plugin\pom.xml" | where {$_ -ne ""}
$nospace = $pluginPom -replace '\s'
$versions =$nospace -match "<version>(.*)<\/version>"
$start = $versions[1].IndexOf('>')+1
$end = $versions[1].LastIndexOf('<')
$substringLen = $end-$start
$pluginVersion = $versions[1].substring($start, $substringLen)
Write-Host "pluginPomVersion: " $pluginVersion
if ([string]::IsNullOrEmpty($pluginVersion))
{
exit -1
}
StopOnFailedExecution
# Get azure-functions-core-library and azure-functions-spi
Write-Host "Build and install azure-functions-java-core-library and azure-functions-spi"
cmd.exe /c '.\mvnBuild.bat'
StopOnFailedExecution
$coreLibraryPom = Get-Content "azure-functions-java-core-library\pom.xml" -Raw
$coreLibraryPom -match "<version>(.*)</version>"
$coreLibraryVersion = $matches[1]
Write-Host "coreLibraryVersion: " $coreLibraryVersion
$spiLibraryPom = Get-Content "azure-functions-java-spi\pom.xml" -Raw
$spiLibraryPom -match "<version>(.*)</version>"
$spiLibraryVersion = $matches[1]
Write-Host "spiLibraryVersion: " $spiLibraryVersion
# Get azure-functions-library
git clone https://github.com/Azure/azure-functions-java-library.git -b dev
Push-Location -Path "./azure-functions-java-library" -StackName libraryDir
Write-Host "Updating azure-functions-java-library to use current version of azure-functions-java-core-library"
cmd.exe /c .\..\updateVersions.bat $coreLibraryVersion
Write-Host "Building azure-functions-java-library"
cmd.exe /c '.\mvnBuild.bat'
StopOnFailedExecution
$libraryPom = Get-Content "pom.xml" -Raw
$libraryPom -match "<version>(.*)</version>"
$libraryVersion = $matches[1]
Write-Host "libraryVersion: " $libraryVersion
Pop-Location -StackName "libraryDir"
# Download azure-functions-core-tools
$FUNC_RUNTIME_VERSION = '4'
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant()
$os = if ($IsWindows) { "win" } else { if ($IsMacOS) { "osx" } else { "linux" } }
$currDir = Get-Location
$skipCliDownload = $false
if($args[0])
{
$skipCliDownload = $args[0]
}
Write-Host "skipCliDownload" $skipCliDownload
if(!$skipCliDownload)
{
Write-Host "Deleting Functions Core Tools if exists...."
Remove-Item -Force ./Azure.Functions.Cli.zip -ErrorAction Ignore
Remove-Item -Recurse -Force ./Azure.Functions.Cli -ErrorAction Ignore
Write-Host "Downloading Functions Core Tools...."
Invoke-RestMethod -Uri "https://functionsclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest/version.txt" -OutFile version.txt
Write-Host "Using Functions Core Tools version: $(Get-Content -Raw version.txt)"
Remove-Item version.txt
$url = "https://functionsclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest/Azure.Functions.Cli.$os-$arch.zip"
$output = "$currDir\Azure.Functions.Cli.zip"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
Write-Host "Extracting Functions Core Tools...."
Expand-Archive ".\Azure.Functions.Cli.zip" -DestinationPath ".\Azure.Functions.Cli"
}
$Env:Path = $Env:Path+";$currDir\Azure.Functions.Cli"
# Clone and build azure-functions-java-worker
git clone https://github.com/azure/azure-functions-java-worker -b dev
Push-Location -Path "./azure-functions-java-worker" -StackName libraryDir
Write-Host "Updating azure-functions-java-worker to use current version of the java core library"
cmd.exe /c .\..\updateVersions.bat $coreLibraryVersion
Write-Host "Building azure-functions-java-worker"
cmd.exe /c '.\mvnBuild.bat'
StopOnFailedExecution
Pop-Location -StackName "libraryDir"
# Update core tools with the new Java worker
Write-Host "Replacing Java worker binaries in the Core Tools..."
Get-ChildItem -Path "./azure-functions-java-worker/target/*" -Include 'azure*' -Exclude '*shaded.jar','*tests.jar' | ForEach-Object {
Copy-Item $_.FullName "./Azure.Functions.Cli/workers/java/azure-functions-java-worker.jar" -Force -Verbose
}
Copy-Item -Path "./azure-functions-java-worker/annotationLib" -Destination "./Azure.Functions.Cli/workers/java/annotationLib" -Recurse -Verbose
Copy-Item -Path ".\Azure.Functions.Cli" -Destination ".\azure-functions-java-worker\Azure.Functions.Cli" -Recurse
# Updating end to end tests with the new library
Push-Location -Path "./azure-functions-java-worker/endtoendtests" -StackName libraryDir
Write-Host "Updating azure-functions-java-worker endtoendtests to use current version of the java core library"
cmd.exe /c .\..\..\updateVersions.bat $coreLibraryVersion $libraryVersion $pluginVersion
Write-Host "Building azure-functions-java-worker end to end tests"
cmd.exe /c '.\..\..\mvnBuild.bat'
StopOnFailedExecution
Pop-Location -StackName "libraryDir"
$ApplicationInsightsAgentVersion = '3.5.2'
$ApplicationInsightsAgentFilename = "applicationinsights-agent-${ApplicationInsightsAgentVersion}.jar"
$ApplicationInsightsAgentUrl = "https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion}/${ApplicationInsightsAgentFilename}"
# Download application insights agent from maven central
$ApplicationInsightsAgentFile = "$currDir/$ApplicationInsightsAgentFilename"
# local testing cleanup
if (Test-Path -Path $ApplicationInsightsAgentFile) {
Remove-Item -Path $ApplicationInsightsAgentFile
}
# local testing cleanup
$oldOutput = [System.IO.Path]::Combine($currDir, "agent")
if (Test-Path -Path $oldOutput) {
Remove-Item -Path $oldOutput -Recurse
}
# local testing cleanup
$oldExtract = [System.IO.Path]::Combine($currDir, "extract")
if (Test-Path -Path $oldExtract) {
Remove-Item -Path $oldExtract -Recurse
}
echo "Start downloading '$ApplicationInsightsAgentUrl' to '$currDir'"
try {
Invoke-WebRequest -Uri $ApplicationInsightsAgentUrl -OutFile $ApplicationInsightsAgentFile
} catch {
echo "An error occurred. Download fails" $ApplicationInsightsAgentFile
echo "Exiting"
exit 1
}
if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) {
echo "$ApplicationInsightsAgentFile do not exist."
exit 1
}
$extract = new-item -type directory -force $currDir\extract
if (-not(Test-Path -Path $extract)) {
echo "Fail to create a new directory $extract"
exit 1
}
echo "Start extracting content from $ApplicationInsightsAgentFilename to extract folder"
cd -Path $extract -PassThru
Start-Process -FilePath "cmd" -ArgumentList "/c jar xf $ApplicationInsightsAgentFile" -Wait
cd $currDir
echo "Done extracting"
echo "Unsign $ApplicationInsightsAgentFilename"
Remove-Item $extract\META-INF\MSFTSIG.*
$manifest = "$extract\META-INF\MANIFEST.MF"
$newContent = (Get-Content -Raw $manifest | Select-String -Pattern '(?sm)^(.*?\r?\n)\r?\n').Matches[0].Groups[1].Value
Set-Content -Path $manifest $newContent
Remove-Item $ApplicationInsightsAgentFile
if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) {
echo "Delete the original $ApplicationInsightsAgentFilename successfully"
} else {
echo "Fail to delete original source $ApplicationInsightsAgentFilename"
exit 1
}
$agent = new-item -type directory -force $currDir/agent
$filename = "applicationinsights-agent.jar"
$result = [System.IO.Path]::Combine($agent, $filename)
echo "re-jar $filename"
cd -Path $extract -PassThru
jar cfm $result META-INF/MANIFEST.MF .
if (-not(Test-Path -Path $result)) {
echo "Fail to re-archive $filename"
exit 1
}
Write-Host "Creating the functions.codeless file"
New-Item -path $currDir\agent -type file -name "functions.codeless"
Write-Host "Copying the unsigned Application Insights Agent to worker directory"
Copy-Item "$currDir/agent" "$currDir/azure-functions-java-worker/Azure.Functions.Cli/workers/java" -Recurse -Verbose -Force