From 096f450195255eb5b18b7b8f4b5f09e94c62cb59 Mon Sep 17 00:00:00 2001 From: Ahmad Abdalla <28486158+ahmadabdalla@users.noreply.github.com> Date: Tue, 5 Sep 2023 17:55:56 +1000 Subject: [PATCH] [CI Platform] Enabled module publishing from feature branch prerelease publishing without publishing stable version (#3906) --- .../pipelineTemplates/jobs.publishModule.yml | 36 ++++++++++++++++++- .../templates/publishModule/action.yml | 14 ++++++++ utilities/tools/Set-ModuleReadMe.ps1 | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/.azuredevops/pipelineTemplates/jobs.publishModule.yml b/.azuredevops/pipelineTemplates/jobs.publishModule.yml index 5087e1244f..801409be31 100644 --- a/.azuredevops/pipelineTemplates/jobs.publishModule.yml +++ b/.azuredevops/pipelineTemplates/jobs.publishModule.yml @@ -184,6 +184,13 @@ jobs: } } + # Filter modules to publish 'prerelease' only if branch is not main/master + $BranchName = '$(Build.SourceBranch)' + if ($BranchName -ne 'refs/heads/main' -and $BranchName -ne 'refs/heads/master') { + Write-Verbose "Filtering modules to only publish a [prerelease] version as the current branch [$BranchName] is not [main/master]." -Verbose + $modulesToPublish = $modulesToPublish | Where-Object -Property version -like '*-prerelease' + } + ################# ## Publish ## ################# @@ -225,6 +232,13 @@ jobs: pwsh: true ScriptType: InlineScript inline: | + # Load PS-Profile configuration + if (Test-Path $profile) { + . $profile + } else { + Write-Warning "No profile loaded from location [$profile]" + } + # Set context to chosen subscription Write-Verbose ('Setting context to subscription [{0}]' -f '${{ parameters.subscriptionId }}') -Verbose $null = Set-AzContext -Subscription '${{ parameters.subscriptionId }}' @@ -279,6 +293,13 @@ jobs: } } + # Filter modules to publish 'prerelease' only if branch is not main/master + $BranchName = '$(Build.SourceBranch)' + if ($BranchName -ne 'refs/heads/main' -and $BranchName -ne 'refs/heads/master') { + Write-Verbose "Filtering modules to only publish a [prerelease] version as the current branch [$BranchName] is not [main/master]." -Verbose + $modulesToPublish = $modulesToPublish | Where-Object -Property version -like '*-prerelease' + } + ################# ## Publish ## ################# @@ -316,8 +337,14 @@ jobs: scriptType: pscore scriptLocation: inlineScript inlineScript: | + # Load PS-Profile configuration + if (Test-Path $profile) { + . $profile + } else { + Write-Warning "No profile loaded from location [$profile]" + } + # Log into Az-PowerShell context - . $profile # Load PS-Profile configuration $SecuredPassword = ConvertTo-SecureString -AsPlainText -String $env:servicePrincipalKey $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:servicePrincipalId, $SecuredPassword $null = Connect-AzAccount -ServicePrincipal -TenantId $env:tenantId -Credential $Credential @@ -370,6 +397,13 @@ jobs: $missingModules = Get-ModulesMissingFromPrivateBicepRegistry @missingInputObject + # Filter modules to publish 'prerelease' only if branch is not main/master + $BranchName = '$(Build.SourceBranch)' + if ($BranchName -ne 'refs/heads/main' -and $BranchName -ne 'refs/heads/master') { + Write-Verbose "Filtering modules to only publish a [prerelease] version as the current branch [$BranchName] is not [main/master]." -Verbose + $modulesToPublish = $modulesToPublish | Where-Object -Property version -like '*-prerelease' + } + foreach($missingModule in $missingModules) { if($modulsToPublish.TemplateFilePath -notcontains $missingModule.TemplateFilePath) { $modulesToPublish += $missingModule diff --git a/.github/actions/templates/publishModule/action.yml b/.github/actions/templates/publishModule/action.yml index 53f1415b7e..7645e7eb21 100644 --- a/.github/actions/templates/publishModule/action.yml +++ b/.github/actions/templates/publishModule/action.yml @@ -141,6 +141,13 @@ runs: } } + # Filter modules to publish 'prerelease' only if branch is not main/master + $BranchName = "$env:GITHUB_REF_NAME" + if ($BranchName -ne 'main' -and $BranchName -ne 'master') { + Write-Verbose "Filtering modules to only publish a [prerelease] version as the current branch [$BranchName] is not [main/master]." -Verbose + $modulesToPublish = $modulesToPublish | Where-Object -Property version -like '*-prerelease' + } + ################# ## Publish ## ################# @@ -222,6 +229,13 @@ runs: } } + # Filter modules to publish 'prerelease' only if branch is not main/master + $BranchName = "$env:GITHUB_REF_NAME" + if ($BranchName -ne 'main' -and $BranchName -ne 'master') { + Write-Verbose "Filtering modules to only publish a [prerelease] version as the current branch [$BranchName] is not [main/master]." -Verbose + $modulesToPublish = $modulesToPublish | Where-Object -Property version -like '*-prerelease' + } + ################# ## Publish ## ################# diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index c57bd40ba6..fd32b00ae5 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -1579,7 +1579,7 @@ function Set-ModuleReadMe { } $moduleRoot = Split-Path $TemplateFilePath -Parent - $fullModuleIdentifier = $moduleRoot.Replace('\', '/').split('modules/')[1] + $fullModuleIdentifier = $moduleRoot.Replace('\', '/').split('modules/')[-1] # Custom modules are modules having the same resource type but different properties based on the name # E.g., web/site/config--appsetting vs web/site/config--authsettingv2 $customModuleSeparator = '--'