From 14543e214fecea6b8f601f49e8cb27347abe1c56 Mon Sep 17 00:00:00 2001 From: Konstantin Tyukalov Date: Fri, 3 Nov 2023 13:24:16 +0400 Subject: [PATCH] Add scheduled release by sprint --- .azure-pipelines/build-job.yml | 7 +- .azure-pipelines/build-jobs.yml | 2 +- .azure-pipelines/pipeline.yml | 10 ++ .azure-pipelines/switch-branch.yml | 1 + .vsts.release.yml | 212 +++++++++++++++++++---------- 5 files changed, 157 insertions(+), 75 deletions(-) diff --git a/.azure-pipelines/build-job.yml b/.azure-pipelines/build-job.yml index 050fc70709..9fa0770bbc 100644 --- a/.azure-pipelines/build-job.yml +++ b/.azure-pipelines/build-job.yml @@ -86,6 +86,7 @@ jobs: DisableCFSDetector: true DisableDockerDetector: true nugetMultiFeedWarnLevel: none + CheckoutBranch: ${{ parameters.branch }} steps: @@ -102,7 +103,7 @@ jobs: - ${{ if ne(parameters.branch, '') }}: - template: switch-branch.yml parameters: - branch: ${{ parameters.branch }} + branch: $(CheckoutBranch) # 1ES images used on the ARM pool doesn't contain unzip tool, so we need to install it before starting the build - ${{ if and(eq(parameters.arch, 'arm64'), ne(parameters.os, 'osx')) }}: @@ -119,7 +120,7 @@ jobs: ADO_ENABLE_LOGISSUE: true # Check if broken symlinks exist in the agent build - - task: Bash@3.201.1 + - task: Bash@3 inputs: filePath: src/Misc/check-symlinks.sh displayName: Check symlinks @@ -255,4 +256,4 @@ jobs: inputs: CodesignValidation: true CodesignValidationBreakOn: WarningAbove - ToolLogsNotFoundAction: Error + ToolLogsNotFoundAction: Error \ No newline at end of file diff --git a/.azure-pipelines/build-jobs.yml b/.azure-pipelines/build-jobs.yml index 594239c308..b198a74294 100644 --- a/.azure-pipelines/build-jobs.yml +++ b/.azure-pipelines/build-jobs.yml @@ -98,4 +98,4 @@ jobs: sign: ${{ parameters.sign }} verifySigning: ${{ parameters.verifySigning }} publishArtifact: ${{ parameters.publishArtifacts }} - packageType: pipelines-agent + packageType: pipelines-agent \ No newline at end of file diff --git a/.azure-pipelines/pipeline.yml b/.azure-pipelines/pipeline.yml index a0a5a40be0..6ddf88e6d3 100644 --- a/.azure-pipelines/pipeline.yml +++ b/.azure-pipelines/pipeline.yml @@ -26,6 +26,12 @@ parameters: - name: testProxyAgent type: boolean default: false +- name: stageDependencies + type: object + default: [] +- name: stageCondition + type: string + default: '' # Targets - name: win_x64 @@ -64,6 +70,10 @@ stages: - stage: build displayName: Build + ${{ if ne(length(parameters.stageDependencies), 0)}}: + dependsOn: ${{ parameters.stageDependencies }} + ${{ if ne(parameters.stageCondition, '') }}: + condition: ${{ parameters.stageCondition }} jobs: # Test Proxy Agent - ${{ if parameters.testProxyAgent }}: diff --git a/.azure-pipelines/switch-branch.yml b/.azure-pipelines/switch-branch.yml index 9f4178c316..ded88fd811 100644 --- a/.azure-pipelines/switch-branch.yml +++ b/.azure-pipelines/switch-branch.yml @@ -7,5 +7,6 @@ steps: - script: | git config user.email "azure-pipelines-bot@microsoft.com" git config user.name "azure-pipelines-bot" + git checkout -f origin/${{ parameters.branch }} displayName: Checkout branch diff --git a/.vsts.release.yml b/.vsts.release.yml index b2e07ba0cb..b6eb05c466 100644 --- a/.vsts.release.yml +++ b/.vsts.release.yml @@ -1,7 +1,15 @@ +schedules: +- cron: '0 6 * * 2' + displayName: Scheduled weekly run + branches: + include: + - master + parameters: - name: version type: string displayName: Version + default: '3.999.999' - name: derivedFrom type: string displayName: Derived From Version @@ -27,54 +35,105 @@ parameters: default: true displayName: Test Proxy Agent -variables: - ${{ if parameters.buildStageOnly }}: - releaseBranch: '' - ${{ else }}: - releaseBranch: releases/${{ parameters.version }} - extends: template: .azure-pipelines/pipeline.yml parameters: - branch: ${{ variables.releaseBranch }} + branch: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.releaseBranch'] ] componentDetection: false test: ${{ not(parameters.skipTests) }} sign: true publishArtifacts: true testProxyAgent: ${{ parameters.testProxyAgent }} + stageDependencies: + - Verify_release + - Create_Release_Branch + stageCondition: | + and( + succeeded('Verify_release'), + in(dependencies.Create_Release_Branch.result, 'Succeeded', 'Skipped') + ) preBuildStages: - - ${{ if and(not(parameters.buildStageOnly), eq(variables['Build.SourceBranch'], 'refs/heads/master')) }}: - - stage: Create_Release_Branch + - stage: Verify_release + displayName: Make sure it's actually the release run + pool: + vmImage: ubuntu-latest + jobs: + - job: Set_variables + displayName: Set release-specific variables + steps: + - pwsh: | + $isBuildStageOnly = [System.Convert]::ToBoolean('${{ parameters.buildStageOnly }}') + $buildReason = '$(Build.Reason)' + + $currentSprint = (Invoke-WebRequest https://whatsprintis.it -Headers @{"Accept" = "application/json" } | ConvertFrom-Json) + $isReleaseWeek = $currentSprint.week -eq 3 + Write-Host "isReleaseWeek = $isReleaseWeek" + + $isRelease = ($buildReason -eq 'Manual' -and !$isBuildStageOnly) -or ($buildReason -eq 'Schedule' -and !$isReleaseWeek) + Write-Host "isRelease = $isRelease" + Write-Host "##vso[task.setVariable variable=isRelease;isOutput=true]$isRelease" + + $isScheduledRelease = $isRelease -and $buildReason -eq 'Schedule' + Write-Host "isScheduledRelease = $isScheduledRelease" + + if ($isRelease) { + if ($isScheduledRelease) { + $agentVersion = "3.$($currentSprint.sprint).0" + } else { + $agentVersion = "${{ parameters.version }}" + } + Write-Host "agentVersion = $agentVersion" + Write-Host "##vso[task.setVariable variable=agentVersion;isOutput=true]$agentVersion" + + $releaseBranch = "releases/$agentVersion" + Write-Host "releaseBranch = $releaseBranch" + Write-Host "##vso[task.setVariable variable=releaseBranch;isOutput=true]$releaseBranch" + } + + name: SetReleaseVariables + displayName: Set release-specific variables + + - stage: Create_Release_Branch + displayName: Create Release Branch + dependsOn: + - Verify_release + jobs: + ################################################################################ + - job: Create_Release_Branch + ################################################################################ displayName: Create Release Branch - jobs: - ################################################################################ - - job: Create_Release_Branch - ################################################################################ - displayName: Create Release Branch - pool: - vmImage: ubuntu-latest + variables: + IsRelease: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.isRelease'] ] + ReleaseBranch: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.releaseBranch'] ] + AgentVersion: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.agentVersion'] ] + condition: and(succeeded(), eq(variables.IsRelease, 'True')) + pool: + vmImage: ubuntu-latest + steps: - steps: - - checkout: self + - checkout: self - - task: NodeTool@0 - displayName: Use node 14.15.1 - inputs: - versionSpec: "14.15.1" + - task: NodeTool@0 + displayName: Use node 14.15.1 + inputs: + versionSpec: "14.15.1" - - script: | - cd release - npm install - node createReleaseBranch.js ${{ parameters.version }} --derivedFrom=${{ parameters.derivedFrom }} - env: - EDITOR: cat - PAT: $(GithubToken) - displayName: Push release branch to GitHub + - script: | + cd release + npm install + + node createReleaseBranch.js $(AgentVersion) --derivedFrom=${{ parameters.derivedFrom }} + env: + EDITOR: cat + PAT: $(GithubToken) + displayName: Push release branch to GitHub postBuildStages: - - ${{ if not(parameters.buildStageOnly) }}: - stage: Release + dependsOn: + - build + - Verify_release jobs: ################################################################################ - job: publish_agent_packages @@ -82,6 +141,11 @@ extends: displayName: Publish Agents (Windows/Linux/OSX) pool: name: RMAgentsProdAME + variables: + IsRelease: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.isRelease'] ] + ReleaseBranch: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.releaseBranch'] ] + AgentVersion: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.agentVersion'] ] + condition: and(succeeded(), eq(variables.IsRelease, 'True')) steps: # Clean @@ -91,7 +155,7 @@ extends: # Switch to release branch - template: switch-branch.yml parameters: - branch: ${{ variables.releaseBranch }} + branch: $(ReleaseBranch) # Download all agent packages from all previous phases - task: DownloadBuildArtifacts@0 @@ -111,7 +175,7 @@ extends: Login-AzAccount -ServicePrincipal -CertificateThumbprint $certificateThumbprint -ApplicationId $clientId -TenantId $(TenantId) Select-AzSubscription -SubscriptionId $(SubscriptionId) $storage = Get-AzStorageAccount -ResourceGroupName vstsagentpackage -AccountName vstsagentpackage - $versionDir = "${{ parameters.version }}" + $versionDir = "$(AgentVersion)" Get-ChildItem -LiteralPath "$(System.ArtifactsDirectory)/agent" | ForEach-Object { $target=$_ Get-ChildItem -LiteralPath "$(System.ArtifactsDirectory)/agent/$target" -Include "*.zip","*.tar.gz" | ForEach-Object { @@ -137,7 +201,7 @@ extends: # Fill release notes with agent version and package hashes - script: | cd release - node fillReleaseNotesTemplate.js ${{ parameters.version }} + node fillReleaseNotesTemplate.js $(AgentVersion) displayName: Fill release notes # Create agent release on Github @@ -145,9 +209,9 @@ extends: Write-Host "Creating github release." $releaseNotes = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\releaseNote.md") $releaseData = @{ - tag_name = "v${{ parameters.version }}"; + tag_name = "v$(AgentVersion)"; target_commitish = "$(Build.SourceVersion)"; - name = "v${{ parameters.version }}"; + name = "v$(AgentVersion)"; body = $releaseNotes; draft = $false; prerelease = $true; @@ -165,7 +229,7 @@ extends: $releaseCreated = Invoke-RestMethod @releaseParams Write-Host $releaseCreated $releaseId = $releaseCreated.id - $assets = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\assets.json").Replace("","${{ parameters.version }}") + $assets = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\assets.json").Replace("","$(AgentVersion)") $assetsParams = @{ Uri = "https://uploads.github.com/repos/Microsoft/azure-pipelines-agent/releases/$releaseId/assets?name=assets.json" Method = 'POST'; @@ -178,38 +242,44 @@ extends: Invoke-RestMethod @assetsParams displayName: Create agent release on Github - - ${{ if not(parameters.onlyGitHubRelease) }}: - - stage: CreatePRs - jobs: - ################################################################################ - - job: create_ado_prs - ################################################################################ + - stage: CreatePRs + dependsOn: + - Release + - Verify_release + condition: and(succeeded(), not(${{ parameters.onlyGitHubRelease }})) + jobs: + ################################################################################ + - job: create_ado_prs + ################################################################################ + displayName: Create PRs in AzureDevOps and ConfigChange + pool: + vmImage: ubuntu-latest + variables: + ReleaseBranch: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.releaseBranch'] ] + AgentVersion: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.agentVersion'] ] + + steps: + - checkout: self + + - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: + - script: git checkout $(ReleaseBranch) + displayName: Checkout release branch + + # Download all agent hashes created in previous phases + - task: DownloadBuildArtifacts@0 + displayName: Download Agent Hashes + inputs: + artifactName: hash + downloadPath: $(Build.SourcesDirectory)/_hashes + + - bash: | + set -x + cd release + npm install + ls + node createAdoPrs.js $(AgentVersion) displayName: Create PRs in AzureDevOps and ConfigChange - pool: - vmImage: ubuntu-latest - - steps: - - checkout: self - - - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: - - script: git checkout ${{ variables.releaseBranch }} - displayName: Checkout release branch - - # Download all agent hashes created in previous phases - - task: DownloadBuildArtifacts@0 - displayName: Download Agent Hashes - inputs: - artifactName: hash - downloadPath: $(Build.SourcesDirectory)/_hashes - - - bash: | - set -x - cd release - npm install - ls - node createAdoPrs.js ${{ parameters.version }} - displayName: Create PRs in AzureDevOps and ConfigChange - env: - USERNAME: $(User) - PAT: $(AdoPAT) - USEREMAIL: $(Email) + env: + USERNAME: $(User) + PAT: $(AdoPAT) + USEREMAIL: $(Email)