Skip to content

Commit 4a6d952

Browse files
committed
initial commit
0 parents  commit 4a6d952

11 files changed

+154
-0
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [0.1.0] - Unreleased
9+
10+
### Added
11+
12+
- Initial commit

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Brandon Olin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PowerShellBuild.Common
2+
3+
A common [psake](https://github.com/psake/psake) task module for PowerShell projects.

build.ps1

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[cmdletbinding(DefaultParameterSetName = 'Task')]
2+
param(
3+
[parameter(ParameterSetName = 'task', position = 0)]
4+
[string[]]$Task = 'default',
5+
6+
[parameter(ParameterSetName = 'Help')]
7+
[switch]$Help
8+
)
9+
10+
$ErrorActionPreference = 'Stop'
11+
12+
# Bootstrap dependencies
13+
Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null
14+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
15+
if (-not (Get-Module -Name PSDepend -ListAvailable)) {
16+
Install-module -Name PSDepend -Repository PSGallery
17+
}
18+
Import-Module -Name PSDepend
19+
Invoke-PSDepend -Path './requirements.psd1' -Install -Import -Force -WarningAction SilentlyContinue
20+
21+
$psakeFile = './psakeFile.ps1'
22+
if ($PSCmdlet.ParameterSetName -eq 'Help') {
23+
Get-PSakeScriptTasks -buildFile $psakeFile |
24+
Format-Table -Property Name, Description, Alias, DependsOn
25+
} else {
26+
Set-BuildEnvironment -Force
27+
28+
Invoke-psake -buildFile $psakeFile -taskList $Task -nologo
29+
exit ( [int]( -not $psake.build_success ) )
30+
}

build.settings.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$projectRoot = if ($ENV:BHProjectPath) { $ENV:BHProjectPath } else { $PSScriptRoot }
2+
3+
@{
4+
ProjectRoot = $projectRoot
5+
ProjectName = $env:BHProjectName
6+
SUT = $env:BHModulePath
7+
Tests = Join-Path -Path $projectRoot -ChildPath Tests
8+
ManifestPath = $env:BHPSModuleManifest
9+
Manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
10+
PSVersion = $PSVersionTable.PSVersion.ToString()
11+
PSGalleryApiKey = $env:PSGalleryApiKey
12+
}

media/psaketaskmodule-256x256.png

23.8 KB
Loading

psakeFile.ps1

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
properties {
2+
$settings = . (Join-Path -path $PSScriptRoot -ChildPath build.settings.ps1)
3+
}
4+
5+
task default -depends Test
6+
7+
task Init {
8+
"STATUS: Testing with PowerShell $($settings.PSVersion)"
9+
'Build System Details:'
10+
Get-Item ENV:BH*
11+
} -description 'Initialize build environment'
12+
13+
task Test -Depends Init, Analyze, Pester -description 'Run test suite'
14+
15+
task Analyze -depends Init {
16+
$analysis = Invoke-ScriptAnalyzer -Path $settings.SUT -Recurse -Verbose:$false
17+
$errors = $analysis | Where-Object {$_.Severity -eq 'Error'}
18+
$warnings = $analysis | Where-Object {$_.Severity -eq 'Warning'}
19+
if (@($errors).Count -gt 0) {
20+
Write-Error -Message 'One or more Script Analyzer errors were found. Build cannot continue!'
21+
$errors | Format-Table
22+
}
23+
24+
if (@($warnings).Count -gt 0) {
25+
Write-Warning -Message 'One or more Script Analyzer warnings were found. These should be corrected.'
26+
$warnings | Format-Table
27+
}
28+
} -description 'Run PSScriptAnalyzer'
29+
30+
task Pester -depends Init {
31+
Remove-Module $settings.ProjectName -ErrorAction SilentlyContinue -Verbose:$false
32+
Import-Module -Name $settings.ManifestPath -Force -Verbose:$false
33+
34+
if (Test-Path -Path $settings.Tests) {
35+
Invoke-Pester -Path $settings.Tests -PassThru -EnableExit
36+
}
37+
} -description 'Run Pester tests'
38+
39+
task Publish -depends Init {
40+
" Publishing version [$($settings.Manifest.ModuleVersion)] to PSGallery..."
41+
if ($settings.PSGalleryApiKey) {
42+
Publish-Module -Path $settings.SUT -NuGetApiKey $settings.PSGalleryApiKey -Repository PSGallery
43+
} else {
44+
throw 'Did not find PSGallery API key!'
45+
}
46+
} -description 'Publish to PowerShellGallery'

requirements.psd1

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
BuildHelpers = 'latest'
3+
Pester = 'latest'
4+
psake = 'latest'
5+
PSScriptAnalyzer = 'latest'
6+
}

src/PowerShellBuild.Common.psd1

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@{
2+
RootModule = 'PowerShellBuild.Common'
3+
ModuleVersion = '0.1.0'
4+
GUID = '15431eb8-be2d-4154-b8ad-4cb68a488e3d'
5+
Author = 'Brandon Olin'
6+
CompanyName = 'Community'
7+
Copyright = '(c) Brandon Olin. All rights reserved.'
8+
Description = 'A common psake task module for PowerShell projects'
9+
PowerShellVersion = '3.0'
10+
RequiredModules = @('BuildHelpers', 'psake')
11+
FunctionsToExport = '*'
12+
CmdletsToExport = @()
13+
VariablesToExport = @()
14+
AliasesToExport = @()
15+
PrivateData = @{
16+
PSData = @{
17+
Tags = @('psake', 'build')
18+
# LicenseUri = ''
19+
# ProjectUri = ''
20+
# IconUri = ''
21+
# ReleaseNotes = ''
22+
}
23+
}
24+
}

src/PowerShellBuild.Common.psm1

Whitespace-only changes.

src/psakeFile.ps1

Whitespace-only changes.

0 commit comments

Comments
 (0)