From 855e230903bdc0adbe9080bbbeb40ad877eef537 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 8 May 2022 11:35:42 +0200 Subject: [PATCH 1/5] First commit --- settings.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/settings.json b/settings.json index a25371a5d3..877323bde3 100644 --- a/settings.json +++ b/settings.json @@ -12,5 +12,9 @@ } ] }, - "enableDefaultTelemetry": true + "enableDefaultTelemetry": true, + "pesterConfiguration": { + "testForAzureDevOpsPipelines": true, + "testForGitHubPipelines": true + } } From 0e16c6b8e33b4c6e4da27b7daaa78bc756872ed6 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 8 May 2022 12:20:05 +0200 Subject: [PATCH 2/5] Added test cases for pipelines --- arm/.global/global.module.tests.ps1 | 39 +++++++++++++++++++++++----- utilities/tools/Set-ModuleReadMe.ps1 | 1 - 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/arm/.global/global.module.tests.ps1 b/arm/.global/global.module.tests.ps1 index 03b11009d5..c81d1cf1e0 100644 --- a/arm/.global/global.module.tests.ps1 +++ b/arm/.global/global.module.tests.ps1 @@ -37,6 +37,37 @@ Describe 'File/folder tests' -Tag Modules { $moduleFolderTestCases += @{ moduleFolderName = $moduleFolderPath.Replace('\', '/').Split('/arm/')[1] moduleFolderPath = $moduleFolderPath + isTopLevelModule = $moduleFolderPath.Replace('\', '/').Split('/arm/')[1].Split('/').Count -eq 2 # / + } + } + + if ($settings.pesterConfiguration.testForGitHubPipelines) { + It '[] Module should have a GitHub workflow' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { + + param( + [string] $moduleFolderName, + [string] $moduleFolderPath + ) + + $workflowsFolderName = Join-Path $RepoRoot '.github' 'workflows' + $workflowFileName = '{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('Microsoft', 'ms').ToLower() + + Test-Path (Join-Path $workflowsFolderName $workflowFileName) | Should -Be $true + } + } + + if ($settings.pesterConfiguration.testForAzureDevOpsPipelines) { + It '[] Module should have an Azure DevOps pipeline' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { + + param( + [string] $moduleFolderName, + [string] $moduleFolderPath + ) + + $pipelinesFolderName = Join-Path $RepoRoot '.azuredevops' 'modulePipelines' + $pipelineFileName = '{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('Microsoft', 'ms').ToLower() + + Test-Path (Join-Path $pipelinesFolderName $pipelineFileName) | Should -Be $true } } @@ -53,13 +84,9 @@ Describe 'File/folder tests' -Tag Modules { (Test-Path (Join-Path -Path $moduleFolderPath 'readme.md')) | Should -Be $true } - It '[] Module should contain a [.parameters] folder' -TestCases $moduleFolderTestCases { + It '[] Module should contain a [.parameters] folder' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { param( [string] $moduleFolderPath ) - if ((Split-Path (Split-Path $moduleFolderPath -Parent) -Leaf) -like 'Microsoft.*') { - (Test-Path (Join-Path -Path $moduleFolderPath '.parameters')) | Should -Be $true - } else { - $true | Should -Be $true - } + Test-Path (Join-Path -Path $moduleFolderPath '.parameters') | Should -Be $true } It '[] Module should contain a [version.json] file' -TestCases $moduleFolderTestCases { diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 3c1e46a9b9..5170f6bca2 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -95,7 +95,6 @@ function Set-ResourceTypesSection { $_.type -notin $ResourceTypesToExclude -and $_ } | Select-Object 'Type', 'ApiVersion' -Unique | Sort-Object Type -Culture en-US - $TextInfo = (Get-Culture).TextInfo foreach ($resourceTypeObject in $RelevantResourceTypeObjects) { $ProviderNamespace, $ResourceType = $resourceTypeObject.Type -split '/', 2 # Validate if Reference URL Is working From 6081fff3b46ae2c1a8b37a492bae8729c3403023 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 8 May 2022 12:37:03 +0200 Subject: [PATCH 3/5] Added docs --- arm/.global/global.module.tests.ps1 | 4 ++-- ... Onboard module library and CI environment.md | 16 +++++++++++++--- settings.json | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arm/.global/global.module.tests.ps1 b/arm/.global/global.module.tests.ps1 index c81d1cf1e0..3d9817b685 100644 --- a/arm/.global/global.module.tests.ps1 +++ b/arm/.global/global.module.tests.ps1 @@ -41,7 +41,7 @@ Describe 'File/folder tests' -Tag Modules { } } - if ($settings.pesterConfiguration.testForGitHubPipelines) { + if ($settings.pesterConfiguration.enableGitHubSpecificTests) { It '[] Module should have a GitHub workflow' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { param( @@ -56,7 +56,7 @@ Describe 'File/folder tests' -Tag Modules { } } - if ($settings.pesterConfiguration.testForAzureDevOpsPipelines) { + if ($settings.pesterConfiguration.enableAzureDevOpsSpecificTests) { It '[] Module should have an Azure DevOps pipeline' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { param( diff --git a/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md b/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md index c5117269b6..1c6e8322ef 100644 --- a/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md +++ b/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md @@ -78,7 +78,8 @@ Alternatively, you can also do the same with a specific release by navigating to To configure the CI environment you have to perform several tasks: - [3.1 Update default `namePrefix`](#31-update-default-nameprefix) -- [3.2 Setup CI-environment-specific configuration](#32-setup-ci-environment-specific-configuration) +- [3.2 Configure tests](#32-configure-tests) +- [3.3 Setup CI-environment-specific configuration](#33-setup-ci-environment-specific-configuration) > **Note:** While you can use the browser, we recommend that you clone all files to your local machine and update them using, for example, Visual Studio Code. @@ -106,7 +107,16 @@ To update the `namePrefix`, perform the following steps: For further information on the token replacement logic, please refer to the corresponding [Token replacement](./The%20CI%20environment%20-%20Token%20replacement) section. -## 3.2 Setup CI-environment-specific configuration +## 3.2 Configure tests + +In the `settings.json` file you further have the option to configure how Pester tests the environment by adjusting the `pesterConfiguration` object. Following you can find an overview of these options and what they do: + +| Setting | Description | +| - | - | +| `enableAzureDevOpsSpecificTests` | Disables/Enables tests that are specific to an Azure DevOps environment.

Should be disabled if using only a GitHub environment. | +| `enableGitHubSpecificTests` | Disables/Enables tests that are specific to a GitHub environment.

Should be disabled if using only an Azure DevOps environment. | + +## 3.3 Setup CI-environment-specific configuration While the concepts are the same, the configuration of the CI environment can differ drastically depending on the DevOps environment in which you want to register and run your pipelines. Following you can find instructions on how to perform the remaining configuration in the corresponding DevOps environment: @@ -205,7 +215,6 @@ The primary pipeline variable file `global.variables.yml` hosts the fundamental ### 3.2.3 Enable actions - Finally, 'GitHub Actions' are disabled by default and must be enabled for execution. To do so, perform the following steps: @@ -229,6 +238,7 @@ For _Azure DevOps_, you have to perform the following environment-specific steps - [3.2.3 Setup variables file](#323-setup-variables-file) - [3.2.4 Register pipelines](#324-register-pipelines) - [3.2.5 Azure Artifacts Universal Packages](#325-azure-artifacts-universal-packages) + ### 3.2.1 Setup service connection The service connection must be set up in the project's settings under _Pipelines: Service connections_ (a step by step guide can be found [here](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml)). diff --git a/settings.json b/settings.json index 877323bde3..0112590e16 100644 --- a/settings.json +++ b/settings.json @@ -14,7 +14,7 @@ }, "enableDefaultTelemetry": true, "pesterConfiguration": { - "testForAzureDevOpsPipelines": true, - "testForGitHubPipelines": true + "enableAzureDevOpsSpecificTests": true, + "enableGitHubSpecificTests": true } } From 0e9d94055f5d6a2d99ae8cb928aa762d3163b009 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 8 May 2022 22:05:50 +0200 Subject: [PATCH 4/5] Removed test setting --- arm/.global/global.module.tests.ps1 | 4 ++-- settings.json | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/arm/.global/global.module.tests.ps1 b/arm/.global/global.module.tests.ps1 index 3d9817b685..afde7ffbc2 100644 --- a/arm/.global/global.module.tests.ps1 +++ b/arm/.global/global.module.tests.ps1 @@ -41,7 +41,7 @@ Describe 'File/folder tests' -Tag Modules { } } - if ($settings.pesterConfiguration.enableGitHubSpecificTests) { + if (Test-Path (Join-Path $repoRoot '.github')) { It '[] Module should have a GitHub workflow' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { param( @@ -56,7 +56,7 @@ Describe 'File/folder tests' -Tag Modules { } } - if ($settings.pesterConfiguration.enableAzureDevOpsSpecificTests) { + if (Test-Path (Join-Path $repoRoot '.azuredevops')) { It '[] Module should have an Azure DevOps pipeline' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) { param( diff --git a/settings.json b/settings.json index 0112590e16..a25371a5d3 100644 --- a/settings.json +++ b/settings.json @@ -12,9 +12,5 @@ } ] }, - "enableDefaultTelemetry": true, - "pesterConfiguration": { - "enableAzureDevOpsSpecificTests": true, - "enableGitHubSpecificTests": true - } + "enableDefaultTelemetry": true } From a03609d79a879d293afb3a54ac168664ab8da81b Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 8 May 2022 22:08:54 +0200 Subject: [PATCH 5/5] Updated docs --- ... Onboard module library and CI environment.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md b/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md index 1c6e8322ef..6238aec25a 100644 --- a/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md +++ b/docs/wiki/Getting started - Scenario 1 Onboard module library and CI environment.md @@ -78,8 +78,7 @@ Alternatively, you can also do the same with a specific release by navigating to To configure the CI environment you have to perform several tasks: - [3.1 Update default `namePrefix`](#31-update-default-nameprefix) -- [3.2 Configure tests](#32-configure-tests) -- [3.3 Setup CI-environment-specific configuration](#33-setup-ci-environment-specific-configuration) +- [3.2 Setup CI-environment-specific configuration](#32-setup-ci-environment-specific-configuration) > **Note:** While you can use the browser, we recommend that you clone all files to your local machine and update them using, for example, Visual Studio Code. @@ -107,16 +106,7 @@ To update the `namePrefix`, perform the following steps: For further information on the token replacement logic, please refer to the corresponding [Token replacement](./The%20CI%20environment%20-%20Token%20replacement) section. -## 3.2 Configure tests - -In the `settings.json` file you further have the option to configure how Pester tests the environment by adjusting the `pesterConfiguration` object. Following you can find an overview of these options and what they do: - -| Setting | Description | -| - | - | -| `enableAzureDevOpsSpecificTests` | Disables/Enables tests that are specific to an Azure DevOps environment.

Should be disabled if using only a GitHub environment. | -| `enableGitHubSpecificTests` | Disables/Enables tests that are specific to a GitHub environment.

Should be disabled if using only an Azure DevOps environment. | - -## 3.3 Setup CI-environment-specific configuration +## 3.2 Setup CI-environment-specific configuration While the concepts are the same, the configuration of the CI environment can differ drastically depending on the DevOps environment in which you want to register and run your pipelines. Following you can find instructions on how to perform the remaining configuration in the corresponding DevOps environment: @@ -339,7 +329,7 @@ This section will explain what is required to publish the modules to [Azure Arti 1. If you chose the feed to be project-scoped, you will need the Project Build Service account to have `Contributor` access to publish to the Azure Artifacts feed. To set this, follow the [Pipeline permission](https://docs.microsoft.com/en-us/azure/devops/artifacts/feeds/feed-permissions?view=azure-devops#pipelines-permissions) steps. #### Implementation Guidance -Each `./azuredevops/modulePipelines` yaml pipeline already calls `/.azuredevops/pipelineTemplates/jobs.publishModule.yml`. This yaml template contains a method to `Publish module to artifacts feed` via `utilities\pipelines\resourcePublish\Publish-ModuleToUniversalArtifactFeed.ps1`. +Each `./azuredevops/modulePipelines` yaml pipeline already calls `/.azuredevops/pipelineTemplates/jobs.publishModule.yml`. This YAML template contains a method to `Publish module to artifacts feed` via `utilities\pipelines\resourcePublish\Publish-ModuleToUniversalArtifactFeed.ps1`.