Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ".Platform - Update Static Test Documentation"

pr: none

trigger:
batch: true
branches:
include:
- main
paths:
include:
- .azuredevops/platformPipelines/platform.updateStaticTestDocs.yml
- 'utilities/pipelines/staticValidation/module.tests.ps1'
- utilities/tools/platform/Set-StaticTestDocumentation.ps1

variables:
- template: "../../settings.yml"
- name: pipelinePrincipalGitUserName
value: "CARMLPipelinePrincipal"
- name: pipelinePrincipalGitUserEmail
value: "CARML@noreply.github.com"

jobs:
- job: Update_Static_Test_Docs
displayName: Update Static Tests Documentation
pool:
${{ if ne(variables.vmImage, '') }}:
vmImage: ${{ variables.vmImage }}
${{ if ne(variables.poolName, '') }}:
name: ${{ variables.poolName }}
steps:
- checkout: self
persistCredentials: true

- task: PowerShell@2
displayName: "Update file"
inputs:
targetType: inline
pwsh: true
script: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'platform' 'Set-StaticTestDocumentation.ps1')

$functionInput = @{
TestFilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'staticValidation' 'module.tests.ps1'
WikiFilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'docs' 'wiki' 'The CI environment - Static validation.md'
}

Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

Set-StaticTestDocumentation @functionInput -Verbose

- task: PowerShell@2
displayName: "Push changes"
inputs:
targetType: inline
pwsh: true
script: |
git config --global user.email '$(pipelinePrincipalGitUserEmail)'
git config --global user.name '$(pipelinePrincipalGitUserName)'

git add .
git status
git commit -m 'Push updated API Specs file'
git pull $(Build.Repository.Uri) HEAD:$(Build.SourceBranch)
git push $(Build.Repository.Uri) HEAD:$(Build.SourceBranch)
55 changes: 55 additions & 0 deletions .github/workflows/platform.updateStaticTestDocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: ".Platform: Update Static Test Documentation"

on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/workflows/platform.updateStaticTestDocs.yml'
- 'utilities/pipelines/staticValidation/module.tests.ps1'
- utilities/tools/platform/Set-StaticTestDocumentation.ps1

env:
pipelinePrincipalGitUserName: "CARMLPipelinePrincipal"
pipelinePrincipalGitUserEmail: "CARML@noreply.github.com"

jobs:
job_update_static_test_docs:
name: "Update file"
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
runs-on: ubuntu-20.04
steps:
- name: "Checkout"
uses: actions/checkout@v3
with:
fetch-depth: 0
token: "${{ secrets.PLATFORM_REPO_UPDATE_PAT }}" # Sets general GIT credentials up

- name: "Update file"
shell: pwsh
run: |
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'tools' 'platform' 'Set-StaticTestDocumentation.ps1')

$functionInput = @{
TestFilePath = Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'staticValidation' 'module.tests.ps1'
WikiFilePath = Join-Path $env:GITHUB_WORKSPACE 'docs' 'wiki' 'The CI environment - Static validation.md'
}

Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

Set-StaticTestDocumentation @functionInput -Verbose

- name: "Push changes"
shell: pwsh
run: |
git config --global user.email '${{ env.pipelinePrincipalGitUserEmail }}'
git config --global user.name '${{ env.pipelinePrincipalGitUserName }}'

