Skip to content

Commit

Permalink
Update the module.tests.ps1 template (#466)
Browse files Browse the repository at this point in the history
Update template for module.tests.ps1. Fixes #465
  • Loading branch information
Sidoran authored Apr 6, 2024
1 parent 5c10447 commit 5b43dd8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Update template for module.tests.ps1. Fixes [#465](https://github.com/gaelcolas/Sampler/issues/465)
- Now the tasks work when using `Set-SamplerTaskVariable` with tasks that
do not have the parameter `ChocolateyBuildOutput`.
- Remove duplicate SECURITY.md template files, and fix templates to
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,45 @@ Invoke-Plaster @invokePlasterParameters
>**Note:** The `GCPackage` template is not yet available, but can be created using
>the `dsccommunity` template with modifications, see the section [GCPackage scaffolding](#gcpackage-scaffolding).
### How to work with the multi-module repository

Typically, such as with a community-driven module, you would have a single
git repository dedicated to each module. However, there are situations where
you might opt for a single git repository to encompass multiple modules. If
you intend to establish a multi-module repository, ensure that each module
is housed within its own folder. Each module's folder structure should be
distinct and should not overlap with the folder structure of other modules.

> [!TIP]
> Right folder structure
```bash
GitRootFolder
├───Module1
├───Module2
├───SomeModuleGroup #Not a module
│ ├───GroupModule1
│ └───GroupModule2
└───Module3
```

> [!CAUTION]
> Wrong folder structure
```bash
GitRootFolder
├───Module1
├───Module2
├───Module3
│ ├───SubModule1
│ └───SubModule2
└───Module3
```

>[!NOTE]
>You can utilize the gitversion tag-prefix to differentiate tags for each module
>separately. [gitVersion configuration](https://gitversion.net/docs/reference/configuration)
### How to download dependencies for the project

To be able to build the project, all the dependencies listed in the file
Expand Down Expand Up @@ -709,6 +748,7 @@ _Guest Configuration_. This process will be replaced with a Plaster template.
1. Replace build image with `windows-latest`.
1. In the job `Package_Module` after the job `gitversion` and before the job
`package` add this new job:

```yaml
- task: PowerShell@2
name: Exp_Feature
Expand All @@ -726,19 +766,24 @@ _Guest Configuration_. This process will be replaced with a Plaster template.
env:
ModuleVersion: $(gitVersion.NuGetVersionV2)
```

1. Remove the job `Test_HQRM`.
1. Remove the job `Test_Integration`.
1. Remove the job `Code_Coverage`.
1. Update deploy condition to use the Azure DevOps organization name:

``` yaml
contains(variables['System.TeamFoundationCollectionUri'], 'myorganizationname')
````
1. In the job `Deploy_Module` for both the deploy tasks `publishRelease`
and `sendChangelogPR` add the following environment variables:

```yaml
ReleaseBranch: main
MainGitBranch: main
```

1. Create a new folder `GCPackages` under the folder `source`.
1. Create a new folder `UserAmyNotPresent` under the new folder `GCPackages`.
1. Under the folder `UserAmyNotPresent` create a new file `UserAmyNotPresent.config.ps1`.
Expand All @@ -760,9 +805,11 @@ _Guest Configuration_. This process will be replaced with a Plaster template.
```

1. Now resolve dependencies and run the task `gcpack`:

```powershell
build.ps1 -task gcpack -ResolveDependency
```

1. The built _Guest Configuration_ package can be found in the folder
`output\GCPolicyPackages\UserAmyNotPresent`.

Expand Down
18 changes: 16 additions & 2 deletions Sampler/Templates/Sampler/module.tests.ps1.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ BeforeDiscovery {
BeforeAll {
# Convert-Path required for PS7 or Join-Path fails
$projectPath = "$($PSScriptRoot)\..\.." | Convert-Path
<%
if ($PLASTER_PARAM_UseGit -eq 'true')
{
@'
# Get git-related project path. This is relevant for modules that will not be deployed in the root folder of Git.
$gitTopLevelPath = (&git rev-parse --show-toplevel)
$gitRelatedModulePath = (($projectPath -replace [regex]::Escape([IO.Path]::DirectorySeparatorChar), '/') -replace $gitTopLevelPath, '')
if (-not [string]::IsNullOrEmpty($gitRelatedModulePath)) { $gitRelatedModulePath = $gitRelatedModulePath.Trim('/') + '/' }
$escapedGitRelatedModulePath = [regex]::Escape($gitRelatedModulePath)

'@
}
%>
<#
If the QA tests are run outside of the build script (e.g with Invoke-Pester)
the parent scope has not set the variable $ProjectName.
Expand Down Expand Up @@ -73,10 +85,12 @@ if ($PLASTER_PARAM_UseGit -eq 'true')
{
$headCommit = &git rev-parse HEAD
$defaultBranchCommit = &git rev-parse origin/main
$filesChanged = &git @('diff', "$defaultBranchCommit...$headCommit", '--name-only')
$filesChanged = (&git @('diff', "$defaultBranchCommit...$headCommit", '--name-only') |
Where-Object { $_ -match "^$escapedGitRelatedModulePath" }) -replace "^$escapedGitRelatedModulePath", ""
}

$filesStagedAndUnstaged = &git @('diff', 'HEAD', '--name-only') 2>&1
$filesStagedAndUnstaged = (&git @('diff', 'HEAD', '--name-only') 2>&1 |
Where-Object { $_ -match "^$escapedGitRelatedModulePath" }) -replace "^$escapedGitRelatedModulePath", ""

$filesChanged += $filesStagedAndUnstaged

Expand Down

0 comments on commit 5b43dd8

Please sign in to comment.