Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 3176509

Browse files
committed
add the validation and latest version scripts
1 parent 0700b44 commit 3176509

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

scripts/getLatestVersion.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.Synopsis
6+
Retrieve the latest version of the library
7+
.Description
8+
Retrieves the latest version specified in the Gradle.Properties file
9+
Uses the retrieved values to update the enviornment variable VERSION_STRING
10+
#>
11+
12+
.Parameter propertiesPath
13+
14+
Param(
15+
[parameter(Mandatory = $true)]
16+
[string]$propertiesPath,
17+
)
18+
19+
#Retrieve the current version from the Gradle.Properties file given the specified path
20+
$file = get-item $propertiesPath
21+
$findVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2
22+
$findVersions = $findVersions -split "`r`n"
23+
24+
$majorVersion = $findVersions[0].Substring($findVersions[0].Length-1)
25+
$minorVersion = $findVersions[1].Substring($findVersions[1].Length-1)
26+
$patchVersion = $findVersions[2].Substring($findVersions[2].Length-1)
27+
$version = "$majorVersion.$minorVersion.$patchVersion"
28+
29+
#Update the VERSION_STRING env variable and inform the user
30+
Write-Host "##vso[task.setVariable variable=VERSION_STRING]$($version)";
31+
Write-Host "Updated the VERSION_STRING enviornment variable with the current Gradle.Properties, $version"

scripts/validateMavenVersion.ps1

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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-Auth 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+
#If the api calls return empty then this library cannot be compared to the online versions
47+
#may proceed with the pull request
48+
if(($mavenVersion -eq $null) -and ($bintrayVersion -eq $null))
49+
{
50+
Write-Information "This package does not exist yet in the online repository, therefore there are no versions to compare."
51+
return
52+
}
53+
54+
#Inform host of current Maven and Bintray versions
55+
Write-Host 'The current version in the Maven central repository is:' $mavenVersion
56+
Write-Host 'The current version in the Bintray central repository is:' $bintrayVersion
57+
58+
#Warn in case Maven and Bintray versions are not the same.
59+
if($mavenVersion -ne $bintrayVersion){
60+
Write-Warning "The current Maven and Bintray versions are not the same"
61+
}
62+
#Success if Local version has been updated, Error otherwise.
63+
if($localVersion -gt $bintrayVersion){
64+
Write-Host "The current pull request is of a greater version"
65+
}
66+
else{
67+
Write-Error "The current local version is not updated. Please update the local version in the Gradle.Properties file."
68+
}

0 commit comments

Comments
 (0)