git pull
git status
git add .
git commit -m 'Push updated API Specs file'
git push
75 changes: 55 additions & 20 deletions docs/wiki/The CI environment - Static validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,61 @@ All module Unit tests are performed with the help of [Pester](https://github.com

The following activities are performed by the [`utilities/pipelines/staticValidation/module.tests.ps1`](https://github.com/Azure/ResourceModules/blob/main/utilities/pipelines/staticValidation/module.tests.ps1) script.

- **File & folder tests** validate that the module folder structure is set up in the intended way, e.g.:
- readme.md file exists
- template file (either `deploy.json` or `deploy.bicep`) exists
- compliance with file naming convention
- **Deployment template tests** check the template's structure and elements for errors as well as consistency matters, e.g.:
- template file (or the built bicep template) converts from JSON and has all expected properties
- variable names are camelCase
- the minimum set of outputs is returned (see [module design](./The%20library%20-%20Module%20design#outputs))
- **Module (readme) documentation** contains all required sections, e.g.:
- is not empty
- contains all the mandatory sections
- describes all the parameters
- describes all outputs
- describes all cross-references
- **Module Test Files**, e.g.:
- at least one `deploy.test.bicep` exists
- files should (optionally) be valid JSON
- must contain all required parameters
- (if tokens are used) Tests that no token values (e.g., `11111111-1111-1111-1111-11111111111`) from the specified token list (i.e., `deploymentSpId`, `subscriptionId`, `managementGroupId`, `tenantId`) are used in the module test files. Instead, the token itself should be referenced.
## Outline

- **File/folder tests**
- **General module folder tests**
1. Module should have a GitHub workflow
1. Module should have an Azure DevOps pipeline
1. Module should contain a [`deploy.json`/`deploy.bicep`] file
1. Module should contain a [`readme.md`] file
1. Module should contain a [`.test`] folder
1. Module should contain a [`version.json`] file
- **.test folder**
1. Folder should contain one or more test files
1. JSON test files in the `.test` folder should be valid json
- **Readme tests**
- **Readme content tests**
1. `Readme.md` file should not be empty
1. `Readme.md` file should contain these sections in order: Navigation, Resource Types, Parameters, Outputs, Cross-referenced modules, Deployment examples
1. Resources section should contain all resources from the template file
1. Resources section should not contain more resources than the template file
1. Parameters section should contain a table for each existing parameter category in the following order: Required, Conditional, Optional, Generated
1. Parameter tables should provide columns in the following order: Parameter Name, Type, Default Value, Allowed Values, Description. Each column should be present unless empty for all the rows.
1. Parameters section should contain all parameters from the template file
1. Outputs section should contain a table with these column names in order: Output Name, Type
1. Output section should contain all outputs defined in the template file
1. Dependencies section should contain all cross-references defined in the template file
1. `Set-ModuleReadMe` script should not apply any updates
- **Test file tests**
- **General test file**
1. Bicep test deployment name should contain [`-test-`]
1. Bicep test deployment should have parameter [`serviceShort`]
1. JSON test deployment name should contain [`-test-`]
1. JSON test deployment should have parameter [`serviceShort`]
- **Token usage**
1. [Tokens] Test file should not contain the plain value for token guid
- **Deployment template tests**
- **General template**
1. The template file should not be empty
1. Template schema version should be the latest
1. Template schema should use HTTPS reference
1. All apiVersion properties should be set to a static, hard-coded value
1. The template file should contain required elements: `schema`, `contentVersion`, `resources`
1. If delete lock is implemented, the template should have a lock parameter with an empty default value
1. Parameter names should be camel-cased (no dashes or underscores and must start with lower-case letter)
1. Variable names should be camel-cased (no dashes or underscores and must start with lower-case letter)
1. Output names should be camel-cased (no dashes or underscores and must start with lower-case letter)
1. CUA ID deployment should be present in the template
1. Location output should be returned for resources that use it
1. Resource Group output should exist for resources that are deployed into a resource group scope
1. Resource name output should exist
1. Resource ID output should exist
1. All parameters in parameters files exist in template file (`deploy.json`)
1. All required parameters in template file (`deploy.json`) should exist in parameters files
1. All non-required parameters in template file should not have description that start with "Required."
- **API version tests**
1. In used resource type should use one of the recent API version(s). Currently using

## Output example

Expand Down Expand Up @@ -85,4 +121,3 @@ Test-ModuleLocally @TestModuleLocallyInput -Verbose
```

> You can use the `Get-Help` cmdlet to show more options on how you can use this script.

Loading