diff --git a/.azure-pipelines/buildAndPackage.yml b/.azure-pipelines/buildAndPackage.yml index ad8e81eea..d398126dc 100644 --- a/.azure-pipelines/buildAndPackage.yml +++ b/.azure-pipelines/buildAndPackage.yml @@ -23,6 +23,7 @@ trigger: - gradlew.bat - readme.md - settings.gradle + - Scripts/* pr: none @@ -82,6 +83,7 @@ steps: settings.gradle gradle.properties **/gradle/wrapper/* + Scripts/getLatestVersion.ps1 TargetFolder: '$(Build.ArtifactStagingDirectory)/' - task: PublishBuildArtifacts@1 diff --git a/.azure-pipelines/prValidate.yml b/.azure-pipelines/prValidate.yml index cdd049d0e..64bbf4c0b 100644 --- a/.azure-pipelines/prValidate.yml +++ b/.azure-pipelines/prValidate.yml @@ -1,4 +1,8 @@ -# Build and test Java Core to make sure a valid pull request is being made +#Copyright (c) Microsoft Corporation. All rights reserved. +#Licensed under the MIT License. +#Build and test Java Core to make sure a valid pull request is being made +#Validate that the versions dont conflict with those online in case a pull request is made to main or master + pr: branches: include: @@ -18,6 +22,7 @@ pr: - gradlew.bat - readme.md - settings.gradle + - Scripts/* trigger: none # disable triggers based on commits. @@ -62,4 +67,4 @@ steps: title: '$(Build.DefinitionName) failure notification' text: 'This pipeline has failed. View the build details for further information. This is a blocking failure. ' condition: and(failed(), ne(variables['Build.Reason'], 'Manual')) - enabled: true \ No newline at end of file + enabled: true diff --git a/Scripts/getLatestVersion.ps1 b/Scripts/getLatestVersion.ps1 new file mode 100644 index 000000000..515408f88 --- /dev/null +++ b/Scripts/getLatestVersion.ps1 @@ -0,0 +1,31 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Retrieve the latest version of the library +.Description + Retrieves the latest version specified in the Gradle.Properties file + Uses the retrieved values to update the enviornment variable VERSION_STRING +#> + +.Parameter propertiesPath + +Param( + [parameter(Mandatory = $true)] + [string]$propertiesPath, +) + +#Retrieve the current version from the Gradle.Properties file given the specified path +$file = get-item $propertiesPath +$findVersions = $file | Select-String -Pattern "mavenMajorVersion" -Context 0,2 +$findVersions = $findVersions -split "`r`n" + +$majorVersion = $findVersions[0].Substring($findVersions[0].Length-1) +$minorVersion = $findVersions[1].Substring($findVersions[1].Length-1) +$patchVersion = $findVersions[2].Substring($findVersions[2].Length-1) +$version = "$majorVersion.$minorVersion.$patchVersion" + +#Update the VERSION_STRING env variable and inform the user +Write-Host "##vso[task.setVariable variable=VERSION_STRING]$($version)"; +Write-Host "Updated the VERSION_STRING enviornment variable with the current Gradle.Properties, $version" \ No newline at end of file diff --git a/Scripts/validateMavenVersion.ps1 b/Scripts/validateMavenVersion.ps1 index 282567a45..f591d5e1e 100644 --- a/Scripts/validateMavenVersion.ps1 +++ b/Scripts/validateMavenVersion.ps1 @@ -43,9 +43,17 @@ $bintrayAPIurl = "https://api.bintray.com/search/packages?name=$packageName" $jsonResult = $web_client.DownloadString($bintrayAPIurl) | ConvertFrom-Json $bintrayVersion = [version]$jsonResult.latest_version +#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) -and ($bintrayVersion -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 and Bintray versions -write-host 'The current version in the Maven central repository is:' $mavenVersion -write-host 'The current version in the Bintray central repository is:' $bintrayVersion +Write-Host 'The current version in the Maven central repository is:' $mavenVersion +Write-Host 'The current version in the Bintray central repository is:' $bintrayVersion #Warn in case Maven and Bintray versions are not the same. if($mavenVersion -ne $bintrayVersion){