Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
df1a955
Add Import-ParameterConfiguration
Jaykul Jul 2, 2019
b7da9c9
Fix build and tests
Jaykul Jul 4, 2019
5aff7e6
Update ReadMe
Jaykul Jul 4, 2019
766cefd
Add Recurse to Import-ParameterConfiguration
Jaykul Jul 6, 2019
4c26fda
Fix broken test
Jaykul Jul 6, 2019
7c1af3d
Use SessionState.PSVariable instead of PSCallStack
Jaykul Jul 6, 2019
a31af34
Let's try making these tests run xplat
Jaykul Jul 22, 2019
fcb80a9
Tweak paths in Configuration test
Jaykul Jul 23, 2019
4b18d38
Update for Build-Module requiring AliasesToExport
Jaykul Jan 11, 2020
983b815
Tweak Build/Test scripts for contributors
Jaykul Jan 15, 2020
ebbe6ff
Preserve PSTypeName from exported configuration objects
Jaykul Feb 18, 2020
f80f75a
Update build manifests
Jaykul Feb 18, 2020
2a8e8d3
Import Configuration Module
Jaykul Feb 18, 2020
036576b
Add IPsMetadataSerializable
Jaykul Jul 24, 2020
673c694
Bump Azure-Pipelines
Jaykul Aug 8, 2020
0ec27f5
Resolve "problems" found by PSScriptAnalyzer
Jaykul Aug 8, 2020
9ad995f
Fix Build for ModuleBuilder 2.0
Jaykul Oct 16, 2020
0f4f60c
Fix bug when piping in an array of scriptblocks
Jaykul Oct 16, 2020
12aa268
Fix alias exports
Jaykul Oct 22, 2020
780b825
Be explicit about variable scope
Jaykul Oct 22, 2020
d401c1c
Tweak Build.ps1
Jaykul Jan 1, 2021
9903f0e
Why is the CI build failing?
Jaykul Jan 1, 2021
dc8d4a0
Try building using github actions
Jaykul Jan 2, 2021
8c4ee7c
Add Actions/Install-RequiredModules
Jaykul Jan 5, 2021
654468e
Normalize by using "action.ps1" as the runner name
Jaykul Jan 4, 2021
85692e6
Make the GitVersion action cache the tool
Jaykul Jan 4, 2021
91b1988
Add a pester runner that can handle Gherkin
Jaykul Jan 5, 2021
263692a
Add the psd1 path to the build output
Jaykul Jan 5, 2021
bd2d73e
Try merging Metadata and Configuration after build
Jaykul Jan 5, 2021
3bb2739
Make a Github Actions build using PoshCode/Actions
Jaykul Jan 5, 2021
e1f047a
Remove the local actions
Jaykul Jan 5, 2021
a22b493
Remove Azure Pipeline, add OSes to github workflows
Jaykul Jan 5, 2021
833da96
Resolve some PSScriptAnalyzer warnings
Jaykul Jan 9, 2021
fd34c79
Add ScriptAnalyzer
Jaykul Jan 18, 2021
16ddc7f
Include PSScriptAnalyzerSettings.psd1
Jaykul Jan 18, 2021
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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"gitversion.tool": {
"version": "5.6.0",
"commands": [
"dotnet-gitversion"
]
}
}
}
33 changes: 33 additions & 0 deletions .github/workflows/Merge-Module.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#requires -Module Configuration
[CmdletBinding()]
param(
$OutputModulePath,
$NestedModulePath
)
$OutputModule = Get-Module $OutputModulePath -ListAvailable
$NestedModule = Get-Module $NestedModulePath -ListAvailable

# Copy and then remove the extra output
Copy-Item -Path (Join-Path $NestedModule.ModuleBase Metadata.psm1) -Destination $OutputModule.ModuleBase
Remove-Item $NestedModule.ModuleBase -Recurse

# Because this is a double-module, combine the exports of both modules
# Put the ExportedFunctions of both in the manifest
Update-Metadata -Path $OutputModule.Path -PropertyName FunctionsToExport `
-Value @(
@(
$NestedModule.ExportedFunctions.Keys
$OutputModule.ExportedFunctions.Keys
) | Select-Object -Unique
# @('*')
)

# Put the ExportedAliases of both in the manifest
Update-Metadata -Path $OutputModule.Path -PropertyName AliasesToExport `
-Value @(
@(
$NestedModule.ExportedAliases.Keys
$OutputModule.ExportedAliases.Keys
) | Select-Object -Unique
# @('*')
)
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build on push

