1+ # Copyright (c) Microsoft Corporation. All rights reserved.
2+ # Licensed under the MIT License.
3+
4+ <#
5+ . Synopsis
6+ Ensure the maven version is updated in the case that the pull request is
7+ to the main/master branch of the repo.
8+ . Description
9+ Retrieves the local, Maven, and Bintray versions of the Java-Core build.
10+ Checks that the Maven and Bintray versions are aligned, trigger warning if not.
11+ Checks that the current local version is greater than those currently deployed.
12+ #>
13+
14+ .Parameter packageName
15+ .Parameter propertiesPath
16+
17+ Param (
18+ [parameter (Mandatory = $true )]
19+ [string ]$packageName ,
20+
21+ [parameter (Mandatory = $true )]
22+ [string ]$propertiesPath
23+ )
24+
25+ # Find the local version from the Gradle.Properties file
26+ $file = get-item $propertiesPath
27+ $findLocalVersions = $file | Select-String - Pattern " mavenMajorVersion" - Context 0 , 2
28+ $findLocalVersions = $findLocalVersions -split " `r`n "
29+
30+ $localMajor = $findLocalVersions [0 ].Substring($findLocalVersions [0 ].Length- 1 )
31+ $localMinor = $findLocalVersions [1 ].Substring($findLocalVersions [1 ].Length- 1 )
32+ $localPatch = $findLocalVersions [2 ].Substring($findLocalVersions [2 ].Length- 1 )
33+ $localVersion = [version ]" $localMajor .$localMinor .$localPatch "
34+
35+ # Set Web Client and retrieve Maven and Bintray versions from their respective repos.
36+ $web_client = New-Object System.Net.WebClient
37+
38+ $mavenAPIurl = " https://search.maven.org/solrsearch/select?q=$packageName &rows=20&wt=json"
39+ $jsonResult = $web_client.DownloadString ($mavenAPIurl ) | ConvertFrom-Json
40+ $mavenVersion = [version ]$jsonResult.response.docs.latestVersion
41+
42+ $bintrayAPIurl = " https://api.bintray.com/search/packages?name=$packageName "
43+ $jsonResult = $web_client.DownloadString ($bintrayAPIurl ) | ConvertFrom-Json
44+ $bintrayVersion = [version ]$jsonResult.latest_version
45+
46+ # Inform host of current Maven and Bintray versions
47+ write-host ' The current version in the Maven central repository is:' $mavenVersion
48+ write-host ' The current version in the Bintray central repository is:' $bintrayVersion
49+
50+ # Warn in case Maven and Bintray versions are not the same.
51+ if ($mavenVersion -ne $bintrayVersion ){
52+ Write-Warning " The current Maven and Bintray versions are not the same"
53+ }
54+ # Success if Local version has been updated, Error otherwise.
55+ if ($localVersion -gt $bintrayVersion ){
56+ Write-Host " The current pull request is of a greater version"
57+ }
58+ else {
59+ Write-Error " The current local version is not updated. Please update the local version in the Gradle.Properties file."
60+ }
0 commit comments