Skip to content

Commit 78de4fe

Browse files
authored
Ping the PowerShell Version to 7.2.11 in codegen pipeline (#24215)
* Fix the powershell version * Refactor * Update MoveFromGeneration2Master.ps1 * Update code-gen.yml * Resolve issues * Resolve issues
1 parent 5ade454 commit 78de4fe

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

.azure-pipelines/code-gen.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,25 @@ jobs:
7575
}
7676
git checkout src/${{ parameters.ServiceName }};
7777
git checkout -b codegen/${{ parameters.ServiceName }} origin/${{ parameters.TargetBranch }};
78-
- pwsh: |
79-
#Uninstall-Module -Name PackageManagement -AllVersions
80-
Install-Module -Name PowerShellGet -RequiredVersion 2.2.3 -Force;
81-
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force;
82-
Install-Module -Name Az.Accounts -Force;
83-
Import-Module .\tools\Gen2Master\MoveFromGeneration2Master.ps1;
84-
Move-Generation2Master -SourcePath .\artifacts\src\${{ parameters.ServiceName }} -DestPath .\src\${{ parameters.ServiceName }};
85-
git config user.email "65331932+azure-powershell-bot@users.noreply.github.com";
86-
git config user.name "azure-powershell-bot";
87-
git add ./src;
88-
git add tools/CreateMappings_rules.json;
89-
git commit -m "Move ${{ parameters.ServiceName }} to ${{ parameters.TargetBranch }}";
90-
git remote set-url origin https://azure-powershell-bot:$(GithubToken)@github.com/Azure/azure-powershell.git;
91-
git push origin codegen/${{ parameters.ServiceName }} --force;
92-
displayName: Create codegen/${{ parameters.ServiceName }} branch
78+
- task: PowerShell@2
79+
displayName: 'Create codegen/${{ parameters.ServiceName }} branch'
80+
inputs:
81+
targetType: 'inline'
82+
script: |
83+
#Uninstall-Module -Name PackageManagement -AllVersions;
84+
Install-Module -Name PowerShellGet -RequiredVersion 2.2.3 -Force;
85+
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force;
86+
Install-Module -Name Az.Accounts -Force;
87+
Import-Module .\tools\Gen2Master\MoveFromGeneration2Master.ps1;
88+
Move-Generation2Master -SourcePath .\artifacts\src\${{ parameters.ServiceName }} -DestPath .\src\${{ parameters.ServiceName }};
89+
git config user.email "65331932+azure-powershell-bot@users.noreply.github.com";
90+
git config user.name "azure-powershell-bot";
91+
git add src;
92+
git add tools/CreateMappings_rules.json;
93+
git commit -m "Move ${{ parameters.ServiceName }} to ${{ parameters.TargetBranch }}";
94+
git remote set-url origin https://azure-powershell-bot:$(GithubToken)@github.com/Azure/azure-powershell.git;
95+
git push origin codegen/${{ parameters.ServiceName }} --force;
96+
arguments: '-RequiredPsVersion $(PSVersion)'
9397
- pwsh: |
9498
$SourceBranch = "$(Build.SourceBranch)"
9599
$SourceBranch = $SourceBranch.Replace("refs/heads/", "")
@@ -101,4 +105,4 @@ jobs:
101105
$(git log -1 origin/$SourceBranch -- ./src/${{ parameters.ServiceName }})
102106
"
103107
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GithubToken) -Description $Description
104-
displayName: Create PR to main branch
108+
displayName: Create PR to main branch

tools/Gen2Master/MoveFromGeneration2Master.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ Function Move-Generation2Master {
2424

2525
process {
2626
#Region Handle the module whoes folder is a subfolder of the module folder.
27-
$ModuleName = $SourcePath.Replace('/', '\').Split('\src\')[1].Split('\')[0]
27+
if (-not (Test-Path -Path $SourcePath)) {
28+
Write-Error "The source path $SourcePath does not exist." -ForegroundColor Red
29+
return
30+
}
31+
$SourceFolder = Get-Item -Path $SourcePath
32+
$ModuleName = $SourceFolder.Name
2833

2934
$DestParentPath = $DestPath
3035
While ("" -ne $DestParentPath) {
@@ -43,6 +48,7 @@ Function Move-Generation2Master {
4348
New-Item "$DestPath\$ModuleName\help" -ItemType Directory
4449
Update-MappingJson $ModuleName
4550
}
51+
$DestPath = (Get-Item -Path $DestPath).FullName
4652
$Dir2Copy = @{
4753
'custom' = 'custom'
4854
'examples' = 'examples'
@@ -68,7 +74,7 @@ Function Move-Generation2Master {
6874
$Psd1Metadata = Import-LocalizedData -BaseDirectory "$PSScriptRoot/Templates" -FileName "Module.psd1"
6975
}
7076
foreach ($submoduleDir in $submoduleDirs) {
71-
$psd1File = Get-ChildItem -Filter *.psd1 -File -Path $submoduleDir
77+
$psd1File = Get-ChildItem -Filter *.psd1 -File -Path $submoduleDir.FullName
7278
write-host ("psd1 file name {0}" -f $psd1File.Name)
7379
$submoduleName = $psd1File.Name.Split('.')[-2]
7480
Foreach ($Dir in $Dir2Copy.GetEnumerator()) {

0 commit comments

Comments
 (0)