This repository was archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvalidateMavenVersion.ps1
More file actions
59 lines (48 loc) · 2.2 KB
/
validateMavenVersion.ps1
File metadata and controls
59 lines (48 loc) · 2.2 KB
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.Synopsis
Ensure the maven version is updated in the case that the pull request is
to the main/master branch of the repo.
.Description
Retrieves the local, and Maven versions of the Java-Auth build.
Checks that the Maven versions are aligned, trigger warning if not.
Checks that the current local version is greater than those currently deployed.
#>
.Parameter packageName
.Parameter propertiesPath
Param(
[parameter(Mandatory = $true)]
[string]$packageName,
[parameter(Mandatory = $true)]
[string]$propertiesPath
)
#Find the local version from the Gradle.Properties file
$file = get-item $propertiesPath
$findLocalVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2
$findLocalVersions = $findLocalVersions -split "`r`n"
$localMajor = $findLocalVersions[0].Substring($findLocalVersions[0].Length-1)
$localMinor = $findLocalVersions[1].Substring($findLocalVersions[1].Length-1)
$localPatch = $findLocalVersions[2].Substring($findLocalVersions[2].Length-1)
$localVersion = [version]"$localMajor.$localMinor.$localPatch"
#Set Web Client and retrieve Maven versions from their respective repos.
$web_client = New-Object System.Net.WebClient
$mavenAPIurl = "https://search.maven.org/solrsearch/select?q=$packageName&rows=20&wt=json"
$jsonResult = $web_client.DownloadString($mavenAPIurl) | ConvertFrom-Json
$mavenVersion = [version]$jsonResult.response.docs.latestVersion
#If the api calls return empty then this library cannot be compared to the online versions
#may proceed with the pull request
if($mavenVersion -eq $null)
{
Write-Information "This package does not exist yet in the online repository, therefore there are no versions to compare."
return
}
#Inform host of current Maven version
Write-Host 'The current version in the Maven central repository is:' $mavenVersion
#Success if Local version has been updated, Error otherwise.
if($localVersion -gt $mavenVersion){
Write-Host "The current pull request is of a greater version"
}
else{
Write-Error "The current local version is not updated. Please update the local version in the Gradle.Properties file."
}