Skip to content

Commit

Permalink
Split Mdoc Release check CI into multiple jobs since single job max t…
Browse files Browse the repository at this point in the history
…imeout limit (#633)

* add Mdoc-ReleaseCheckCI yml

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines

* Update compareXmlFiles.ps1

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines

* Update compareXmlFiles.ps1

* Update compareXmlFiles.ps1

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines

* Update Mdoc-ReleaseCheckCI.yml

* Update compareXmlFiles.ps1

* Update Mdoc-ReleaseCheckCI.yml

* Update compareXmlFiles.ps1

* Update Mdoc-ReleaseCheckCI.yml

* Update Mdoc-ReleaseCheckCI.yml

* Update compareXmlFiles.ps1

* Update Mdoc-ReleaseCheckCI.yml

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines

* Update Mdoc-ReleaseCheckCI.yml

* Update Mdoc-ReleaseCheckCI.yml for Azure Pipelines
  • Loading branch information
v-susu1 authored May 20, 2022
1 parent eb7fec6 commit 6284e28
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 50 deletions.
109 changes: 109 additions & 0 deletions Mdoc-ReleaseCheckCI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger: none
pr:
- main

# Variable 'needRunReleaseMdoc' was defined in the Variables tab
# Variable 'params' was defined in the Variables tab
# Agent Queue 'Azure Pipelines' was used with unrecognized Agent Specification, vmImage property must be specified to determine image - https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#software
variables:
solution: 'apidoctools.sln'
buildConfiguration: 'Release'
buildPlatform: 'any cpu'
name: $(date:yyyyMMdd)$(rev:.r)
resources:
repositories:
- repository: self
type: git
ref: refs/heads/develop
jobs:
- job: Job_1
displayName: Agent job 1
timeoutInMinutes: 600
pool:
name: Azure Pipelines
vmImage: windows-2022
steps:
- checkout: self
clean: true
- task: AzureKeyVault@2
displayName: 'Azure Key Vault: ReferenceAutomation-Prod'
inputs:
ConnectedServiceName: 886728b9-fc93-486c-ba21-26777bea99af
KeyVaultName: ReferenceAutomation-Prod
enabled: true
- task: NuGetAuthenticate@0
displayName: NuGet Authenticate
- task: PowerShell@2
displayName: Compare xml files
timeoutInMinutes: 600
inputs:
filePath: mdoc/compareXmlFiles.ps1
arguments: -paramsJson '$(params)' -githubTokenBase64 '$(githubTokenBase64)' -githubOptionsAccountName $(githubOptionsAccountName) -githubOptionsAccountEmail $(githubOptionsAccountEmail) -vstsTokenBase64 '$(vstsTokenBase64)' -step '1' -commit1 ''
enabled: true
name: job1output
- job: Job_2
displayName: Agent job2
timeoutInMinutes: 600
dependsOn: Job_1
variables:
commit1: $[ dependencies.Job_1.outputs['job1output.commit1'] ]
pool:
name: Azure Pipelines
vmImage: windows-2022
steps:
- checkout: self
clean: true
- task: AzureKeyVault@2
displayName: 'Azure Key Vault: ReferenceAutomation-Prod'
inputs:
ConnectedServiceName: 886728b9-fc93-486c-ba21-26777bea99af
KeyVaultName: ReferenceAutomation-Prod
enabled: true
- task: NuGetToolInstaller@0
displayName: Use NuGet 4.4.1
inputs:
versionSpec: 4.4.1
enabled: true
- task: NuGetCommand@2
displayName: NuGet restore
inputs:
solution: $(BuildParameters.solution)
enabled: true
- task: CmdLine@2
displayName: Command Line Script
inputs:
script: make prepare
enabled: true
- task: VSBuild@1
displayName: Build solution
inputs:
solution: $(solution)
msbuildArgs: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
enabled: true
- task: NuGetAuthenticate@0
displayName: NuGet Authenticate
- task: PowerShell@2
displayName: Compare xml files
timeoutInMinutes: 600
inputs:
filePath: mdoc/compareXmlFiles.ps1
arguments: -paramsJson '$(params)' -githubTokenBase64 '$(githubTokenBase64)' -githubOptionsAccountName $(githubOptionsAccountName) -githubOptionsAccountEmail $(githubOptionsAccountEmail) -vstsTokenBase64 '$(vstsTokenBase64)' -step '2' -commit1 '$(commit1)'
enabled: true
name: job2output
- task: PowerShell@2
displayName: Print Compare Url
inputs:
targetType: inline
script: >-
# Write your PowerShell commands here.
Write-Host "Compare Url: $Env:CompareUrl"
...
103 changes: 53 additions & 50 deletions mdoc/compareXmlFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ param (
[string]$githubOptionsAccountName,
[string]$githubOptionsAccountEmail,
[string]$vstsTokenBase64,
[bool]$needRunReleaseMdoc
[string]$step,
[string]$commit1
)

function Git-Init([string]$githubAccountName, [string]$githubAccountEmail)
Expand Down Expand Up @@ -41,6 +42,11 @@ function Git-Push([string]$rootPath, [string] $token, [string] $commitMessage, [
{
& git add --all
& git commit -m $commitMessage

& git config pull.rebase false
Write-Host 'git -c http.extraHeader="Authorization: Basic '$token'" pull'
& git -c http.extraHeader="Authorization: Basic $token" pull

& git -c http.extraHeader="Authorization: Basic $token" push --set-upstream origin $branch --force-with-lease
}
}
Expand Down Expand Up @@ -107,7 +113,6 @@ function Run($source_repo,$target_repo,$origin_target_repo)
Write-Host "origin target repo folder is null or empty!"
}


$sourceRepoUrl = $source_repo.url
$sourceRepoBranch = $source_repo.branch
$sourceFolder = $source_repo.folder
Expand Down Expand Up @@ -138,69 +143,67 @@ function Run($source_repo,$target_repo,$origin_target_repo)

Write-Host "==================== Clone target repo: $targetRepoUrl"
Git-Clone $targetRepoUrl $targetRepoPath $githubTokenBase64 $targetRepoBranch

if (Test-Path $xmlPath)
{
Write-Host "Delete files under path: $xmlPath"
Remove-Item -Recurse -Force $xmlPath\*
Write-Host "Delete files done."
}
Copy-Item "$originRepoXmlPath\*" -Destination "$xmlPath\" -Recurse -Force -Container

if ($needRunReleaseMdoc -eq $true)
{
# This part(if) run in Job_1
if($step -eq "1"){
Write-Host "==================== Run Mdoc(release version) tool to generated xml files."
Run-Mdoc $releaseMdocPath $frameworksPath $xmlPath
if ($lastexitcode -ne 0)
{
exit $lastexitcode
}
}

Write-Host "==================== First to commit xml files"
$message = "CI Update 1 with build number " + $env:BUILD_BUILDNUMBER
Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
$commitid1 = & git rev-parse HEAD
Write-Host "Commit Id1: $commitid1"
Pop-Location
if (Test-Path $xmlPath)
{
Write-Host "Delete files under path: $xmlPath"
Remove-Item -Recurse -Force $xmlPath\*
Write-Host "Delete files done."
}
Copy-Item "$originRepoXmlPath\*" -Destination "$xmlPath\" -Recurse -Force -Container

Write-Host "==================== Run Mdoc(pr version) tool to generated xml files."
Run-Mdoc $prMdocPath $frameworksPath $xmlPath
if ($lastexitcode -ne 0)
{
exit $lastexitcode
}

Write-Host "==================== Sencond to commit xml files"
$message = "CI Update 2 with build number " + $env:BUILD_BUILDNUMBER
Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
$commitid2 = & git rev-parse HEAD
Write-Host "Commit Id2: $commitid2"
Pop-Location

Write-Host "==================== First to commit xml files"
$message = "CI Update 1 with build number " + $env:BUILD_BUILDNUMBER
Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
$commitid1 = & git rev-parse HEAD
Write-Host "Commit Id1: $commitid1"
Pop-Location

Write-Host "##vso[task.setvariable variable=commit1;isOutput=true]$commitid1"
} else { # This part(else) run in Job_2

Write-Host "==================== Compare two version xml files."
$shortCommitId1 = $commitid1.Substring(0, 7)
$shortCommitId2 = $commitid2.Substring(0, 7)
if($targetRepoUrl.EndsWith(".git"))
{
$compareUrl = $targetRepoUrl.Substring(0, $ymlRepoUrl.Length - 4)
}
else
{
$compareUrl = $targetRepoUrl
Write-Host "==================== Run Mdoc(pr version) tool to generated xml files."
Run-Mdoc $prMdocPath $frameworksPath $xmlPath
if ($lastexitcode -ne 0)
{
exit $lastexitcode
}

Write-Host "==================== Sencond to commit xml files"
$message = "CI Update 2 with build number " + $env:BUILD_BUILDNUMBER
Git-Push $targetRepoPath $githubTokenBase64 $message $targetRepoBranch
$commitid2 = & git rev-parse HEAD
Write-Host "Commit Id2: $commitid2"
Pop-Location

Write-Host "==================== Compare two version xml files."
$commitid1 = $commit1 # commit1 from job_1
$shortCommitId1 = $commitid1.Substring(0, 7)
$shortCommitId2 = $commitid2.Substring(0, 7)
if($targetRepoUrl.EndsWith(".git"))
{
$compareUrl = $targetRepoUrl.Substring(0, $ymlRepoUrl.Length - 4)
}
else
{
$compareUrl = $targetRepoUrl
}

$compareUrl = $compareUrl + "/compare/"
$compareUrl = $compareUrl + "$shortCommitId1...$shortCommitId2/"

Write-Host ("##vso[task.setvariable variable=CompareUrl;]$compareUrl")
Write-Host "Compare Url: $compareUrl"
}

$compareUrl = $compareUrl + "/compare/"
$compareUrl = $compareUrl + "$shortCommitId1...$shortCommitId2/"

Write-Host ("##vso[task.setvariable variable=CompareUrl;]$compareUrl")
Write-Host "Compare Url: $compareUrl"
}

$params = $paramsJson | ConvertFrom-Json
Expand Down

0 comments on commit 6284e28

Please sign in to comment.