diff --git a/.azure-pipelines/docker.yml b/.azure-pipelines/docker.yml index d26803ea1d..a71d362324 100644 --- a/.azure-pipelines/docker.yml +++ b/.azure-pipelines/docker.yml @@ -1,19 +1,176 @@ +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 + 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: + - 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 + image: windows-latest + sourceRepositoriesToScan: + exclude: + - repository: ReleasePipelines + stages: + - stage: Build + jobs: + - job: build + variables: + version: '' + steps: + - task: UseDotNet@2 + displayName: 'Use .NET 8' + inputs: + version: $(dotnetVersion8) + - task: UseDotNet@2 + displayName: 'Use .NET 9' + inputs: + version: $(dotnetVersion9) + - task: NuGetToolInstaller@1 + displayName: 'Install Nuget dependency manager' + inputs: + versionSpec: '>=5.2.0' + checkLatest: true + + - script: | + ls + displayName: 'List files in the repo' + - 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.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: | + $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 "$(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' + + - task: DotNetCoreCLI@2 + displayName: "publish with version_suffix" + inputs: + command: publish + publishWebProjects: false + projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' + arguments: "-c Release -f net9.0 --version-suffix $(versionSuffix)" + condition: and(succeeded(), ne(variables['versionSuffix'], '')) + + - task: DotNetCoreCLI@2 + displayName: "publish without version_suffix" + inputs: + command: publish + publishWebProjects: false + projects: '$(Build.SourcesDirectory)/src/kiota/kiota.csproj' + arguments: "-c Release -f net9.0" + condition: and(succeeded(), eq(variables['versionSuffix'], '')) + + - task: 1ES.BuildContainerImage@1 + condition: contains(variables['Build.SourceBranch'], 'Preview') + inputs: + 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: + 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 + jobs: + - template: pipelines/templates/checkout-and-copy-1es.yml@ReleasePipelines + parameters: + directory: 'kiota' + repoName: ReleasePipelines \ No newline at end of file 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