|
| 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 | +.Parameter propertiesPath |
| 13 | +#> |
| 14 | + |
| 15 | + |
| 16 | +Param( |
| 17 | + [string]$propertiesPath |
| 18 | +) |
| 19 | + |
| 20 | +#Find the local version from the Gradle.Properties file |
| 21 | +if($propertiesPath -eq "" -or $null -eq $propertiesPath) { |
| 22 | + $propertiesPath = Join-Path -Path $PSScriptRoot -ChildPath "../gradle.properties" |
| 23 | +} |
| 24 | +$file = get-item $propertiesPath |
| 25 | +$findLocalVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2 |
| 26 | +$findLocalVersions = $findLocalVersions -split "`r`n" |
| 27 | +$packageName = ($file | Select-String -Pattern "mavenArtifactId").Line.Split("=")[1].Trim() |
| 28 | + |
| 29 | +$localMajor = $findLocalVersions[0].Substring($findLocalVersions[0].Length-1) |
| 30 | +$localMinor = $findLocalVersions[1].Substring($findLocalVersions[1].Length-1) |
| 31 | +$localPatch = $findLocalVersions[2].Substring($findLocalVersions[2].Length-1) |
| 32 | +$localVersion = [version]"$localMajor.$localMinor.$localPatch" |
| 33 | + |
| 34 | +#Set Web Client and retrieve Maven and Bintray versions from their respective repos. |
| 35 | +$web_client = New-Object System.Net.WebClient |
| 36 | + |
| 37 | +$mavenAPIurl = "https://search.maven.org/solrsearch/select?q=$packageName&rows=20&wt=json" |
| 38 | +$jsonResult = $web_client.DownloadString($mavenAPIurl) | ConvertFrom-Json |
| 39 | +$mavenVersion = [version]$jsonResult.response.docs.latestVersion |
| 40 | + |
| 41 | +$bintrayAPIurl = "https://api.bintray.com/search/packages?name=$packageName" |
| 42 | +$jsonResult = $web_client.DownloadString($bintrayAPIurl) | ConvertFrom-Json |
| 43 | +$bintrayVersion = [version]$jsonResult.latest_version |
| 44 | + |
| 45 | +#If the api calls return empty then this library cannot be compared to the online versions |
| 46 | +#may proceed with the pull request |
| 47 | +if(($mavenVersion -eq $null) -and ($bintrayVersion -eq $null)) |
| 48 | +{ |
| 49 | + Write-Information "This package does not exist yet in the online repository, therefore there are no versions to compare." |
| 50 | + return |
| 51 | +} |
| 52 | + |
| 53 | +#Inform host of current Maven and Bintray versions |
| 54 | +Write-Host 'The current version in the Maven central repository is:' $mavenVersion |
| 55 | +Write-Host 'The current version in the Bintray central repository is:' $bintrayVersion |
| 56 | + |
| 57 | +#Warn in case Maven and Bintray versions are not the same. |
| 58 | +if($mavenVersion -ne $bintrayVersion){ |
| 59 | + Write-Warning "The current Maven and Bintray versions are not the same" |
| 60 | +} |
| 61 | +#Success if Local version has been updated, Error otherwise. |
| 62 | +if($localVersion -gt $bintrayVersion -and $localVersion -gt $mavenVersion){ |
| 63 | + Write-Host "The current pull request is of a greater version" |
| 64 | +} |
| 65 | +else{ |
| 66 | + Write-Error "The current local version is not updated. Please update the local version in the Gradle.Properties file." |
| 67 | +} |
0 commit comments