From 251da192f8ec8c29ea9e316fbe82acbd54d5e4ff Mon Sep 17 00:00:00 2001 From: Chenjie Shi Date: Wed, 24 Nov 2021 16:22:18 +0800 Subject: [PATCH] feat: add check release to auto trigger internal release job (#16207) --- .../templates/jobs/archetype-go-release.yml | 137 ++++++++++-------- eng/scripts/Verify-NeedToRelease.ps1 | 42 ++++++ 2 files changed, 120 insertions(+), 59 deletions(-) create mode 100644 eng/scripts/Verify-NeedToRelease.ps1 diff --git a/eng/pipelines/templates/jobs/archetype-go-release.yml b/eng/pipelines/templates/jobs/archetype-go-release.yml index 6fd1d2ff78c0..d0128eac036d 100644 --- a/eng/pipelines/templates/jobs/archetype-go-release.yml +++ b/eng/pipelines/templates/jobs/archetype-go-release.yml @@ -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 }}' diff --git a/eng/scripts/Verify-NeedToRelease.ps1 b/eng/scripts/Verify-NeedToRelease.ps1 new file mode 100644 index 000000000000..c1f594943ab0 --- /dev/null +++ b/eng/scripts/Verify-NeedToRelease.ps1 @@ -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" +}