Skip to content

Commit

Permalink
rework module, add -WhatIf support and pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolonsky committed Aug 18, 2020
1 parent 7c4b97f commit b0d78fc
Show file tree
Hide file tree
Showing 20 changed files with 556 additions and 290 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin
.vscode
67 changes: 67 additions & 0 deletions AzureADLicensing.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
#Requires -Modules @{ModuleName='ModuleBuilder';ModuleVersion='1.0.0'}

$Script:IsAppveyor = $null -ne $env:APPVEYOR
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
Get-Module -Name $ModuleName | Remove-Module -Force

task Clean {
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
}

task TestCode {
Write-Build Yellow "`n`n`nTesting dev code before build"
$TestResult = Invoke-Pester -Script "$PSScriptRoot\Test\Unit" -Tag Unit -Show 'Header','Summary' -PassThru
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
}

task CompilePSM {
Write-Build Yellow "`n`n`nCompiling all code into single psm1"
try {
$BuildParams = @{}
if((Get-Command -ErrorAction stop -Name gitversion)) {
$GitVersion = gitversion | ConvertFrom-Json | Select-Object -Expand FullSemVer
$GitVersion = gitversion | ConvertFrom-Json | Select-Object -Expand InformationalVersion
$BuildParams['SemVer'] = $GitVersion
}
}
catch{
Write-Warning -Message 'gitversion not found, keeping current version'
}
Push-Location -Path "$BuildRoot\Source" -StackName 'InvokeBuildTask'
$Script:CompileResult = Build-Module @BuildParams -Passthru
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination $Script:CompileResult.ModuleBase
Pop-Location -StackName 'InvokeBuildTask'
}

task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {

}

task TestBuild {
Write-Build Yellow "`n`n`nTesting compiled module"
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath=$Script:CompileResult.ModuleBase}}
$CodeCoverage = (Get-ChildItem -Path $Script:CompileResult.ModuleBase -Filter *.psm1).FullName
$TestResult = Invoke-Pester -Script $Script -CodeCoverage $CodeCoverage -Show None -PassThru

if($TestResult.FailedCount -gt 0) {
Write-Warning -Message "Failing Tests:"
$TestResult.TestResult.Where{$_.Result -eq 'Failed'} | ForEach-Object -Process {
Write-Warning -Message $_.Name
Write-Verbose -Message $_.FailureMessage -Verbose
}
throw 'Tests failed'
}

$CodeCoverageResult = $TestResult | Convert-CodeCoverage -SourceRoot "$PSScriptRoot\Source" -Relative
$CodeCoveragePercent = $TestResult.CodeCoverage.NumberOfCommandsExecuted/$TestResult.CodeCoverage.NumberOfCommandsAnalyzed*100 -as [int]
Write-Verbose -Message "CodeCoverage is $CodeCoveragePercent%" -Verbose
$CodeCoverageResult | Group-Object -Property SourceFile | Sort-Object -Property Count | Select-Object -Property Count, Name -Last 10
}

task . Clean, TestCode, Build

task Build CompilePSM, MakeHelp, TestBuild

Binary file removed AzureADLicensing/AzureADLicensing.psd1
Binary file not shown.
284 changes: 0 additions & 284 deletions AzureADLicensing/AzureADLicensing.psm1

This file was deleted.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

PowerShell Cmdlets to manage Azure AD Group based licensing.

[![PSGallery Version](https://img.shields.io/powershellgallery/v/AzureADLicensing.svg?style=flat-square&label=PSGallery%20Version)](https://www.powershellgallery.com/packages/AzureADLicensing) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/AzureADLicensing?style=flat-square&label=PSGallery%20Downloads)](https://www.powershellgallery.com/packages/AzureADLicensing)
[![PowerShell Gallery Version](https://img.shields.io/powershellgallery/v/AzureADLicensing?label=PS%20Gallery%20Version&style=flat-square)](https://www.powershellgallery.com/packages/AzureADLicensing) [![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/AzureADLicensing?label=PS%20Gallery%20downloads&style=flat-square)](https://www.powershellgallery.com/packages/AzureADLicensing) ![GitHub](https://img.shields.io/github/license/nicolonsky/AzureADLicensing?style=flat-square)

## Using the module

1. Install the module: ```Install-Module -Name AzureADLicensing -AllowClobber```
2. If you hav the deprecated AzureRM module installed, uninstall it first ```Uninstall-AzureRm```
3. Authenticate to Azure: ```Connect-AzAccount```
2. If you have the deprecated AzureRM module installed, uninstall it first ```Uninstall-AzureRm```
3. Authenticate to your Azure tenant: ```Connect-AzAccount```
1. Feel free to use a service principal for unattended authentication and automation

## Available commands

All critical commands which modify settings support the `-WhatIf` parameter to predict changes.

Get available licenses and services:

<pre>
Expand Down
Loading

0 comments on commit b0d78fc

Please sign in to comment.