Skip to content

Commit

Permalink
Dev (#19)
Browse files Browse the repository at this point in the history
* WIP. Added PSSA, renamed some functions, added some new ones as well.

* WIP: Updated function names, added some better pipeline usability, and outputs custom object classes now

* WIP: Added a new class, converted to some more pipeline stuff

* Added multiple available pipeline types

* WIP: Started adding custom query

Has much more work to be done.

* Changed to a select string array, instead of PSCustomObject, for the custom queries

* Create Write-ePOWhere.ps1

* Update Write-ePOWhere.ps1

* Update Write-ePOWhere.ps1

* Sharing current so I can go home.

* New class builder

* CmdletBinding and updated variable names

* Fixed example names

* Fixed example function name

* More logging

* Added pipeline, simplified function, and returns an object now

* Needs a hashtable

* Removed file

* Deleted file

* Changed to use IWR, and handling to PS Core

* Updated documentation

* Renamed files, starting to work on pester tests

* Sharing current

* Added

* Updated and added some pester test

* Added some more pester tests

* Updated pester tests, and cleaned up unnecessary ones too

* Finished pester tests for Get-ePOQuery

* Added testing for ePOTag, ePOVersion, and updated functions for better pipelining.

* Re-added the manifest file

* Lots of work...

* Removed

* Fixed parameters

* Removed

* Added /dev to ignore

* Updated

* Updated/Fixed tests and cleaned up code

* Added function with tests

* Forgot the export

* Changed repo root

* changed back to root

* Cleaned up, and added skip_tags

* Added -t

* Updated README.md

* Cleaned up

* Removed branch

* Removed codecov

* Updated README.md to remove codecov

* Changed dependency

* Updated

* Removed skip tag and cleaned up

* Forgot error checking

* ...meh

* Fixed spacing

* Re-added enable exit

* Removed global

* Fixed function name and cleaned up expletive

* Changed to warning and added parent ID

* Added a foreach

* Fixed parameter name

* added some logging
  • Loading branch information
marranaga authored Jul 12, 2019
1 parent 7826fae commit 2f8b0d5
Show file tree
Hide file tree
Showing 337 changed files with 4,971 additions and 3,457 deletions.
24 changes: 5 additions & 19 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:
secure: 19uAs7mfu9YRkwTvHIymJuSyXGjUUXCR+jsaRvo3ST44NmgZG2HZkOjuabTe/Cyu
CODECOV_TOKEN:
secure: 2zRKXm7Sw+GlVonpMOerfEBjeYc05cJinePPX8nJl7c7j1PzNAbrNHAbi7y1RALU




Expand All @@ -25,27 +26,12 @@ install:
build_script:
- ps: Invoke-psake '.\.scripts\build.ps1' -Properties @{'SkipBootStrap' = $true}



# deploy:
# release: v$(APPVEYOR_BUILD_VERSION)
# description: ePOwerShell v$(appveyor_build_version)
# provider: GitHub
# auth_token:
# secure: EHLdOgH35OJQ/AAj6dXn/iQ9datyBKgai5JGB+Lbh9Yaltk4wLefi2MIfGZ5N2ca
# artifact: /.*\.zip/
# draft: false
# prerelease: true
# on:
# branch: master # release from master branch only
# appveyor_repo_tag: false # deploy except on tag push only
- ps: Invoke-psake '.\.scripts\build.ps1'



on_success:
# If build was started by pushed tag; deploy it.
- ps: |
Write-Host "[AppVeyor] On Success; deploying ..." -Foregroundcolor Green
Invoke-PSDeploy -Path '.\.scripts\deploy.ps1' -Force
- ps: |
Write-Host "[AppVeyor] On Success; deploying ..." -Foregroundcolor Green
Invoke-PSDeploy -Path '.\.scripts\deploy.ps1' -Force
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
settings.json
/*.code-workspace
./dev/*
/dev
208 changes: 85 additions & 123 deletions .scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
May do different tasks depending on the environment it's running in. Read the code for the details on that.
.Example
# Run this Build Script:
Invoke-psake .\.build.ps1
.Example
# Skip Bootstrap
Expand All @@ -20,14 +20,14 @@
Invoke-psake .\.build.ps1 -Properties @{'thisModuleName'='OtherModuleName'}
.Example
# Run this Build Script with a parameters/properties that's not otherwise defined:
Invoke-psake .\.build.ps1 -Properties @{'Version'=[version]'1.2.3'}
#>
$ErrorActionPreference = 'Stop'

$script:thisModuleName = 'ePOwerShell'
$script:PSScriptRootParent = Split-Path $PSScriptRoot -Parent
$script:ManifestJsonFile = "${PSScriptRootParent}\${thisModuleName}\Manifest.json"
$script:ManifestJsonFile = "${PSScriptRootParent}\Manifest.json"
$script:BuildOutput = "${PSScriptRootParent}\dev\BuildOutput"

$script:Manifest = @{}
Expand Down Expand Up @@ -62,8 +62,6 @@ Properties {
$ManifestJsonFile = $script:ManifestJsonFile
$BuildOutput = $script:BuildOutput

# Manipulate the Parameters for usage:

$script:Manifest.Copyright = $script:Manifest.Copyright -f [DateTime]::Now.Year
$script:Manifest.GUID = (New-Guid).Guid

Expand All @@ -78,149 +76,113 @@ Properties {
$script:Version = [string](& "${PSScriptRootParent}\.scripts\version.ps1")
}

# Start psake builds

Task default -Depends CompressModule

<#
Bootstrap PSDepend:
- https://github.com/RamblingCookieMonster/PSDepend
Install Dependencies
#>
Task Bootstrap -Description "Bootstrap & Run PSDepend" {
$PSDepend = Get-Module -Name 'PSDepend'
Write-Host "[BUILD Bootstrap] PSDepend: $($PSDepend.Version)" -ForegroundColor Magenta
if ($PSDepend)
{
Write-Host "[BUILD Bootstrap] PSDepend: Updating..." -ForegroundColor Magenta
$PSDepend | Update-Module -Force
}
else
{
Write-Host "[BUILD Bootstrap] PSDepend: Installing..." -ForegroundColor Magenta
Install-Module -Name 'PSDepend' -Force
Task Clean -Description 'Cleans the build environment' {
if (Test-Path $ParentModulePath) {
Write-Host "[BUILD Clean] Parent module path exists: $ParentModulePath" -ForegroundColor Magenta

if ((Get-ChildItem $ParentModulePath | Measure-Object).Count -ne 0) {
Write-Host "[BUILD Clean] Parent module path is not empty: $(Get-ChildItem $ParentModulePath)" -ForegroundColor Magenta
Remove-Item "$ParentModulePath\*" -Recurse -Force
}
} else {
Write-Host "[BUILD Clean] Parent module path does not exist: $ParentModulePath" -ForegroundColor Magenta

New-Item -ItemType Directory -Path $ParentModulePath -Force
}

Write-Host "[BUILD Bootstrap] PSDepend: Installing..." -ForegroundColor Magenta
$PSDepend = Import-Module -Name 'PSDepend' -PassThru
Write-Host "[BUILD Bootstrap] PSDepend: $($PSDepend.Version)" -ForegroundColor Magenta
if (Get-Module -Name $script:thisModuleName) {
Write-Host "[BUILD Clean] Module is imported: $(Get-Module -Name $script:thisModuleName)" -ForegroundColor Magenta

Write-Host "[BUILD Bootstrap] PSDepend: Invoking '${PSScriptRootParent}\REQUIREMENTS.psd1'" -ForegroundColor Magenta
Push-Location $PSScriptRootParent
Invoke-PSDepend -Path "${PSScriptRootParent}\REQUIREMENTS.psd1" -Force
Pop-Location
Remove-Module -Name $script:thisModuleName -Force
}
}

<#
Preperation and Setup:
- Import Manifest.json to create the PDS1 file.
- Modify Manifest information; keeping purged information.
- Establish Module/Resource Locations/Paths.
#>
Task SetupModule -Description "Prepare and Setup Module" -Depends $DependsBootstrap {
New-Item -ItemType Directory -Path $script:ParentModulePath -Force

Task CompileManifest -Description 'Created the module .psd1 manifest file' -Depends Clean {
$script:Manifest.Path = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psd1"
$script:Manifest.ModuleVersion = $script:Version
Write-Host "[BUILD SetupModule] New-ModuleManifest: $($script:Manifest | ConvertTo-Json -Compress)" -ForegroundColor Magenta
if ($env:APPVEYOR_REPO_TAG -eq 'true') {
try {
[Version] $env:APPVEYOR_REPO_TAG_NAME
$script:Manifest.ModuleVersion = $env:APPVEYOR_REPO_TAG_NAME
} catch {
$script:Manifest.ModuleVersion = $script:Version
}
} else {
$script:Manifest.ModuleVersion = $script:Version
}
Write-Host "[BUILD CompileManifest] New-ModuleManifest: $($script:Manifest | ConvertTo-Json -Compress)" -ForegroundColor Magenta
New-ModuleManifest @script:Manifest
}


Task PSScriptAnalyzer -Description 'Runs PSScriptAnalyzer against compiled module' -Depends Clean {
$PSSAResults = Invoke-ScriptAnalyzer -Path "${PSScriptRootParent}\${thisModuleName}" -Settings "${script:PSScriptRootParent}\PSScriptAnalyzerSettings.psd1" -Recurse

$copyItem = @{
LiteralPath = "${PSScriptRootParent}\${script:thisModuleName}\${script:thisModuleName}.psm1"
Destination = $script:ParentModulePath
Force = $true
$Information = $PSSAResults | Where-Object { $_.Severity -eq 'Information' }
$Errors = $PSSAResults | Where-Object { $_.Severity -eq 'Error' }
$Warnings = $PSSAResults | Where-Object { $_.Severity -eq 'Warning' }
$ParseErrors = $PSSAResults | Where-Object { $_.Severity -eq 'ParseError' }

if ($Information) {
Write-Host "PSSA Information:"
$Information
}
Write-Host "[BUILD SetupModule] Copy-Item: $($copyItem | ConvertTo-Json -Compress)" -ForegroundColor Magenta
Copy-Item @copyItem

foreach ($directory in (Get-ChildItem "${PSScriptRootParent}\${thisModuleName}" -Directory)) {
$copyItem = @{
LiteralPath = $directory.FullName
Destination = $script:ParentModulePath
Recurse = $true
Force = $true
}
Write-Host "[BUILD SetupModule] Copy-Item: $($copyItem | ConvertTo-Json -Compress)" -ForegroundColor Magenta
Copy-Item @copyItem

if ($Warnings) {
Write-Host "PSSA Warnings:"
$Warnings
}

if ($Errors) {
Write-Error "PSSA Errors"
Throw $Errors
} elseif ($ParseErrors) {
Write-Error "PSSA Parse Errors"
Throw $ParseErrors
}
}

<#
Put Module/Resource in locations accessible by DSC:
- Create the PSD1 files from Manifest.
- Copy PSM1 to location.
- Copy Module to System Location; for testing.
#>
Task InstallModule -Description "Prepare and Setup/Install Module" -Depends SetupModule {
$New_Item = @{
ItemType = 'Directory'
Path = $script:SystemModuleLocation
Force = $true
Task CompileModule -Description 'Compiles all funcitons into a single .psm1 file' -Depends PSScriptAnalyzer {
$CompiledModule = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1"
$Files = Get-ChildItem -Path "${PSScriptRootParent}\${thisModuleName}" -Recurse -File
$FileContents = foreach ($File in $Files) {
Get-Content $File.FullName -Force
}
Write-Host "[BUILD InstallModule] New-Item: $($New_Item | ConvertTo-Json -Compress)" -ForegroundColor Magenta
New-Item @New_Item | Out-Null

$Copy_Item = @{
Path = "${script:BuildOutput}\*"
Destination = $script:SystemModuleLocation
Recurse = $true
Force = $true

$FileContents | Out-File -FilePath $CompiledModule -Force
Write-Host "[BUILD CompileModule] Module: $CompiledModule" -ForegroundColor Magenta
}

Task ImportModule -Description 'Imports the compiled module' -Depends CompileModule, CompileManifest {
try {
Import-Module "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1" -Force
} catch {
Throw $_
}
Write-Host "[BUILD InstallModule] Copy-Item: $($Copy_Item | ConvertTo-Json -Compress)" -ForegroundColor Magenta
Copy-Item @Copy_Item
}

<#
Tests
- Pester
- CodeCov
#>
Task TestModule -Description "Run Pester Tests and CoeCoverage" -Depends InstallModule {
Write-Host "[BUILD TestModule] Import-Module ${env:Temp}\CodeCovIo.psm1" -ForegroundColor Magenta
Import-Module ${env:Temp}\CodeCovIo.psm1

$invokePester = @{
Path = "${PSScriptRootParent}\Tests"
CodeCoverage = (Get-ChildItem "${PSScriptRootParent}\${thisModuleName}" -Recurse -Include '*.psm1', '*.ps1').FullName
PassThru = $true
Task InvokePester -Description 'Runs Pester tests against compiled module' -Depends ImportModule {
$InvokePester = @{
Path = "${PSScriptRootParent}\Tests\"
CodeCoverage = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1"
PassThru = $True
OutputFormat = 'NUnitXml'
OutputFile = ([IO.FileInfo] '{0}\dev\CodeCoverage.xml' -f $PSScriptRootParent)
EnableExit = $True
EnableExit = $True
}
Write-Host "[BUILD TestModule] Invoke-Pester $($invokePester | ConvertTo-Json)" -ForegroundColor Magenta
$res = Invoke-Pester @invokePester
# Write-Host "[BUILD TestModule] Pester Result: $($res | ConvertTo-Json)" -ForegroundColor Magenta

$exportCodeCovIoJson = @{
CodeCoverage = $res.CodeCoverage
RepoRoot = $PSScriptRootParent
Path = ([string] $invokePester.OutputFile).Replace('.xml', '.json')
}
Write-Host "[BUILD TestModule] Export-CodeCovIoJson: $($exportCodeCovIoJson | ConvertTo-Json)" -ForegroundColor Magenta
Export-CodeCovIoJson @exportCodeCovIoJson

Write-Host "[BUILD TestModule] Uploading CodeCov.io Report ..." -ForegroundColor Magenta
Push-Location $script:PSScriptRootParent
& "${env:Temp}\Codecov\codecov.exe" -f $exportCodeCovIoJson.Path
Pop-Location

Write-Host "[BUILD TestModule] Adding Results to Artifacts..." -ForegroundColor Magenta
# (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/${env:APPVEYOR_JOB_ID}", (Resolve-Path $invokePester.OutputFile))
Push-AppveyorArtifact (Resolve-Path $invokePester.OutputFile)
Push-AppveyorArtifact (Resolve-Path $exportCodeCovIoJson.Path)

if ($res.FailedCount -gt 0) {
Throw "$($res.FailedCount) tests failed."
# $Host.SetShouldExit($res.FailedCount)
Exit $res.FailedCount

$Pester = Invoke-Pester @InvokePester

if ($Pester.FailedCount -gt 0) {
Throw "$($Pester.FailedCount) tests failed."
}
}

<#
Compress things for releasing
#>
Task CompressModule -Description "Compress module for easy download from GitHub" -Depends TestModule {
Task CompressModule -Description "Compress module for easy download from GitHub" -Depends InvokePester {
Write-Host "[BUILD CompressModule] Import-Module ${env:Temp}\CodeCovIo.psm1" -ForegroundColor Magenta
Compress-Archive -Path $script:ParentModulePath -DestinationPath "${script:ParentModulePath}.zip"

Push-AppveyorArtifact (Resolve-Path "${script:ParentModulePath}.zip")
}
}
5 changes: 1 addition & 4 deletions .scripts/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ Write-Host "[Deploy] APPVEYOR_PROJECT_NAME: ${env:APPVEYOR_PROJECT_NAME}" -Foreg
Write-Host "[Deploy] APPVEYOR_REPO_TAG: ${env:APPVEYOR_REPO_TAG}" -Foregroundcolor 'Blue' -BackgroundColor 'Magenta'
Write-Host "[Deploy] APPVEYOR_REPO_BRANCH: ${env:APPVEYOR_REPO_BRANCH}" -Foregroundcolor 'Blue' -BackgroundColor 'Magenta'

if (
($env:APPVEYOR_REPO_TAG -eq 'true') -and
($env:APPVEYOR_REPO_BRANCH -eq 'master')
) {
if (($env:APPVEYOR_REPO_TAG -eq 'true') -and ($env:APPVEYOR_REPO_BRANCH -eq 'master')) {
Write-Host "Deploying to PSGallery"
Deploy Module {
By PSGalleryModule ePOwerShell {
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.tabSize": 4,
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.openBraceOnSameLine":true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceAroundPipe": true,
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2f8b0d5

Please sign in to comment.