Skip to content

Commit a491163

Browse files
NoriZCwyunchi-ms
andauthored
Sync upcoming breaking changes doc (#20925)
* Test Sync docs between 2 repos under NoriZC * Change to absolute temp location * Split file while copying to doc repo * Change branch name to checkout * Change pr org * Change file location * Change file location 2 * Switch HEAD and Base * Switch to MicrosoftDocs org and azure-bot. * Add header to markdown file. * Remove indents of header * Set Create PR process as optional * Try to skip pr when existed. * Try to skip pr when existed * Update pr description * Update tools/SyncDocs.ps1 Co-authored-by: Yunchi Wang <[email protected]> * Make the script name clear and add some comments. * Update ps1 path --------- Co-authored-by: Yunchi Wang <[email protected]>
1 parent 9db4c3b commit a491163

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

.azure-pipelines/SyncDocsConfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"SyncPath": [
3+
"documentation/breaking-changes/upcoming-breaking-changes.md"
4+
],
5+
"UnSyncPath": [
6+
]
7+
}

.azure-pipelines/sync-MSdoc.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
resources:
2+
repositories:
3+
- repository: self
4+
type: git
5+
ref: main
6+
7+
trigger:
8+
branches:
9+
include:
10+
- main
11+
paths:
12+
include:
13+
- documentation\breaking-changes\upcoming-breaking-changes.md
14+
15+
variables:
16+
TargetedRepo: azure-docs-powershell
17+
TargetedBranchName: sync-upcoming-breaking-changes
18+
GithubToken: $(GITHUB_TOKEN)
19+
20+
jobs:
21+
- job: Sync
22+
displayName: Sync task
23+
condition: succeeded()
24+
strategy:
25+
matrix:
26+
Generation:
27+
BranchName: ${{ variables.TargetedBranchName }}
28+
29+
steps:
30+
- task: PowerShell@2
31+
displayName: Sync branch
32+
inputs:
33+
targetType: inline
34+
script: >-
35+
./tools/SyncDocsToMicrosoftDocsOrg.ps1 -BranchName $(BranchName) -GithubToken $(GithubToken)
36+
pwsh: true
37+
38+
- pwsh: |
39+
$Title = "Sync upcoming breaking changes docs from Azure/azure-powershell repo"
40+
$HeadBranch = "$(BranchName)"
41+
$BaseBranch = "main"
42+
$Description = "Sync latest upcoming breaking changes doc from Azure/azure-powershell repo."
43+
$Headers = @{"Accept" = "application/vnd.github+json"; "Authorization" = "Bearer $(GithubToken)"}
44+
$PrBody = @"
45+
<!-- DO NOT DELETE THIS TEMPLATE -->
46+
47+
## Description
48+
$Description
49+
50+
<!-- Please add a brief description of the changes made in this PR. If you have an ongoing or finished cmdlet design, please paste the link below. -->
51+
"@
52+
$RequestBody = @{"title" = $Title; "body" = $PrBody; "head" = $HeadBranch; "base" = $BaseBranch }
53+
Invoke-WebRequest -Uri https://api.github.com/repos/MicrosoftDocs/azure-docs-powershell/pulls -method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json)
54+
55+
continueOnError: true
56+
displayName: Create PR to main branch

tools/SyncDocsToMicrosoftDocsOrg.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Sync doc from Azure/azure-powershell to MicrosoftDocs/azure-docs-powershell
2+
[CmdletBinding()]
3+
param(
4+
[Parameter()]
5+
[string]$RepoName = "azure-docs-powershell",
6+
[Parameter()]
7+
[string]$OrgName = "MicrosoftDocs",
8+
[Parameter()]
9+
[string]$BranchName,
10+
[Parameter()]
11+
[string]$WorkSpace,
12+
[Parameter()]
13+
[string]$GithubToken
14+
)
15+
16+
# The absolute location of repos
17+
$WorkSpace = (Resolve-Path (Join-Path $PSScriptRoot "../../")).Path
18+
$RepoCloneLink = "https://github.com/$OrgName/$RepoName.git"
19+
$Config = Get-Content (Join-Path $PSScriptRoot "../.azure-pipelines/SyncDocsConfig.json") | ConvertFrom-Json
20+
$TmpFolder = Resolve-Path (New-Item -ItemType Directory -Path tmp)
21+
# Get az version to match target folder
22+
$AzVersion = (Import-PowerShellDataFile -Path "$PSScriptRoot\Az\Az.psd1").ModuleVersion
23+
24+
foreach ($SyncPath in $Config.SyncPath)
25+
{
26+
Write-Host "Back up $SyncPath from main branch."
27+
Copy-Item -Path $SyncPath -Destination $TmpFolder -Recurse -Force
28+
}
29+
30+
$SyncFile = Split-Path $SyncPath -Leaf
31+
32+
git config user.email "[email protected]"
33+
git config user.name "azure-powershell-bot"
34+
35+
cd $WorkSpace
36+
git clone $RepoCloneLink
37+
cd $RepoName
38+
git checkout -b $BranchName
39+
40+
41+
foreach ($SyncPath in $Config.SyncPath)
42+
{
43+
$Date = Get-Date -Format MM/dd/yyyy
44+
$Header = @"
45+
---
46+
description: Learn about upcoming breaking changes to the Azure Az PowerShell module
47+
ms.custom: devx-track-azurepowershell
48+
ms.date: $Date
49+
ms.devlang: powershell
50+
ms.service: azure-powershell
51+
ms.topic: conceptual
52+
title: Upcoming breaking changes in Azure PowerShell
53+
---
54+
55+
"@
56+
57+
$Header + (Get-Content $TmpFolder\$SyncFile -Raw) | Set-Content $TmpFolder\$SyncFile
58+
Copy-Item $TmpFolder\$SyncFile (Join-Path $WorkSpace $RepoName/docs-conceptual/azps-$AzVersion) -Force
59+
git add (Join-Path $WorkSpace $RepoName/docs-conceptual/azps-$AzVersion)
60+
}
61+
62+
git commit -m "Sync upcoming breaking changes doc from azure-powershell repo."
63+
git remote set-url origin "https://$GithubToken@github.com/$OrgName/$RepoName.git"
64+
git push origin "$BranchName" --force

0 commit comments

Comments
 (0)