From 62986e33e9e0bcddef213932fd8bb94f2e6062ec Mon Sep 17 00:00:00 2001 From: "Evans Aboge (from Dev Box)" Date: Thu, 30 Jan 2025 16:09:19 +0300 Subject: [PATCH 1/4] Add new acr pipeline --- .azure-pipelines/docker.yml | 154 ++++++++++++++++++++++++++++++++---- 1 file changed, 139 insertions(+), 15 deletions(-) diff --git a/.azure-pipelines/docker.yml b/.azure-pipelines/docker.yml index d26803ea1d..b927e5ea32 100644 --- a/.azure-pipelines/docker.yml +++ b/.azure-pipelines/docker.yml @@ -1,19 +1,143 @@ +name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) + trigger: branches: include: - - 'task/add-acr-pipeline' - tags: - include: - - v* -schedules: - - cron: "0 18 * * 4" - displayName: "Weekly Publish Docker Image" - branches: - include: - - main - always: true - + - main + - task/add-new-acr-pipeline + +pr: none + variables: - REGISTRY: "msgraphprod.azurecr.io" - IMAGE_NAME: "public/openapi/kiota" - PREVIEW_BRANCH: "refs/heads/main" \ No newline at end of file + buildConfiguration: 'Release' + BUILDPLATFORM: 'linux/amd64' + REGISTRY: msgraphprodregistry.azurecr.io # Azure Container Registry + IMAGE_NAME: public/openapi/kiota # Docker image name + PREVIEW_BRANCH: "refs/heads/main" # Branch for preview builds + VERSION_SUFFIX: "" # Version suffix for preview builds + +resources: + repositories: + - repository: 1ESPipelineTemplates + type: git + name: 1ESPipelineTemplates/1ESPipelineTemplates + ref: refs/tags/release + - repository: ReleasePipelines + type: git + name: "Graph Developer Experiences/release-pipelines" + +parameters: +- name: poolName + type: string + default: Azure-Pipelines-1ESPT-ExDShared + +- name: image + type: string + default: ubuntu-latest + +- name: os + type: string + default: linux + +extends: + template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates + parameters: + pool: + name: ${{ parameters.poolName }} + image: ${{ parameters.image }} + os: ${{ parameters.os }} + sdl: + sourceAnalysisPool: + name: Azure-Pipelines-1ESPT-ExDShared # Name of your hosted pool + image: windows-latest # Name of the image in your pool. If not specified, first image of the pool is used + sourceRepositoriesToScan: + exclude: + - repository: ReleasePipelines + stages: + - stage: Build + jobs: + - job: build + steps: + - task: UseDotNet@2 + displayName: 'Use .NET 8' + inputs: + version: 8.x + - task: UseDotNet@2 + displayName: 'Use .NET 9' + inputs: + version: 9.x + # Install the nuget tool. + - task: NuGetToolInstaller@1 + displayName: 'Install Nuget dependency manager' + inputs: + versionSpec: '>=5.2.0' + checkLatest: true + + - script: | + ls + displayName: 'List files in the repo' + # Build the Product project + - task: DotNetCoreCLI@2 + displayName: "build" + inputs: + projects: '$(Build.SourcesDirectory)/kiota.sln' + arguments: "--configuration $(BuildConfiguration) --no-incremental" + - script: | + docker version + docker info + displayName: Show docker environment + - script: echo "##vso[task.setvariable variable=BUILDNUMBER]$(Build.BuildId)" + displayName: 'Set BUILDNUMBER variable' + - powershell: | + .\scripts\get-prerelease-version.ps1 -currentBranch $(Build.SourceBranchName) -previewBranch 'azure-pipelines' -excludeHeadingDash + displayName: 'Generate version suffix' + + - script: | + echo "Generated version_suffix: $(versionSuffix)" + displayName: 'Show generated version_suffix' + + # Publish the Product project with version_suffix if available + - task: DotNetCoreCLI@2 + displayName: "publish with version_suffix" + inputs: + command: publish + publishWebProjects: false + projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' + arguments: "-c Release -p:TreatWarningsAsErrors=false -f net9.0 --version-suffix $(versionSuffix)" + condition: and(succeeded(), ne(variables['versionSuffix'], '')) + + # Publish the Product project without version_suffix if not available + - task: DotNetCoreCLI@2 + displayName: "publish without version_suffix" + inputs: + command: publish + publishWebProjects: false + projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' + arguments: "-c Release -p:TreatWarningsAsErrors=false -f net9.0" + condition: and(succeeded(), eq(variables['versionSuffix'], '')) + + # Build Docker image for validation (no push) + - task: 1ES.BuildContainerImage@1 + inputs: + image: $(REGISTRY)/$(IMAGE_NAME):validation # Image name to build (including a tag). Required. Alias: localImage + path: $(Build.SourcesDirectory) # Required. Alias: context + dockerfile: ./Dockerfile # Optional. Default: 'contextPath/Dockerfile' + buildArguments: --build-arg version_suffix=$(versionSuffix) --platform linux/amd64,linux/arm64/v8 # Optional. Default: '' + - task: Bash@3 + displayName: Save Docker Image + inputs: + targetType: inline + script: | + docker save $(REGISTRY)/$(IMAGE_NAME):validation -o $(Build.ArtifactStagingDirectory)/kiota.tar + + - task: 1ES.PublishPipelineArtifact@1 + inputs: + path: $(Build.ArtifactStagingDirectory) + artifact: drop + + - stage: CheckoutAndCopy # Add a new stage + jobs: + - template: pipelines/templates/checkout-and-copy-1es.yml@ReleasePipelines + parameters: + directory: 'kiota' + repoName: ReleasePipelines \ No newline at end of file From dca90cd69c66355d7518c3fe39375a06cf9d009b Mon Sep 17 00:00:00 2001 From: "Evans Aboge (from Dev Box)" Date: Thu, 30 Jan 2025 16:30:02 +0300 Subject: [PATCH 2/4] Remove build step --- Dockerfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index dcbc63d010..e0fddababd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,6 @@ WORKDIR /app COPY ./src ./kiota/src COPY ./resources ./kiota/resources WORKDIR /app/kiota -RUN if [ -z "$version_suffix" ]; then \ - dotnet publish ./src/kiota/kiota.csproj -c Release -p:TreatWarningsAsErrors=false -f net9.0; \ - else \ - dotnet publish ./src/kiota/kiota.csproj -c Release -p:TreatWarningsAsErrors=false -f net9.0 --version-suffix "$version_suffix"; \ - fi FROM mcr.microsoft.com/dotnet/runtime:9.0-noble-chiseled AS runtime WORKDIR /app From ec54c4cab9c5b79733cd93fd0c3bac4d78b4c180 Mon Sep 17 00:00:00 2001 From: "Evans Aboge (from Dev Box)" Date: Fri, 31 Jan 2025 14:42:30 +0300 Subject: [PATCH 3/4] Add powershell scripts --- .azure-pipelines/docker.yml | 74 +++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/.azure-pipelines/docker.yml b/.azure-pipelines/docker.yml index b927e5ea32..17ed46d60e 100644 --- a/.azure-pipelines/docker.yml +++ b/.azure-pipelines/docker.yml @@ -11,10 +11,14 @@ pr: none variables: buildConfiguration: 'Release' BUILDPLATFORM: 'linux/amd64' - REGISTRY: msgraphprodregistry.azurecr.io # Azure Container Registry - IMAGE_NAME: public/openapi/kiota # Docker image name - PREVIEW_BRANCH: "refs/heads/main" # Branch for preview builds - VERSION_SUFFIX: "" # Version suffix for preview builds + REGISTRY: msgraphprodregistry.azurecr.io + IMAGE_NAME: public/openapi/kiota + PREVIEW_BRANCH: "refs/heads/main" + VERSION_SUFFIX: "" + dotnetVersion8: '8.x' + dotnetVersion9: '9.x' + MSBuildTreatWarningsAsErrors: 'false' + CONTAINER_PLATFORMS: 'linux/amd64,linux/arm64/v8,linux/arm/v7' resources: repositories: @@ -48,8 +52,8 @@ extends: os: ${{ parameters.os }} sdl: sourceAnalysisPool: - name: Azure-Pipelines-1ESPT-ExDShared # Name of your hosted pool - image: windows-latest # Name of the image in your pool. If not specified, first image of the pool is used + name: Azure-Pipelines-1ESPT-ExDShared + image: windows-latest sourceRepositoriesToScan: exclude: - repository: ReleasePipelines @@ -61,12 +65,11 @@ extends: - task: UseDotNet@2 displayName: 'Use .NET 8' inputs: - version: 8.x + version: $(dotnetVersion8) - task: UseDotNet@2 displayName: 'Use .NET 9' inputs: - version: 9.x - # Install the nuget tool. + version: $(dotnetVersion9) - task: NuGetToolInstaller@1 displayName: 'Install Nuget dependency manager' inputs: @@ -76,7 +79,6 @@ extends: - script: | ls displayName: 'List files in the repo' - # Build the Product project - task: DotNetCoreCLI@2 displayName: "build" inputs: @@ -89,40 +91,66 @@ extends: - script: echo "##vso[task.setvariable variable=BUILDNUMBER]$(Build.BuildId)" displayName: 'Set BUILDNUMBER variable' - powershell: | - .\scripts\get-prerelease-version.ps1 -currentBranch $(Build.SourceBranchName) -previewBranch 'azure-pipelines' -excludeHeadingDash - displayName: 'Generate version suffix' - + .\scripts\get-prerelease-version.ps1 -currentBranch $(Build.SourceBranch) -previewBranch $(PREVIEW_BRANCH) -excludeHeadingDash -isGHA + displayName: "Set version suffix" + env: + BUILD_BUILDNUMBER: $(Build.BuildNumber) + name: getversionsuffix + + - powershell: | + .\scripts\update-version-suffix-for-source-generator.ps1 -versionSuffix "$(getversionsuffix.versionSuffix)" + displayName: "Set version suffix in csproj for generators" + condition: contains(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH']) + + - powershell: | + .\scripts\get-version-from-csproj.ps1 -isGHA + displayName: "Get Kiota's version-number from .csproj" + name: getversion + + - powershell: | + .\scripts\get-release-notes.ps1 -version "$(getversion.version)" + displayName: "Get release notes from CHANGELOG.md" + condition: not(contains(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])) + + - powershell: | + .\scripts\get-release-notes.ps1 -version Unreleased + displayName: "Get release notes from CHANGELOG.md" + condition: contains(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH']) + + - powershell: | + .\scripts\update-versions.ps1 + displayName: "Update dependencies versions" + - script: | echo "Generated version_suffix: $(versionSuffix)" displayName: 'Show generated version_suffix' - # Publish the Product project with version_suffix if available - task: DotNetCoreCLI@2 displayName: "publish with version_suffix" inputs: command: publish publishWebProjects: false projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' - arguments: "-c Release -p:TreatWarningsAsErrors=false -f net9.0 --version-suffix $(versionSuffix)" + arguments: "-c Release -f net9.0 --version-suffix $(versionSuffix)" condition: and(succeeded(), ne(variables['versionSuffix'], '')) - # Publish the Product project without version_suffix if not available - task: DotNetCoreCLI@2 displayName: "publish without version_suffix" inputs: command: publish publishWebProjects: false projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' - arguments: "-c Release -p:TreatWarningsAsErrors=false -f net9.0" + arguments: "-c Release -f net9.0" condition: and(succeeded(), eq(variables['versionSuffix'], '')) - # Build Docker image for validation (no push) - task: 1ES.BuildContainerImage@1 + condition: contains(variables['Build.SourceBranch'], 'Preview') inputs: - image: $(REGISTRY)/$(IMAGE_NAME):validation # Image name to build (including a tag). Required. Alias: localImage - path: $(Build.SourcesDirectory) # Required. Alias: context - dockerfile: ./Dockerfile # Optional. Default: 'contextPath/Dockerfile' - buildArguments: --build-arg version_suffix=$(versionSuffix) --platform linux/amd64,linux/arm64/v8 # Optional. Default: '' + image: $(REGISTRY)/$(IMAGE_NAME):validation + path: $(Build.SourcesDirectory) + dockerfile: ./Dockerfile + buildArguments: --build-arg version_suffix=$(versionSuffix) --platform $(CONTAINER_PLATFORMS) + - task: Bash@3 displayName: Save Docker Image inputs: @@ -135,7 +163,7 @@ extends: path: $(Build.ArtifactStagingDirectory) artifact: drop - - stage: CheckoutAndCopy # Add a new stage + - stage: CheckoutAndCopy jobs: - template: pipelines/templates/checkout-and-copy-1es.yml@ReleasePipelines parameters: From 34eb849b5431f5598baee161c0b61c641c6d6be8 Mon Sep 17 00:00:00 2001 From: "Evans Aboge (from Dev Box)" Date: Fri, 31 Jan 2025 15:43:20 +0300 Subject: [PATCH 4/4] Fix acr --- .azure-pipelines/docker.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/docker.yml b/.azure-pipelines/docker.yml index 17ed46d60e..a71d362324 100644 --- a/.azure-pipelines/docker.yml +++ b/.azure-pipelines/docker.yml @@ -61,6 +61,8 @@ extends: - stage: Build jobs: - job: build + variables: + version: '' steps: - task: UseDotNet@2 displayName: 'Use .NET 8' @@ -88,8 +90,10 @@ extends: docker version docker info displayName: Show docker environment + - script: echo "##vso[task.setvariable variable=BUILDNUMBER]$(Build.BuildId)" displayName: 'Set BUILDNUMBER variable' + - powershell: | .\scripts\get-prerelease-version.ps1 -currentBranch $(Build.SourceBranch) -previewBranch $(PREVIEW_BRANCH) -excludeHeadingDash -isGHA displayName: "Set version suffix" @@ -103,12 +107,13 @@ extends: condition: contains(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH']) - powershell: | - .\scripts\get-version-from-csproj.ps1 -isGHA + $version = .\scripts\get-version-from-csproj.ps1 -isGHA + Write-Host "##vso[task.setvariable variable=version]$version" displayName: "Get Kiota's version-number from .csproj" name: getversion - powershell: | - .\scripts\get-release-notes.ps1 -version "$(getversion.version)" + .\scripts\get-release-notes.ps1 -version "$(version)" displayName: "Get release notes from CHANGELOG.md" condition: not(contains(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH']))