Skip to content

Commit

Permalink
Add scheduled release by sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Tyukalov committed Nov 3, 2023
1 parent 6ee2a6b commit 14543e2
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 75 deletions.
7 changes: 4 additions & 3 deletions .azure-pipelines/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
DisableCFSDetector: true
DisableDockerDetector: true
nugetMultiFeedWarnLevel: none
CheckoutBranch: ${{ parameters.branch }}

steps:

Expand All @@ -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')) }}:
Expand All @@ -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
Expand Down Expand Up @@ -255,4 +256,4 @@ jobs:
inputs:
CodesignValidation: true
CodesignValidationBreakOn: WarningAbove
ToolLogsNotFoundAction: Error
ToolLogsNotFoundAction: Error
2 changes: 1 addition & 1 deletion .azure-pipelines/build-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ jobs:
sign: ${{ parameters.sign }}
verifySigning: ${{ parameters.verifySigning }}
publishArtifact: ${{ parameters.publishArtifacts }}
packageType: pipelines-agent
packageType: pipelines-agent
10 changes: 10 additions & 0 deletions .azure-pipelines/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}:
Expand Down
1 change: 1 addition & 0 deletions .azure-pipelines/switch-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ steps:
- script: |
git config user.email "[email protected]"
git config user.name "azure-pipelines-bot"
git checkout -f origin/${{ parameters.branch }}
displayName: Checkout branch
212 changes: 141 additions & 71 deletions .vsts.release.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,61 +35,117 @@ 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
################################################################################
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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -137,17 +201,17 @@ 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
- powershell: |
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;
Expand All @@ -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("<AGENT_VERSION>","${{ parameters.version }}")
$assets = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\assets.json").Replace("<AGENT_VERSION>","$(AgentVersion)")
$assetsParams = @{
Uri = "https://uploads.github.com/repos/Microsoft/azure-pipelines-agent/releases/$releaseId/assets?name=assets.json"
Method = 'POST';
Expand All @@ -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)

0 comments on commit 14543e2

Please sign in to comment.