Skip to content

Commit 30c95e7

Browse files
authored
Merge pull request #2402 from microsoftgraph/ci/migration-to-esrp-release
ci: draft migration to ESRP release
2 parents 35f2d91 + 4cdad79 commit 30c95e7

File tree

5 files changed

+287
-2
lines changed

5 files changed

+287
-2
lines changed

.azure-pipelines/ci-build.yml

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
5+
6+
trigger:
7+
tags:
8+
include:
9+
- "v*"
10+
branches:
11+
include:
12+
- main
13+
14+
parameters:
15+
- name: previewBranch
16+
type: string
17+
default: "refs/heads/main"
18+
19+
resources:
20+
repositories:
21+
- repository: 1ESPipelineTemplates
22+
type: git
23+
name: 1ESPipelineTemplates/1ESPipelineTemplates
24+
ref: refs/tags/release
25+
26+
extends:
27+
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
28+
parameters:
29+
sdl:
30+
sourceAnalysisPool:
31+
name: Azure-Pipelines-1ESPT-ExDShared
32+
os: windows
33+
image: windows-latest
34+
35+
stages:
36+
- stage: build
37+
jobs:
38+
- job: build
39+
pool:
40+
name: Azure-Pipelines-1ESPT-ExDShared
41+
os: linux
42+
image: ubuntu-latest
43+
#TODO maybe missing template context with sdl baselines?
44+
steps:
45+
- checkout: self
46+
persistCredentials: true
47+
48+
- task: JavaToolInstaller@1
49+
inputs:
50+
versionSpec: '21'
51+
jdkArchitectureOption: 'x64'
52+
jdkSourceOption: 'PreInstalled'
53+
54+
- task: DownloadSecureFile@1
55+
name: downloadLocalProperties
56+
inputs:
57+
secureFile: 'local.properties'
58+
59+
- task: DownloadSecureFile@1
60+
name: downloadSecringGpg
61+
inputs:
62+
secureFile: 'secring.gpg'
63+
64+
- pwsh: |
65+
Copy-Item $(downloadSecringGpg.secureFilePath) secring.gpg -Verbose
66+
Copy-Item $(downloadLocalProperties.secureFilePath) local.properties -Verbose
67+
displayName: Copy secring and 'local.properties'
68+
69+
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
70+
displayName: Publish to local Maven for verification
71+
# condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
72+
73+
# - script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true
74+
# displayName: Publish to local Maven for verification
75+
# condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
76+
77+
- script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
78+
displayName: Publish to local Maven ADO for ESRP
79+
# condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
80+
81+
# - script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true
82+
# displayName: Publish to local Maven ADO for ESRP
83+
# condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
84+
85+
- pwsh: |
86+
$contents = Get-Content gradle.properties -Raw
87+
$major = $contents | Select-String -Pattern 'mavenMajorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
88+
$minor = $contents | Select-String -Pattern 'mavenMinorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
89+
$patch = $contents | Select-String -Pattern 'mavenPatchVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
90+
# $snapshot_suffix = if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) { '' } else { '-SNAPSHOT' }
91+
$version = "$major.$minor.$patch$snapshot_suffix"
92+
echo "Current version is $version"
93+
echo "##vso[task.setvariable variable=PACKAGE_VERSION;]$version"
94+
displayName: Get current version
95+
name: GetVersion
96+
env:
97+
BRANCH_NAME: $(Build.SourceBranchName)
98+
99+
- pwsh: |
100+
.\scripts\validatePackageContents.ps1 -ArtifactId microsoft-graph -Version $(PACKAGE_VERSION) -ValidateMavenMetadata $false
101+
displayName: Inspect contents of local Maven cache
102+
103+
- pwsh: |
104+
.\scripts\zipPackageContent.ps1 -OutputDirectory $Env:OUTPUT_DIRECTORY -ArtifactId microsoft-graph -PackageSegment abstractions -Version $(PACKAGE_VERSION)
105+
echo "list of zips:"
106+
Get-ChildItem -Path $Env:OUTPUT_DIRECTORY -Filter "*.zip" | ForEach-Object { Write-Host $_.FullName }
107+
displayName: Zip contents of local Maven cache
108+
env:
109+
OUTPUT_DIRECTORY: $(Build.ArtifactStagingDirectory)
110+
111+
- task: 1ES.PublishPipelineArtifact@1
112+
displayName: "Publish Artifact: jars"
113+
inputs:
114+
artifactName: jars
115+
targetPath: "$(Build.ArtifactStagingDirectory)"
116+
117+
- stage: deploy
118+
# condition: and(or(contains(variables['build.sourceBranch'], 'refs/tags/v'), eq(variables['build.sourceBranch'], '${{ parameters.previewBranch }}')), succeeded())
119+
dependsOn: build
120+
jobs:
121+
- deployment: deploy_github
122+
condition: and(contains(variables['build.sourceBranch'], 'refs/tags/v'), succeeded())
123+
pool:
124+
name: Azure-Pipelines-1ESPT-ExDShared
125+
os: linux
126+
image: ubuntu-latest
127+
templateContext:
128+
type: releaseJob
129+
isProduction: true
130+
inputs:
131+
- input: pipelineArtifact
132+
artifactName: jars
133+
targetPath: "$(Pipeline.Workspace)"
134+
environment: kiota-github-releases
135+
strategy:
136+
runOnce:
137+
deploy:
138+
steps:
139+
- pwsh: |
140+
$zips = Get-ChildItem -Path "$(Pipeline.Workspace)" -Filter "*.zip"
141+
$zip = $zips | Select-Object -First 1
142+
$zipName = $zip.Name
143+
if ($zipName -match "\d+.\d+.\d+")
144+
{
145+
$version = $matches[0]
146+
echo "Current version is $version"
147+
echo "##vso[task.setvariable variable=artifactVersion;]$version"
148+
}
149+
else
150+
{
151+
Write-Error "No valid version found in zip file name."
152+
exit 1
153+
}
154+
155+
- pwsh: |
156+
$zips = Get-ChildItem -Path "$(Pipeline.Workspace)" -Filter "*.zip"
157+
foreach ($zip in $zips) {
158+
$targetPath = $zip.FullName.Replace(".zip", "")
159+
Expand-Archive -Path $zip.FullName -DestinationPath $targetPath
160+
Remove-Item -Path $zip.FullName -Force
161+
}
162+
displayName: Unzip artifacts
163+
164+
- task: GitHubRelease@1
165+
inputs:
166+
gitHubConnection: "microsoftkiota"
167+
tagSource: userSpecifiedTag
168+
tag: "v$(artifactVersion)"
169+
title: "v$(artifactVersion)"
170+
assets: |
171+
$(Pipeline.Workspace)/**/*.jar
172+
$(Pipeline.Workspace)/**/*.jar.md5
173+
$(Pipeline.Workspace)/**/*.jar.sha1
174+
$(Pipeline.Workspace)/**/*.jar.sha256
175+
$(Pipeline.Workspace)/**/*.jar.sha512
176+
$(Pipeline.Workspace)/**/*.jar.asc
177+
$(Pipeline.Workspace)/**/*.jar.asc.md5
178+
$(Pipeline.Workspace)/**/*.jar.asc.sha1
179+
$(Pipeline.Workspace)/**/*.jar.asc.sha256
180+
$(Pipeline.Workspace)/**/*.jar.asc.sha512
181+
$(Pipeline.Workspace)/**/*.pom
182+
$(Pipeline.Workspace)/**/*.pom.md5
183+
$(Pipeline.Workspace)/**/*.pom.sha1
184+
$(Pipeline.Workspace)/**/*.pom.sha256
185+
$(Pipeline.Workspace)/**/*.pom.sha512
186+
$(Pipeline.Workspace)/**/*.pom.asc
187+
$(Pipeline.Workspace)/**/*.pom.asc.md5
188+
$(Pipeline.Workspace)/**/*.pom.asc.sha1
189+
$(Pipeline.Workspace)/**/*.pom.asc.sha256
190+
$(Pipeline.Workspace)/**/*.pom.asc.sha512
191+
$(Pipeline.Workspace)/**/*.module
192+
$(Pipeline.Workspace)/**/*.module.md5
193+
$(Pipeline.Workspace)/**/*.module.sha1
194+
$(Pipeline.Workspace)/**/*.module.sha256
195+
$(Pipeline.Workspace)/**/*.module.sha512
196+
$(Pipeline.Workspace)/**/*.module.asc
197+
$(Pipeline.Workspace)/**/*.module.asc.md5
198+
$(Pipeline.Workspace)/**/*.module.asc.sha1
199+
$(Pipeline.Workspace)/**/*.module.asc.sha256
200+
$(Pipeline.Workspace)/**/*.module.asc.sha512
201+
202+
addChangeLog: false
203+
action: edit
204+
205+
- deployment: deploy_maven
206+
# snapshots are not supported by ESRP release for now, but they are planning to add support. When it happens, simply remove the condition
207+
# condition: and(contains(variables['build.sourceBranch'], 'refs/tags/v'), succeeded())
208+
pool:
209+
name: Azure-Pipelines-1ESPT-ExDShared
210+
os: linux
211+
image: ubuntu-latest
212+
templateContext:
213+
type: releaseJob
214+
isProduction: true
215+
inputs:
216+
- input: pipelineArtifact
217+
artifactName: jars
218+
targetPath: "$(Pipeline.Workspace)"
219+
dependsOn: []
220+
environment: maven_central
221+
strategy:
222+
runOnce:
223+
deploy:
224+
steps:
225+
- task: EsrpRelease@9
226+
inputs:
227+
connectedservicename: "Federated DevX ESRP Managed Identity Connection"
228+
usemanagedidentity: false
229+
keyvaultname: "akv-prod-eastus"
230+
authcertname: "ReferenceLibraryPrivateCert"
231+
signcertname: "ReferencePackagePublisherCertificate"
232+
clientid: "65035b7f-7357-4f29-bf25-c5ee5c3949f8"
233+
intent: "PackageDistribution"
234+
contenttype: "Maven"
235+
contentsource: "Folder"
236+
folderlocation: "$(Pipeline.Workspace)"
237+
waitforreleasecompletion: true
238+
owners: vibiret@microsoft.com
239+
approvers: mmainer@microsoft.com
240+
serviceendpointurl: "https://api.esrp.microsoft.com"
241+
mainpublisher: "ESRPRELPACMAN"
242+
domaintenantid: "cdc5aeea-15c5-4db6-b079-fcadd2505dc2"

