Skip to content

Commit ad035d1

Browse files
committed
Updated script file reflecting the feedback and requested fixes
1 parent 3758106 commit ad035d1

File tree

1 file changed

+24
-42
lines changed

1 file changed

+24
-42
lines changed

Scripts/validateMavenVersion.ps1

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Ensure the maven version is updated in the case that the pull request is
77
to the main/master branch of the repo.
88
.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.
912
#>
1013

1114
.Parameter packageName
@@ -19,60 +22,39 @@ Param(
1922
[string]$propertiesPath
2023
)
2124

25+
#Find the local version from the Gradle.Properties file
2226
$file = get-item $propertiesPath
23-
$findVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2
24-
$localVersions = $findVersions -split "`r`n"
27+
$findLocalVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2
28+
$findLocalVersions = $findLocalVersions -split "`r`n"
2529

26-
$localMajorVersion = $localVersions[0]
27-
$localMajorVersion = [int]$localMajorVersion.Substring($localMajorVersion.Length-1)
28-
29-
$localMinorVersion = $localVersions[1]
30-
$localMinorVersion = [int]$localMinorVersion.Substring($localMinorVersion.Length-1)
31-
32-
$localPatchVersion = $localVersions[2]
33-
$localPatchVersion = [int]$localPatchVersion.Substring($localPatchVersion.Length-1)
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"
3434

35+
#Set Web Client and retrieve Maven and Bintray versions from their respective repos.
3536
$web_client = New-Object System.Net.WebClient
3637

37-
$mavenAPIurl = 'https://search.maven.org/solrsearch/select?q=$packageName&rows=20&wt=json'
38+
$mavenAPIurl = "https://search.maven.org/solrsearch/select?q=$packageName&rows=20&wt=json"
3839
$jsonResult = $web_client.DownloadString($mavenAPIurl) | ConvertFrom-Json
39-
$mavenVersions = $jsonResult.response.docs.v
40-
$mavenSplit = $mavenVersions.split(".")
41-
$mavenMajorVersion = [int]$mavenSplit[0]
42-
$mavenMinorVersion = [int]$mavenSplit[1]
43-
$mavenPatchVersion = [int]$mavenSplit[2]
40+
$mavenVersion = [version]$jsonResult.response.docs.latestVersion
4441

45-
$bintrayAPIurl = 'https://api.bintray.com/search/packages?name=$packageName'
42+
$bintrayAPIurl = "https://api.bintray.com/search/packages?name=$packageName"
4643
$jsonResult = $web_client.DownloadString($bintrayAPIurl) | ConvertFrom-Json
47-
$bintrayVersions = $jsonResult.latest_version
48-
$bintraySplit = $bintrayVersions.split(".")
49-
$bintrayMajorVersion = [int]$bintraySplit[0]
50-
$bintrayMinorVersion = [int]$bintraySplit[1]
51-
$bintrayPatchVersion = [int]$bintraySplit[2]
44+
$bintrayVersion = [version]$jsonResult.latest_version
5245

53-
write-host 'The current version in the Maven central repository is:' $mavenVersions
54-
write-host 'The current version in the Bintray central repository is:' $bintrayVersions
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
5549

56-
if(($bintrayMinorVersion -ne $mavenMinorVersion) -OR
57-
($bintrayMajorversion -ne $mavenMajorVersion) -OR
58-
($bintraypatchversion -ne $mavenpatchversion)){
50+
#Warn in case Maven and Bintray versions are not the same.
51+
if($mavenVersion -ne $bintrayVersion){
5952
Write-Warning "The current Maven and Bintray versions are not the same"
6053
}
61-
62-
if(($localMajorVersion -gt $bintrayMajorVersion) -OR
63-
($localMinorVersion -gt $bintrayMinorVersion) -OR
64-
($localPatchVersion -gt $bintrayPatchVersion)){
54+
#Success if Local version has been updated, Error otherwise.
55+
if($localVersion -gt $bintrayVersion){
6556
Write-Host "The current pull request is of a greater version"
6657
}
6758
else{
68-
Write-Error "The local version has not been updated or is of an earlier version than that on the remote repository"
69-
}
70-
71-
72-
73-
74-
75-
76-
77-
78-
59+
Write-Error "The current local version is not updated. Please update the local version in the Gradle.Properties file."
60+
}

0 commit comments

Comments
 (0)