From b311f66e149d58bdd527b8d6ada781a6b897bf0e Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 24 Jul 2024 16:24:41 +0100 Subject: [PATCH] [ci] Move to push nightly to a template (#23811) --- eng/pipelines/common/push-nightly.yml | 87 +++++++++++++++++++++++++ eng/pipelines/device-tests.yml | 5 +- eng/pipelines/maui-release-internal.yml | 9 ++- eng/pipelines/maui-release.yml | 85 +++--------------------- 4 files changed, 109 insertions(+), 77 deletions(-) create mode 100644 eng/pipelines/common/push-nightly.yml diff --git a/eng/pipelines/common/push-nightly.yml b/eng/pipelines/common/push-nightly.yml new file mode 100644 index 000000000000..576fafe2563e --- /dev/null +++ b/eng/pipelines/common/push-nightly.yml @@ -0,0 +1,87 @@ +parameters: + poolName: MAUI-1ESPT + vmImage: '1ESPT-Windows2022' + os: windows + dependsOn: [''] + scanArtifacts: [] + stageName: 'nightly' + displayName: 'Nightly' + +stages: + - stage: ${{ parameters.stageName }} + dependsOn: ${{ parameters.dependsOn }} + displayName: ${{ parameters.displayName }} + jobs: + - job: push_nightly_job + displayName: Push to nightly feed + pool: + name: ${{ parameters.poolName }} + vmImage: ${{ parameters.vmImage }} + workspace: + clean: all + timeoutInMinutes: 60 + steps: + - checkout: none + + - task: UseDotNet@2 + displayName: Use .NET 8.x + inputs: + version: 8.x + + - task: AzureCLI@2 + displayName: Update service connection with managed identity + inputs: + azureSubscription: maui-nightly-feed-mi + scriptType: ps + scriptLocation: inlineScript + inlineScript: | + $accessToken = az account get-access-token --query accessToken --resource $(MauiNightlyFeedMIResourceId) -o tsv + Write-Host "##vso[task.setsecret]$accessToken" + Write-Host "Overwriting authorization token for the maui-nightly-feed service connection" + # https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#setendpoint-modify-a-service-connection-field + Write-Host "##vso[task.setendpoint id=$(MauiNightlyFeedServiceConnectionId);field=authParameter;key=apitoken]${accessToken}" + + - task: NuGetAuthenticate@1 + displayName: NuGet Authenticate using managed identity token + inputs: + nuGetServiceConnections: maui-nightly-feed + + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: nuget-signed + downloadPath: $(Build.StagingDirectory)\nuget-signed + displayName: Download nuget-signed + + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: vs-msi-nugets + downloadPath: $(Build.StagingDirectory)\nuget-signed + displayName: Download vs-msi-nugets + + - powershell: | + $feed = "$env:NUGET_FEED_MAUI_NIGHTLY" + # Signed maui packages except manifest + $nupkgs = (Get-ChildItem -Path "$(Build.StagingDirectory)\nuget-signed\" -Filter *.nupkg) | Where-Object { $_.BaseName -notlike 'Microsoft.NET.Sdk.Maui.Manifest-*' } + $maxAttempts = 5 + foreach($nupkg in $nupkgs) { + $nupkgFile = $nupkg.FullName + $attempt = 1 + $waiting = $true + do { + try { + Write-Output "dotnet push $nupkgFile" + & dotnet nuget push --source $feed --api-key az --skip-duplicate $nupkgFile + $waiting = $false + } + catch { + if ($attempt -gt $maxAttempts) + { + throw 'Maximum attempts reached, failing!' + } + Write-Output " attempt $attempt of $maxAttempts failed..." + $attempt = $attempt + 1 + } + } while ($waiting) + } + displayName: Push nupkg to maui nightly feed + diff --git a/eng/pipelines/device-tests.yml b/eng/pipelines/device-tests.yml index d127ac23ab1f..415d99406863 100644 --- a/eng/pipelines/device-tests.yml +++ b/eng/pipelines/device-tests.yml @@ -3,7 +3,8 @@ trigger: include: - main - release/* - - loc + - net9.0 + - net8.0 tags: include: - '*' @@ -27,6 +28,8 @@ pr: include: - main - release/* + - net9.0 + - net8.0 paths: include: - '*' diff --git a/eng/pipelines/maui-release-internal.yml b/eng/pipelines/maui-release-internal.yml index 5b8c16d2ef5f..0c4dd4e3883b 100644 --- a/eng/pipelines/maui-release-internal.yml +++ b/eng/pipelines/maui-release-internal.yml @@ -20,7 +20,14 @@ trigger: - SECURITY.md - THIRD-PARTY-NOTICES.TXT - +schedules: +- cron: "0 5 * * *" + displayName: Run daily at 5:00 UTC + branches: + include: + - main + - net9.0 + variables: - template: /eng/pipelines/common/variables.yml@self - group: DotNetBuilds storage account read tokens diff --git a/eng/pipelines/maui-release.yml b/eng/pipelines/maui-release.yml index 978b1dc29998..69990fc47eaa 100644 --- a/eng/pipelines/maui-release.yml +++ b/eng/pipelines/maui-release.yml @@ -26,6 +26,7 @@ schedules: branches: include: - main + - net9.0 variables: - template: /eng/pipelines/common/variables.yml@self @@ -196,78 +197,12 @@ extends: os: ${{ parameters.VM_IMAGE_HOST.os }} scanArtifacts: ['${{ parameters.PackPlatform.binariesArtifact }}'] - - ${{ if eq(variables['Build.Reason'], 'Manual') }}: - - stage: nightly - displayName: Nightly - dependsOn: ['sdk_insertion'] - jobs: - - job: push_nightly - displayName: Push to nightly feed - pool: ${{ parameters.VM_IMAGE_HOST }} - workspace: - clean: all - timeoutInMinutes: 60 - steps: - - checkout: none - - - task: UseDotNet@2 - displayName: Use .NET 8.x - inputs: - version: 8.x - - - task: AzureCLI@2 - displayName: Update service connection with managed identity - inputs: - azureSubscription: maui-nightly-feed-mi - scriptType: ps - scriptLocation: inlineScript - inlineScript: | - $accessToken = az account get-access-token --query accessToken --resource $(MauiNightlyFeedMIResourceId) -o tsv - Write-Host "##vso[task.setsecret]$accessToken" - Write-Host "Overwriting authorization token for the maui-nightly-feed service connection" - # https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#setendpoint-modify-a-service-connection-field - Write-Host "##vso[task.setendpoint id=$(MauiNightlyFeedServiceConnectionId);field=authParameter;key=apitoken]${accessToken}" - - - task: NuGetAuthenticate@1 - displayName: NuGet Authenticate using managed identity token - inputs: - nuGetServiceConnections: maui-nightly-feed - - - task: DownloadPipelineArtifact@2 - inputs: - artifactName: nuget-signed - downloadPath: $(Build.StagingDirectory)\nuget-signed - displayName: Download nuget-signed - - - task: DownloadPipelineArtifact@2 - inputs: - artifactName: vs-msi-nugets - downloadPath: $(Build.StagingDirectory)\nuget-signed - displayName: Download vs-msi-nugets - - - powershell: | - $feed = "$env:NUGET_FEED_MAUI_NIGHTLY" - # Signed maui packages except manifest - $nupkgs = (Get-ChildItem -Path "$(Build.StagingDirectory)\nuget-signed\" -Filter *.nupkg) | Where-Object { $_.BaseName -notlike 'Microsoft.NET.Sdk.Maui.Manifest-*' } - $maxAttempts = 5 - foreach($nupkg in $nupkgs) { - $nupkgFile = $nupkg.FullName - $attempt = 1 - $waiting = $true - do { - try { - Write-Output "dotnet push $nupkgFile" - & dotnet nuget push --source $feed --api-key az --skip-duplicate $nupkgFile - $waiting = $false - } - catch { - if ($attempt -gt $maxAttempts) - { - throw 'Maximum attempts reached, failing!' - } - Write-Output " attempt $attempt of $maxAttempts failed..." - $attempt = $attempt + 1 - } - } while ($waiting) - } - displayName: Push nupkg to maui nightly feed + - ${{ if eq(variables['Build.Reason'], 'Schedule') }}: + - template: /eng/pipelines/common/push-nightly.yml@self + parameters: + dependsOn: ['sdk_insertion'] + stageName: 'nightly' + displayName: 'Push Nightly' + poolName: ${{ parameters.VM_IMAGE_HOST.name }} + vmImage: ${{ parameters.VM_IMAGE_HOST.image }} + os: ${{ parameters.VM_IMAGE_HOST.os }}