diff --git a/.azure-pipelines/SyncDocsConfig.json b/.azure-pipelines/SyncDocsConfig.json new file mode 100644 index 000000000000..6d51efb367b3 --- /dev/null +++ b/.azure-pipelines/SyncDocsConfig.json @@ -0,0 +1,7 @@ +{ + "SyncPath": [ + "documentation/breaking-changes/upcoming-breaking-changes.md" + ], + "UnSyncPath": [ + ] +} diff --git a/.azure-pipelines/sync-MSdoc.yml b/.azure-pipelines/sync-MSdoc.yml new file mode 100644 index 000000000000..53db11a6207a --- /dev/null +++ b/.azure-pipelines/sync-MSdoc.yml @@ -0,0 +1,56 @@ +resources: + repositories: + - repository: self + type: git + ref: main + +trigger: + branches: + include: + - main + paths: + include: + - documentation\breaking-changes\upcoming-breaking-changes.md + +variables: + TargetedRepo: azure-docs-powershell + TargetedBranchName: sync-upcoming-breaking-changes + GithubToken: $(GITHUB_TOKEN) + +jobs: +- job: Sync + displayName: Sync task + condition: succeeded() + strategy: + matrix: + Generation: + BranchName: ${{ variables.TargetedBranchName }} + + steps: + - task: PowerShell@2 + displayName: Sync branch + inputs: + targetType: inline + script: >- + ./tools/SyncDocsToMicrosoftDocsOrg.ps1 -BranchName $(BranchName) -GithubToken $(GithubToken) + pwsh: true + + - pwsh: | + $Title = "Sync upcoming breaking changes docs from Azure/azure-powershell repo" + $HeadBranch = "$(BranchName)" + $BaseBranch = "main" + $Description = "Sync latest upcoming breaking changes doc from Azure/azure-powershell repo." + $Headers = @{"Accept" = "application/vnd.github+json"; "Authorization" = "Bearer $(GithubToken)"} + $PrBody = @" + + + ## Description + $Description + + + "@ + $RequestBody = @{"title" = $Title; "body" = $PrBody; "head" = $HeadBranch; "base" = $BaseBranch } + Invoke-WebRequest -Uri https://api.github.com/repos/MicrosoftDocs/azure-docs-powershell/pulls -method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json) + + continueOnError: true + displayName: Create PR to main branch \ No newline at end of file diff --git a/tools/SyncDocsToMicrosoftDocsOrg.ps1 b/tools/SyncDocsToMicrosoftDocsOrg.ps1 new file mode 100644 index 000000000000..71f7d934b172 --- /dev/null +++ b/tools/SyncDocsToMicrosoftDocsOrg.ps1 @@ -0,0 +1,64 @@ +# Sync doc from Azure/azure-powershell to MicrosoftDocs/azure-docs-powershell +[CmdletBinding()] +param( + [Parameter()] + [string]$RepoName = "azure-docs-powershell", + [Parameter()] + [string]$OrgName = "MicrosoftDocs", + [Parameter()] + [string]$BranchName, + [Parameter()] + [string]$WorkSpace, + [Parameter()] + [string]$GithubToken +) + +# The absolute location of repos +$WorkSpace = (Resolve-Path (Join-Path $PSScriptRoot "../../")).Path +$RepoCloneLink = "https://github.com/$OrgName/$RepoName.git" +$Config = Get-Content (Join-Path $PSScriptRoot "../.azure-pipelines/SyncDocsConfig.json") | ConvertFrom-Json +$TmpFolder = Resolve-Path (New-Item -ItemType Directory -Path tmp) +# Get az version to match target folder +$AzVersion = (Import-PowerShellDataFile -Path "$PSScriptRoot\Az\Az.psd1").ModuleVersion + +foreach ($SyncPath in $Config.SyncPath) +{ + Write-Host "Back up $SyncPath from main branch." + Copy-Item -Path $SyncPath -Destination $TmpFolder -Recurse -Force +} + +$SyncFile = Split-Path $SyncPath -Leaf + +git config user.email "65331932+azure-powershell-bot@users.noreply.github.com" +git config user.name "azure-powershell-bot" + +cd $WorkSpace +git clone $RepoCloneLink +cd $RepoName +git checkout -b $BranchName + + +foreach ($SyncPath in $Config.SyncPath) +{ + $Date = Get-Date -Format MM/dd/yyyy + $Header = @" +--- +description: Learn about upcoming breaking changes to the Azure Az PowerShell module +ms.custom: devx-track-azurepowershell +ms.date: $Date +ms.devlang: powershell +ms.service: azure-powershell +ms.topic: conceptual +title: Upcoming breaking changes in Azure PowerShell +--- + +"@ + + $Header + (Get-Content $TmpFolder\$SyncFile -Raw) | Set-Content $TmpFolder\$SyncFile + Copy-Item $TmpFolder\$SyncFile (Join-Path $WorkSpace $RepoName/docs-conceptual/azps-$AzVersion) -Force + git add (Join-Path $WorkSpace $RepoName/docs-conceptual/azps-$AzVersion) +} + +git commit -m "Sync upcoming breaking changes doc from azure-powershell repo." +git remote set-url origin "https://$GithubToken@github.com/$OrgName/$RepoName.git" +git push origin "$BranchName" --force