Skip to content

Commit

Permalink
feat: add check release to auto trigger internal release job (#16207)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh authored Nov 24, 2021
1 parent f3c6958 commit 251da19
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 59 deletions.
137 changes: 78 additions & 59 deletions eng/pipelines/templates/jobs/archetype-go-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,86 @@ parameters:
ServiceDirectory: ''

stages:
- ${{if and(eq(variables['Build.Reason'], 'Manual'), eq(variables['System.TeamProject'], 'internal'))}}:
- stage: Release
displayName: 'Release: ${{ parameters.ServiceDirectory }}'
dependsOn: ${{ parameters.DependsOn }}
condition: and(succeeded(), ne(variables['SetDevVersion'], 'true'), ne(variables['Skip.Release'], 'true'), ne(variables['Build.Repository.Name'], 'Azure/azure-sdk-for-go-pr'))
jobs:
- deployment: TagRepository
displayName: "Create release tag"
condition: and(succeeded(), ne(variables['Skip.TagRepository'], 'true'))
environment: github
- stage: CheckRelease
displayName: 'Check Release: ${{ parameters.ServiceDirectory }}'
dependsOn: ${{ parameters.DependsOn }}
condition: and(succeeded(), ne(variables['SetDevVersion'], 'true'), ne(variables['Skip.Release'], 'true'), ne(variables['Build.Repository.Name'], 'Azure/azure-sdk-for-go-pr'))
jobs:
- job: CheckReleaseJob
displayName: "Check whether need to release"
steps:
- task: PowerShell@2
name: Verify
inputs:
filePath: ./eng/scripts/Verify-NeedToRelease.ps1
arguments: >
-PackageName 'sdk/${{ parameters.ServiceDirectory }}'
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
-repoId Azure/azure-sdk-for-go
-workingDirectory $(System.DefaultWorkingDirectory)
pwsh: true
env:
GH_TOKEN: $(azuresdk-github-pat)
- stage: Release
displayName: 'Release: ${{ parameters.ServiceDirectory }}'
dependsOn: CheckRelease
condition: and(succeeded(), eq(dependencies.CheckRelease.outputs['CheckReleaseJob.Verify.NeedToRelease'], 'true'))
jobs:
- deployment: TagRepository
displayName: "Create release tag"
condition: and(succeeded(), eq(variables['NeedToRelease'], 'true'), ne(variables['Skip.TagRepository'], 'true'))
environment: github

pool:
name: azsdk-pool-mms-ubuntu-2004-general
vmImage: MMSUbuntu20.04
pool:
name: azsdk-pool-mms-ubuntu-2004-general
vmImage: MMSUbuntu20.04

strategy:
runOnce:
deploy:
steps:
- checkout: self
- template: /eng/common/pipelines/templates/steps/retain-run.yml
- template: /eng/common/pipelines/templates/steps/verify-changelog.yml
parameters:
PackageName: 'sdk/${{ parameters.ServiceDirectory }}'
ForRelease: true
- task: PowerShell@2
displayName: 'Verify no replace directives in go.mod file'
inputs:
targetType: 'filePath'
filePath: ./eng/scripts/validate_go_mod.ps1
arguments: '${{ parameters.ServiceDirectory }}'
pwsh: true
- template: /eng/common/pipelines/templates/steps/create-tags-and-git-release.yml
parameters:
ArtifactLocation: $(Build.SourcesDirectory)/sdk/${{ parameters.ServiceDirectory }}
ReleaseSha: $(Build.SourceVersion)
RepoId: Azure/azure-sdk-for-go
WorkingDirectory: $(System.DefaultWorkingDirectory)
strategy:
runOnce:
deploy:
steps:
- checkout: self
- template: /eng/common/pipelines/templates/steps/retain-run.yml
- template: /eng/common/pipelines/templates/steps/verify-changelog.yml
parameters:
PackageName: 'sdk/${{ parameters.ServiceDirectory }}'
ForRelease: true
- task: PowerShell@2
displayName: 'Verify no replace directives in go.mod file'
inputs:
targetType: 'filePath'
filePath: ./eng/scripts/validate_go_mod.ps1
arguments: '${{ parameters.ServiceDirectory }}'
pwsh: true
- template: /eng/common/pipelines/templates/steps/create-tags-and-git-release.yml
parameters:
ArtifactLocation: $(Build.SourcesDirectory)/sdk/${{ parameters.ServiceDirectory }}
ReleaseSha: $(Build.SourceVersion)
RepoId: Azure/azure-sdk-for-go
WorkingDirectory: $(System.DefaultWorkingDirectory)

- deployment: UpdatePackageVersion
displayName: "Update Package Version"
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))
environment: github
dependsOn: TagRepository
- deployment: UpdatePackageVersion
displayName: "Update Package Version"
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))
environment: github
dependsOn: TagRepository

