Skip to content

Commit accc2f9

Browse files
authored
Update the codegen pipeline (#19543)
* Update the codegen pipeline * Add logic of submitting PR after genereate code Co-authored-by: wyunchi-ms <[email protected]>
1 parent 723943b commit accc2f9

File tree

1 file changed

+97
-46
lines changed

1 file changed

+97
-46
lines changed

.azure-pipelines/code-gen.yml

Lines changed: 97 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
# Variable 'BaseBranch' was defined in the Variables tab
21
# Variable 'BotAccessToken' was defined in the Variables tab
3-
# Variable 'ServiceName' was defined in the Variables tab
42
# Multi-job configuration must be converted to matrix strategy: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#multi-job-configuration
3+
parameters:
4+
- name: TargetBranch
5+
displayName: Branch this module will generated to
6+
type: string
7+
default: main
8+
- name: ServiceName
9+
displayName: Service to generate
10+
type: string
11+
default: null
12+
513
resources:
614
repositories:
715
- repository: self
816
type: git
917
ref: refs/heads/generation
1018
jobs:
1119
- job: Job_1
12-
displayName: 'Service: '
20+
displayName: "Service: ${{ parameters.ServiceName }}"
1321
timeoutInMinutes: 90
1422
pool:
1523
name: pool-windows-2019
@@ -25,55 +33,98 @@ jobs:
2533
command: custom
2634
verbose: false
2735
customCommand: install -g autorest@latest
28-
- powershell: |
29-
$subModuleFolders = Get-ChildItem -Directory -Filter *.Autorest
30-
31-
if ($subModuleFolders -eq $null) {
32-
autorest --max-memory-size=8192
33-
} else {
34-
$subModuleFolders | foreach-object { cd $_.FullName; autorest --max-memory-size=8192}
35-
}
36-
workingDirectory: src/$(ServiceName)
36+
- task: PowerShell@2
3737
displayName: Generate
38-
condition: eq(variables.ServiceSubmoduleName, '')
39-
- powershell: |
40-
$subModuleFolders = Get-ChildItem -Directory -Filter *.Autorest
41-
if ($subModuleFolders -eq $null) {
42-
./build-module.ps1
43-
} else {
44-
$subModuleFolders | foreach-object { cd $_.FullName; ./build-module.ps1; cd ..}
45-
}
46-
mkdir ../../artifacts/src/$env:SERVICENAME
47-
cp -r ./* ../../artifacts/src/$env:SERVICENAME
48-
workingDirectory: src/$(ServiceName)
38+
inputs:
39+
targetType: inline
40+
script: >-
41+
$subModuleFolders = Get-ChildItem -Directory -Filter *.Autorest;
42+
43+
if ($subModuleFolders -eq $null) {
44+
autorest --max-memory-size=8192;
45+
} else {
46+
$subModuleFolders | foreach-object { cd $_.FullName; autorest --max-memory-size=8192};
47+
}
48+
workingDirectory: src/${{ parameters.ServiceName }}
49+
50+
- task: PowerShell@2
4951
displayName: Build
50-
condition: eq(variables.ServiceSubmoduleName, '')
51-
- powershell: |
52-
mkdir src/$env:SERVICENAME
53-
git checkout src/$env:SERVICENAME
54-
git checkout -b codegen/$env:SERVICENAME origin/$env:BaseBranch
52+
inputs:
53+
targetType: inline
54+
script: >-
55+
$subModuleFolders = Get-ChildItem -Directory -Filter *.Autorest;
56+
57+
if ($subModuleFolders -eq $null) {
58+
./build-module.ps1;
59+
} else {
60+
$subModuleFolders | foreach-object { cd $_.FullName; ./build-module.ps1; cd ..}
61+
}
62+
63+
mkdir ../../artifacts/src/${{ parameters.ServiceName }};
64+
65+
cp -r ./* ../../artifacts/src/${{ parameters.ServiceName }};
66+
pwsh: true
67+
workingDirectory: src/${{ parameters.ServiceName }}
68+
- task: PowerShell@2
5569
displayName: Checkout main branch
56-
- powershell: |
70+
inputs:
71+
targetType: inline
72+
script: >-
73+
if ((Test-Path src/${{ parameters.ServiceName }}))
74+
{
75+
rm -r src/${{ parameters.ServiceName }};
76+
}
77+
git checkout src/${{ parameters.ServiceName }};
78+
git checkout -b codegen/${{ parameters.ServiceName }} origin/${{ parameters.TargetBranch }};
79+
- pwsh: |
5780
#Uninstall-Module -Name PackageManagement -AllVersions
58-
Install-Module -Name PowerShellGet -RequiredVersion 2.2.3 -Force
59-
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force
60-
Install-Module -Name Az.Accounts -Force
61-
Import-Module .\tools\Gen2Master\MoveFromGeneration2Master.ps1
62-
63-
$subModuleFolders = Get-ChildItem .\artifacts\src\$env:SERVICENAME -Directory -Filter *.Autorest
81+
Install-Module -Name PowerShellGet -RequiredVersion 2.2.3 -Force;
82+
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force;
83+
Install-Module -Name Az.Accounts -Force;
84+
Import-Module .\tools\Gen2Master\MoveFromGeneration2Master.ps1;
85+
$subModuleFolders = Get-ChildItem .\artifacts\src\${{ parameters.ServiceName }} -Directory -Filter *.Autorest;
6486
if ($subModuleFolders -eq $null) {
65-
Move-Generation2Master -SourcePath .\artifacts\src\$env:SERVICENAME -DestPath .\src\$env:SERVICENAME
87+
Move-Generation2Master -SourcePath .\artifacts\src\${{ parameters.ServiceName }} -DestPath .\src\${{ parameters.ServiceName }};
6688
} else {
67-
Move-Generation2MasterHybrid -SourcePath .\artifacts\src\$env:SERVICENAME -DestPath .\src\$env:SERVICENAME
89+
Move-Generation2MasterHybrid -SourcePath .\artifacts\src\${{ parameters.ServiceName }} -DestPath .\src\${{ parameters.ServiceName }};
6890
}
91+
git config user.email "[email protected]";
92+
git config user.name "azure-powershell-bot";
93+
git add ./src;
94+
git add tools/CreateMappings_rules.json;
95+
git commit -m "Move ${{ parameters.ServiceName }} to ${{ parameters.TargetBranch }}";
96+
git remote set-url origin https://azure-powershell-bot:$(BotAccessToken)@github.com/Azure/azure-powershell.git;
97+
git push origin codegen/${{ parameters.ServiceName }} --force;
98+
displayName: Create codegen/${{ parameters.ServiceName }} branch
99+
- pwsh: |
100+
$Headers = @{"Accept" = "application/vnd.github+json"; "Authorization" = "Bearer $(BotAccessToken)"}
101+
$PrBody = @'
102+
<!-- DO NOT DELETE THIS TEMPLATE -->
103+
104+
## Description
105+
106+
<!-- 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. -->
107+
108+
## Checklist
69109
70-
git config user.email "[email protected]"
71-
git config user.name "azure-powershell-bot"
72-
git add ./src
73-
git add tools/CreateMappings_rules.json
74-
git commit -m "Move $env:SERVICENAME to $env:BaseBranch"
75-
git remote set-url origin https://azure-powershell-bot:$(BotAccessToken)@github.com/Azure/azure-powershell.git
76-
git push origin codegen/$env:SERVICENAME
77-
displayName: Move code to main
78-
condition: eq(variables.ServiceSubmoduleName, '')
110+
- [x] Check this box to confirm: **I have read the [_Submitting Changes_](../blob/main/CONTRIBUTING.md#submitting-changes) section of [`CONTRIBUTING.md`](../blob/main/CONTRIBUTING.md) and reviewed the following information:**
79111
112+
* **SHOULD** select appropriate branch. Cmdlets from Autorest.PowerShell should go to [`generation`](https://github.com/Azure/azure-powershell/tree/generation) branch.
113+
* **SHOULD** make the title of PR clear and informative, and in the present imperative tense.
114+
* **SHOULD** update `ChangeLog.md` file(s) appropriately
115+
* For any service, the `ChangeLog.md` file can be found at `src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md`
116+
* A snippet outlining the change(s) made in the PR should be written under the `## Upcoming Release` header in the past tense. Add changelog in description section if PR goes into [`generation`](https://github.com/Azure/azure-powershell/tree/generation) branch.
117+
* Should **not** change `ChangeLog.md` if no new release is required, such as fixing test case only.
118+
* **SHOULD** have approved design review for the changes in [this repository](https://github.com/Azure/azure-powershell-cmdlet-review-pr) ([_Microsoft internal only_](../blob/main/CONTRIBUTING.md#onboarding)) with following situations
119+
* Create new module from scratch
120+
* Create new resource types which are not easy to conform to [Azure PowerShell Design Guidelines](../blob/main/documentation/development-docs/design-guidelines)
121+
* Create new resource type which name doesn't use module name as prefix
122+
* Have design question before implementation
123+
* **SHOULD** regenerate markdown help files if there is cmdlet API change. [Instruction](../blob/main/documentation/development-docs/help-generation.md#updating-all-markdown-files-in-a-module)
124+
* **SHOULD** have proper test coverage for changes in pull request.
125+
* **SHOULD NOT** introduce [breaking changes](../blob/main/documentation/breaking-changes/breaking-changes-definition.md) in Az minor release except preview version.
126+
* **SHOULD NOT** adjust version of module manually in pull request
127+
'@
128+
$RequestBody = @{"title" = "Migrate ${{ parameters.ServiceName }} from generation to ${{ parameters.TargetBranch }}"; "body" = $PrBody; "head" = "codegen/${{ parameters.ServiceName }}"; "base" = "${{ parameters.TargetBranch }}" }
129+
Invoke-WebRequest -Uri https://api.github.com/repos/Azure/azure-powershell/pulls -method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json)
130+
displayName: Create PR to main branch

0 commit comments

Comments
 (0)