Skip to content

Commit 93edbfc

Browse files
Merge pull request #32 from microsoftgraph/rsh/prValidate
Rsh/pr validate
2 parents 16ee86b + ad035d1 commit 93edbfc

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

.azure-pipelines/prValidate.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Starter pipeline
2+
# Start with a minimal pipeline that you can customize to build and deploy your code.
3+
# Add steps that build, run tests, deploy, and more:
4+
# https://aka.ms/yaml
5+
6+
7+
pr:
8+
branches:
9+
include:
10+
- master
11+
- main
12+
- dev
13+
paths:
14+
exclude:
15+
- .azure-pipelines
16+
- .gradle/wrapper
17+
- .gitignore
18+
- CONTRIBUTING.md
19+
- LICENSE
20+
- THIRD PARTY NOTICES
21+
- gradle.properties
22+
- gradlew
23+
- gradlew.bat
24+
- readme.md
25+
- settings.gradle
26+
27+
trigger: none # disable triggers based on commits.
28+
29+
variables:
30+
PACKAGE_NAME: 'microsoft-graph-core'
31+
PROPERTIES_PATH: '.\gradle.properties'
32+
33+
pool:
34+
vmImage: windows-latest
35+
36+
steps:
37+
- checkout: self
38+
clean: true
39+
fetchDepth: 1
40+
41+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
42+
displayName: 'Run CredScan'
43+
inputs:
44+
debugMode: false
45+
46+
- task: PowerShell@2
47+
condition: and(failed(), eq(variables['Build.SourceBranchName'], 'dev'))
48+
inputs:
49+
filePath: '$(System.DefaultWorkingDirectory)\Scripts\validateMavenVersion.ps1'
50+
pwsh: true
51+
arguments: '-packageName "$(PACKAGE_NAME)" -propertiesPath "$(PROPERTIES_PATH)"'
52+
53+
- task: Gradle@2
54+
inputs:
55+
gradleWrapperFile: 'gradlew'
56+
tasks: 'build'
57+
publishJUnitResults: true
58+
testResultsFiles: '**/TEST-*.xml'
59+
javaHomeOption: 'JDKVersion'
60+
sonarQubeRunAnalysis: false
61+
62+
63+
- task: YodLabs.O365PostMessage.O365PostMessageBuild.O365PostMessageBuild@0
64+
displayName: 'Graph Client Tooling pipeline fail notification'
65+
inputs:
66+
addressType: serviceEndpoint
67+
serviceEndpointName: 'microsoftgraph pipeline status'
68+
title: '$(Build.DefinitionName) failure notification'
69+
text: 'This pipeline has failed. View the build details for further information. This is a blocking failure. '
70+
condition: and(failed(), ne(variables['Build.Reason'], 'Manual'))
71+
enabled: true

Scripts/validateMavenVersion.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
#>
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+
#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
49+
50+
#Warn in case Maven and Bintray versions are not the same.
51+
if($mavenVersion -ne $bintrayVersion){
52+
Write-Warning "The current Maven and Bintray versions are not the same"
53+
}
54+
#Success if Local version has been updated, Error otherwise.
55+
if($localVersion -gt $bintrayVersion){
56+
Write-Host "The current pull request is of a greater version"
57+
}
58+
else{
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)