.github/workflows/preview-and-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Maven Preview/Release and GitHub Release
22

3+
# TODO: remove the todo entries in build.gradle
4+
35
on:
46
push:
57
branches: [main]

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
id 'eclipse'
1313
id 'maven-publish'
1414
id 'signing'
15+
// TODO remove this dependency once we remove the GH WF
1516
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
1617
}
1718

@@ -79,8 +80,16 @@ publishing {
7980
}
8081
}
8182
}
83+
84+
repositories {
85+
maven {
86+
name = "ADO"
87+
url = layout.buildDirectory.dir("publishing-repository")
88+
}
89+
}
8290
}
8391

92+
// TODO remove this configuration once we remove the GH WF
8493
nexusPublishing {
8594
repositories {
8695
sonatype {

scripts/validatePackageContents.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ param(
33
[Parameter(Mandatory=$true)][string] $ArtifactId,
44
[Parameter(Mandatory=$true)][string] $Version,
55
[Parameter()][string] $GroupId = "com.microsoft.graph",
6-
[Parameter()][string] $MavenLocalCachePath = "~" + [System.IO.Path]::DirectorySeparatorChar + ".m2" + [System.IO.Path]::DirectorySeparatorChar + "repository"
6+
[Parameter()][string] $MavenLocalCachePath = "~" + [System.IO.Path]::DirectorySeparatorChar + ".m2" + [System.IO.Path]::DirectorySeparatorChar + "repository",
7+
[Parameter()][bool] $ValidateMavenMetadata = $true
78
)
89

910
$groupIdPath = $GroupId -replace "\.", [System.IO.Path]::DirectorySeparatorChar
@@ -48,7 +49,7 @@ foreach($file in $expectedFiles) {
4849
}
4950

5051
$mavenMetadataFiles = Get-ChildItem -Path $packageFullPath -Filter "maven-metadata*.xml"
51-
if($mavenMetadataFiles.Count -eq 0) {
52+
if($mavenMetadataFiles.Count -eq 0 -and $ValidateMavenMetadata -eq $true) {
5253
Write-Output "No maven-metadata*.xml files found in package."
5354
exit 1
5455
}

scripts/zipPackageContent.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Checks that expected files are present & have contents after the publish process to the local cache
2+
param(
3+
[Parameter(Mandatory=$true)][string] $ArtifactId,
4+
[Parameter(Mandatory=$true)][string] $PackageSegment,
5+
[Parameter(Mandatory=$true)][string] $Version,
6+
[Parameter(Mandatory=$true)][string] $OutputDirectory,
7+
[Parameter()][string] $GroupId = "com.microsoft.kiota",
8+
[Parameter()][string] $ComponentsSegment = "..\components",
9+
[Parameter()][string] $buildOutDir = "build\publishing-repository"
10+
)
11+
12+
#components\bundle\build\publishing-repository\com\microsoft\kiota\microsoft-kiota-bundle\1.8.5\
13+
14+
$groupIdPath = $GroupId -replace "\.", [System.IO.Path]::DirectorySeparatorChar
15+
$packageFullPath = Join-Path -Path $PSScriptRoot -ChildPath $ComponentsSegment -AdditionalChildPath $PackageSegment, $buildOutDir, $groupIdPath, $ArtifactId, $Version
16+
17+
Write-Output "---------------------------------------------------"
18+
Write-Output "Zipping package contents at $packageFullPath"
19+
20+
if(-not (Test-Path -Path $packageFullPath)) {
21+
Write-Output "Package not found in local cache."
22+
exit 1
23+
}
24+
25+
$outputFilePath = Join-Path -Path $OutputDirectory -ChildPath "$ArtifactId-$Version.zip"
26+
# removing any existing file
27+
Remove-Item -Path $outputFilePath -ErrorAction SilentlyContinue
28+
# removing any xml files that are not expected in ESRP release
29+
Compress-Archive -Path "$packageFullPath\*" -DestinationPath $outputFilePath
30+
31+
exit 0

0 commit comments

Comments
 (0)