Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add check release to auto trigger internal release job #16207

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#use-outputs-in-a-different-stage

I suspect you need to get this value from the outputs similar to the other usage. Actually, do we need the condition here as well as on the stage? Perhaps this one can be removed.

I think this is likely the reason for the issue that @seankane-msft is seeing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this job condition is wrong and also redundant. I've removed it by this PR. Thanks @weshaggard @seankane-msft for your validation and correction.

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)
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
{
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"
}