pool:
name: azsdk-pool-mms-ubuntu-2004-general
vmImage: MMSUbuntu20.04
pool:
name: azsdk-pool-mms-ubuntu-2004-general
vmImage: MMSUbuntu20.04

strategy:
runOnce:
deploy:
steps:
- checkout: self
- pwsh: |
eng/scripts/Update-ModuleVersion.ps1 -ModulePath 'sdk/${{parameters.ServiceDirectory}}'
displayName: Increment package version
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
parameters:
PRBranchName: increment-package-version-${{ parameters.ServiceDirectory }}-$(Build.BuildId)
CommitMsg: "Increment package version after release of ${{ parameters.ServiceDirectory }}"
PRTitle: "Increment version for ${{ parameters.ServiceDirectory }} releases"
PRLabels: "auto-merge"
CloseAfterOpenForTesting: '${{ parameters.TestPipeline }}'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- pwsh: |
eng/scripts/Update-ModuleVersion.ps1 -ModulePath 'sdk/${{parameters.ServiceDirectory}}'
displayName: Increment package version
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
parameters:
PRBranchName: increment-package-version-${{ parameters.ServiceDirectory }}-$(Build.BuildId)
CommitMsg: "Increment package version after release of ${{ parameters.ServiceDirectory }}"
PRTitle: "Increment version for ${{ parameters.ServiceDirectory }} releases"
PRLabels: "auto-merge"
CloseAfterOpenForTesting: '${{ parameters.TestPipeline }}'
42 changes: 42 additions & 0 deletions eng/scripts/Verify-NeedToRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param (
$PackageName,
$ServiceDirectory,
$repoId
)

. (Join-Path $PSScriptRoot .. common scripts common.ps1)

$apiUrl = "https://api.github.com/repos/$repoId"
Write-Host "Using API URL $apiUrl"

# VERIFY CHANGELOG
$PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $PackageProp.ChangeLogPath
$changeLogEntry = $changeLogEntries[$PackageProp.Version]

if (!$changeLogEntry)
{
Write-Host "Changelog does not exist for package: $PackageName, version: $($PackageProp.Version)."
Write-Output "##vso[task.setvariable variable=NeedToRelease;isOutput=true]false"
return
}

if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus) -or $changeLogEntry.ReleaseStatus -eq $CHANGELOG_UNRELEASED_STATUS)
{
Write-Host "Changelog is not in release status for package: $PackageName, version: $($PackageProp.Version)."
Write-Output "##vso[task.setvariable variable=NeedToRelease;isOutput=true]false"
return
}

# VERIFY TAG
$existingTags = GetExistingTags($apiUrl)
if ($existingTags -contains "$($PackageProp.Name)/v$($PackageProp.Version)")
{
Write-Host "Package: $PackageName, version: $($PackageProp.Version) has already released."
Write-Output "##vso[task.setvariable variable=NeedToRelease;isOutput=true]false"
}
else
{
Write-Host "Package: $PackageName, version: $($PackageProp.Version) need to release."
Write-Output "##vso[task.setvariable variable=NeedToRelease;isOutput=true]true"
}

0 comments on commit 251da19

Please sign in to comment.