on: [push]

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: GitVersion
id: gitversion
uses: PoshCode/Actions/gitversion@v1
- name: Install-RequiredModules
uses: PoshCode/Actions/install-requiredmodules@v1
- name: Build Module
id: build
uses: PoshCode/actions/build-module@v1
with:
version: ${{ steps.gitversion.outputs.LegacySemVerPadded }}
destination: ${{github.workspace}}/output
- name: Combine Configuration
run: |
$OutputModule, $NestedModule = (ConvertFrom-Json -Input '${{ steps.build.outputs.moduleinfo }}').Where({$_.Name -eq "Configuration"}, "Split")
& "${{github.workspace}}/.github/workflows/Merge-Module.ps1" -OutputModulePath $OutputModule.Path -NestedModulePath $NestedModule.Path
- name: Upload Build Output
uses: actions/upload-artifact@v2
with:
name: Modules
path: ${{github.workspace}}/output
- name: Upload Tests
uses: actions/upload-artifact@v2
with:
name: PesterTests
path: ${{github.workspace}}/Specs
- name: Upload RequiredModules.psd1
uses: actions/upload-artifact@v2
with:
name: RequiredModules
path: ${{github.workspace}}/RequiredModules.psd1
- name: Upload PSScriptAnalyzerSettings.psd1
uses: actions/upload-artifact@v2
with:
name: ScriptAnalyzer
path: ${{github.workspace}}/PSScriptAnalyzerSettings.psd1
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, windows-2016] #, ubuntu-16.04, ubuntu-18.04, macos-latest]
needs: build
steps:
- name: Download Build Output
uses: actions/download-artifact@v2
- uses: PoshCode/Actions/install-requiredmodules@v1
- uses: PoshCode/Actions/pester@v1
with:
codeCoveragePath: Modules/Configuration
moduleUnderTest: Configuration
additionalModulePaths: ${{github.workspace}}/Modules
- name: Upload Results
uses: actions/upload-artifact@v2
with:
name: Pester Results
path: ${{github.workspace}}/*.xml
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
/[0-9]*/

/.vs/
/RequiredModules/
RequiredModules/
node_modules/

