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

{CI} Use target_commitish branch in release to trigger Reference Docs CI #31011

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
50 changes: 9 additions & 41 deletions .github/workflows/TriggerReferenceDocsCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,24 @@ jobs:
env:
AdoOrg: ${{secrets.ADO_DocsReference_Organization}}
AdoProject: ${{secrets.ADO_DocsReference_Project}}
AdoPipelineId: ${{secrets.ADO_DocsReference_JumpPipeline_ID}}
CheckInterval: 60
AdoLatestPipelineId: ${{secrets.ADO_DocsReference_Latest_Pipeline_ID}}
Copy link
Member

@wangzelin007 wangzelin007 Mar 13, 2025

Choose a reason for hiding this comment

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

LGTM.
We need a quick call or meeting to setup the new github action secrets.

AdoLtsPipelineId: ${{secrets.ADO_DocsReference_LTS_Pipeline_ID}}
ReleaseBranch: ${{ github.event.release.target_commitish }}
run: |
$organization = $env:AdoOrg
$project = $env:AdoProject
$definitionId = $env:AdoPipelineId
$checkInterval = $env:CheckInterval
$thisRepoLink = "${{ github.server_url }}/${{ github.repository }}"
$thisRunLink = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
$triggerBranch = 'main'
$variables = @('commitAuthor=azcli', 'triggerFromRepo=https://github.com/Azure/azure-cli', "triggerBranch=$triggerBranch", "triggerByPipeline=$thisRunLink")
$triggerBranch = $env:ReleaseBranch
$definitionId = $triggerBranch -eq 'release' ? $env:AdoLatestPipelineId : $env:AdoLtsPipelineId
$variables = @("triggerBranch=$triggerBranch", "triggerFromRepo=$thisRepoLink", "triggerByPipeline=$thisRunLink")

$output = az pipelines build queue --definition-id $definitionId --project $project --organization $organization --variables @variables | ConvertFrom-Json -AsHashtable
if ($? -eq $false)
{
$pipelineDefinitionLink = $organization + [uri]::EscapeDataString($project) + "/_build?definitionId=$definitionId"
Write-Error "Failed to queue the pipeline run for $pipelineDefinitionLink, please check above error message."
}
$runIdInJumpPipeline = $output.id
Write-Host "runIdInJumpPipeline: $runIdInJumpPipeline"
do
{
Start-Sleep -Seconds $checkInterval
$status = az pipelines runs show --query status --id $runIdInJumpPipeline --project $project --organization $organization --output tsv
$currentTime = (Get-Date -AsUTC).ToString('yyyy-MM-dd HH:mm:ss')
Write-Host "[UTC $currentTime] apidrop shared jump pipeline run status: $status"
} while ($status -ne 'completed')
$jumpOutput = az pipelines runs show --id $runIdInJumpPipeline --project $project --organization $organization | ConvertFrom-Json -AsHashtable

$targetPipelineResult = ($jumpOutput.tags -Match 'jump_return_result_(canceled|failed|partiallySucceeded|succeeded)')[0] -replace 'jump_return_result_', ''
$runId = ($jumpOutput.tags -Match 'jump_return_id_\d+')[0] -replace 'jump_return_id_', ''
$triggeredTargetPipeline = $runId ? $true : $false
if ($triggeredTargetPipeline)
{
# apidrop shared jump pipeline triggered target pipeline
$printMessage = 'Triggered reference pipeline run'
$printMessage += $targetPipelineResult ? " with its result $targetPipelineResult" : '' # waited for completion or not
}
else
{
# apidrop shared jump pipeline may fail to trigger target pipeline
$runId = $runIdInJumpPipeline
$printMessage = "Jump pipeline run with $($jumpOutput.result) state may fail to trigger reference pipeline"
}
$runId = $output.id
$runLink = $organization + [uri]::EscapeDataString($project) + "/_build/results?buildId=$runId"
$printMessage += ", for details please check: $runLink"
if ($triggeredTargetPipeline)
{
Write-Host $printMessage
}
else
{
Write-Error $printMessage
}
Write-Host "Triggered reference pipeline run, for details please check: $runLink"