Skip to content

Commit

Permalink
[ci] Move to push nightly to a template (dotnet#23811)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho authored Jul 24, 2024
1 parent 406c1ef commit b311f66
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 77 deletions.
87 changes: 87 additions & 0 deletions eng/pipelines/common/push-nightly.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion eng/pipelines/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ trigger:
include:
- main
- release/*
- loc
- net9.0
- net8.0
tags:
include:
- '*'
Expand All @@ -27,6 +28,8 @@ pr:
include:
- main
- release/*
- net9.0
- net8.0
paths:
include:
- '*'
Expand Down
9 changes: 8 additions & 1 deletion eng/pipelines/maui-release-internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 10 additions & 75 deletions eng/pipelines/maui-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ schedules:
branches:
include:
- main
- net9.0

variables:
- template: /eng/pipelines/common/variables.yml@self
Expand Down Expand Up @@ -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 }}

0 comments on commit b311f66

Please sign in to comment.