results.xml
coverage.xml
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files.defaultLanguage": "powershell",
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.scriptAnalysis.enable": true,
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
}
10 changes: 4 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "shell",
"command": "${workspaceFolder}\\build.ps1",
"args": [
"-OutputDirectory", "${workspaceFolder}\\Output\\Configuration"
"-OutputDirectory", "${workspaceFolder}"
],
"presentation": {
"echo": true,
Expand All @@ -29,7 +29,7 @@
"type": "shell",
"command": "Invoke-ScriptAnalyzer",
"args": [
"-Path", "${workspaceFolder}\\Output\\"
"-Path", "(Get-Module Configuration -List | Sort Version -Desc | Select -First 1 -Expand ModuleBase)"
],
"presentation": {
"echo": true,
Expand All @@ -49,15 +49,13 @@
"type": "shell",
"options": {
"cwd": "${workspaceFolder}",
"env": {
"PSModulePath": "${workspaceFolder}\\Output;${env:PSModulePath}"
}

},
"command": "Invoke-Gherkin",
"args": [
"-Path", "${workspaceFolder}\\Specs",
"-PesterOption", "@{ IncludeVSCodeMarker = $True }",
"-CodeCoverage", "${workspaceFolder}\\Output\\*.psm1"
"-CodeCoverage", "(Convert-Path (Join-Path (Split-Path (Get-Module Configuration -List | Sort Version -Desc | Select -First 1 -Expand ModuleBase)) *.psm1))"
],
"presentation": {
"echo": true,
Expand Down
39 changes: 27 additions & 12 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#requires -Module ModuleBuilder, Configuration
#requires -Module @{ModuleName = "ModuleBuilder"; ModuleVersion = "2.0.0"}, Configuration
[CmdletBinding()]
param(
# A specific folder to build into
$OutputDirectory = $PSScriptRoot,
$OutputDirectory,

# The version of the output module
[Alias("ModuleVersion")]
[string]$SemVer,

# Optionally, a local folder that modules and CLI tools can be installed in
$LocalTools = "./RequiredModules"
[string]$SemVer
)
Push-Location $PSScriptRoot -StackName BuildWindowsConsoleFont
Push-Location $PSScriptRoot -StackName BuildTestStack

if (!$SemVer -and (Get-Command gitversion -ErrorAction Ignore)) {
$PSBoundParameters['SemVer'] = gitversion -showvariable nugetversion
}
if (!$PSBoundParameters.ContainsKey("OutputDirectory")) {
$PSBoundParameters["OutputDirectory"] = $PSScriptRoot
}

try {
## Build the actual module
Expand All @@ -27,18 +27,33 @@ try {
-Target Build -Passthru `
@PSBoundParameters

# Copy and then remove the extra output
Copy-Item -Path (Join-Path $MetadataInfo.ModuleBase Metadata.psm1) -Destination $ConfigurationInfo.ModuleBase
Remove-Item $MetadataInfo.ModuleBase -Recurse

# Because this is a double-module, combine the exports of both modules
# Put the ExportedFunctions of both in the manifest
Update-Metadata -Path $ConfigurationInfo.Path -PropertyName FunctionsToExport `
-Value @(
$MetadataInfo.ExportedFunctions.Keys
$ConfigurationInfo.ExportedFunctions.Keys
@(
$MetadataInfo.ExportedFunctions.Keys
$ConfigurationInfo.ExportedFunctions.Keys
) | Select-Object -Unique
# @('*')
)

# Put the ExportedAliases of both in the manifest
Update-Metadata -Path $ConfigurationInfo.Path -PropertyName AliasesToExport `
-Value @(
@(
$MetadataInfo.ExportedAliases.Keys
$ConfigurationInfo.ExportedAliases.Keys
) | Select-Object -Unique
# @('*')
)

$ConfigurationInfo

# Remove the extra metadata file
Remove-Item $MetadataInfo.Path
} finally {
Pop-Location -StackName BuildWindowsConsoleFont
Pop-Location -StackName BuildTestStack
}
1 change: 0 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mode: Mainline
next-version: 1.0.0
commit-message-incrementing: MergeMessageOnly

assembly-versioning-format: '{Major}.{Minor}.{Patch}.{env:BUILDCOUNT ?? 0}'
Expand Down
4 changes: 4 additions & 0 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@{
Severity = @('Error', 'Warning')
ExcludeRules = @('PSAvoidUsingDeprecatedManifestFields', 'PSPossibleIncorrectUsageOfAssignmentOperator')
}
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# Configuration
[![Build Status](https://dev.azure.com/poshcode/Configuration/_apis/build/status/Configuration?branchName=master)](https://dev.azure.com/poshcode/Configuration/_build/latest?definitionId=2&branchName=master)

A module for saving and loading settings and configuration objects for PowerShell modules (and scripts).
# The Configuration Module

The Configuration module supports layered configurations with default values, and serializes objects and hashtables to the simple PowerShell metadata format with the ability to extend how your custom types are serialized, so your configuration files are just .psd1 files!
## Metadata commands for working with .psd1:

The key feature is that you don't have to worry about where to store files, and modules using the Configuration commands will be able to easily store data even when installed in write-protected folders like Program Files.
- Manipulating metadata files
- Extensible serialization of types
- Built in support for DateTime, Version, Guid, SecureString, ScriptBlocks and more
- Lets you store almost anything in readable metadata (.psd1) files
- Serializing (`Export`) to metadata (.psd1) files
- Deserializing (`Import`) from metadata (.psd1) files

Supports WindowsPowerShell, as well as PowerShell Core on Windows, Linux and OS X.
## Configuration commands for loading settings:

- Ship default configuration files with your module
- Automatically determines where to save your settings
- Supports Windows roaming profiles
- Supports XDG settings for Linux (and MacOS)
- Allow users to configure settings using our commands, or your wrappers
- Supports _layered_ configurations:
- Machine-level config
- User override files
- Supports automatic configuration of parameters values for a command
- Reads `Noun` configuration files in your working directory
- Filters only values which apply to the current command


It supports WindowsPowerShell, as well as PowerShell Core on Windows, Linux and OS X.

## Installation

Expand Down
7 changes: 4 additions & 3 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@{
Configuration = "[1.3.1,2.0)"
Pester = "[4.7.2,5.0)"
ModuleBuilder = "[1.0.0,2.0)"
Configuration = "[1.3.1,2.0)"
Pester = "[4.10.1,5.0)"
ModuleBuilder = "[2.0.0,3.0)"
PSScriptAnalyzer = "1.19.1"
}
6 changes: 5 additions & 1 deletion Source/Configuration/Public/Export-Configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function Export-Configuration {

This example shows how to use Export-Configuration to export data for use in a specific module.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] # Because PSSCriptAnalyzer team refuses to listen to reason. See bugs: #194 #283 #521 #608
# PSSCriptAnalyzer team refuses to listen to reason. See bugs: #194 #283 #521 #608
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Callstack', Justification = 'This is referenced in ParameterBinder')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Module', Justification = 'This is referenced in ParameterBinder')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'DefaultPath', Justification = 'This is referenced in ParameterBinder')]
[CmdletBinding(DefaultParameterSetName = '__ModuleInfo', SupportsShouldProcess)]
param(
# Specifies the objects to export as metadata structures.
Expand Down
2 changes: 2 additions & 0 deletions Source/Configuration/Public/Get-ConfigurationPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function Get-ConfigurationPath {
#
# This example shows how to use Get-ConfigurationPath with Export-CliXML to cache data as clixml from inside a module.
[Alias("Get-StoragePath")]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Callstack', Justification = 'This is referenced in ParameterBinder')]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Module', Justification = 'This is referenced in ParameterBinder')]
[CmdletBinding(DefaultParameterSetName = '__ModuleInfo')]
param(
# The scope to save at, defaults to Enterprise (which returns a path in "RoamingData")
Expand Down
3 changes: 3 additions & 0 deletions Source/Configuration/Public/Import-Configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function Import-Configuration {
#
# This example shows how to use Import-Configuration in your module to load data cached for another module
#
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Callstack', Justification = 'This is referenced in ParameterBinder')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Module', Justification = 'This is referenced in ParameterBinder')]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'DefaultPath', Justification = 'This is referenced in ParameterBinder')]
[CmdletBinding(DefaultParameterSetName = '__CallStack')]
param(
# A callstack. You should not ever pass this.
Expand Down
Loading