Skip to content

Commit 52dba0f

Browse files
authored
Release 0.2.0 (#3) - Better CI Operation, no new actual features
* Clean up Github Build Logic with Skip functions * Minor PSScriptAnalyzer Items
1 parent 6b23e4f commit 52dba0f

1 file changed

Lines changed: 30 additions & 38 deletions

File tree

PSModule.build.ps1

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -363,46 +363,44 @@ task PreDeploymentChecks {
363363
$CurrentErrorActionPreference = $ErrorActionPreference
364364
try {
365365
$ErrorActionPreference = "Stop"
366-
$MostRecentPesterTestResult = [xml]((Get-Content -raw (get-item "$ENV:BHBuildOutput/*-TestResults*.xml" | sort lastwritetime | select -last 1)))
366+
$MostRecentPesterTestResult = [xml]((Get-Content -raw (get-item "$ENV:BHBuildOutput/*-TestResults*.xml" | Sort-Object lastwritetime | Select-Object -last 1)))
367367
$MostRecentPesterTestResult = $MostRecentPesterTestResult."test-results"
368368
if (
369369
$MostRecentPesterTestResult -isnot [System.XML.XMLElement] -or
370370
$MostRecentPesterTestResult.errors -gt 0 -or
371371
$MostRecentPesterTestResult.failures -gt 0
372372
) {throw "Fail!"}
373373
} catch {
374-
throw "Unable to detect a clean passing Pester Test xml in the $env:BHBuildOutput directory. Ensure you were successful in the Build and Test phases first."
374+
throw "Unable to detect a clean passing Pester Test nunit xml file in the $env:BHBuildOutput directory. Did you run {Invoke-Build Build,Test} and ensure it passed all tests first?"
375375
}
376376
finally {
377377
$ErrorActionPreference = $CurrentErrorActionPreference
378378
}
379379

380-
if ((-not $env:BHBranchName -eq 'master') -or ($ForceDeploy -ne $true)) {
380+
if (($env:BHBranchName -eq 'master') -or $ForceDeploy) {
381+
if (-not (Get-Item $ProjectBuildPath/*.psd1 -erroraction silentlycontinue)) {throw "No Powershell Module Found in $ProjectBuildPath. Skipping deployment. Did you remember to build it first with {Invoke-Build Build}?"}
382+
} else {
381383
write-build Magenta "Task $($task.name)`: We are not in master branch, skipping publish. If you wish to deploy anyways such as for testing, run {InvokeBuild Deploy -ForceDeploy:$true}"
382384
$script:SkipPublish=$true
383-
} else {
384-
if (-not (Get-Item $ProjectBuildPath/*.psd1 -erroraction silentlycontinue)) {throw "No Powershell Module Found in $ProjectBuildPath. Skipping deployment. Did you remember to build it first with {Invoke-Build Build}?"}
385385
}
386386
}
387387

388-
task PublishGitHubRelease Package,{
388+
task PublishGitHubRelease -if (-not $SkipPublish) Package,{
389389
#TODO: Add Prerelease Logic when message commit says "!prerelease" or is in a release branch
390-
if (-not $SkipPublish) {
391-
if ($AppVeyor -and -not $GitHubAPIKey) {
392-
write-build DarkYellow "Task PublishGitHubRelease: Couldn't find GitHubAPIKey in the Appveyor secure environment variables. Did you save your Github API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://github.com/settings/tokens"
393-
$SkipPublish = $true
394-
}
395-
if (-not $GitHubAPIKey) {
396-
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
397-
write-build DarkYellow 'Task PublishGitHubRelease: $env:GitHubAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -GitHubUser "MyGitHubUser" -GitHubAPIKey "MyAPIKeyString"}. Have you created a GitHub API key with minimum public_repo scope permissions yet? https://github.com/settings/tokens'
398-
$SkipPublish = $true
399-
}
400-
if (-not $GitHubUserName) {
401-
write-build DarkYellow 'Task PublishGitHubRelease: $env:GitHubUserName was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -GitHubUser "MyGitHubUser" -GitHubAPIKey "MyAPIKeyString"}. Have you created a GitHub API key with minimum public_repo scope permissions yet? https://github.com/settings/tokens'
402-
$SkipPublish = $true
403-
}
390+
if ($AppVeyor -and -not $GitHubAPIKey) {
391+
write-build DarkYellow "Task PublishGitHubRelease: Couldn't find GitHubAPIKey in the Appveyor secure environment variables. Did you save your Github API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://github.com/settings/tokens"
392+
$SkipGitHubRelease = $true
404393
}
405-
if ($SkipPublish) {
394+
if (-not $GitHubAPIKey) {
395+
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
396+
write-build DarkYellow 'Task PublishGitHubRelease: $env:GitHubAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -GitHubUser "MyGitHubUser" -GitHubAPIKey "MyAPIKeyString"}. Have you created a GitHub API key with minimum public_repo scope permissions yet? https://github.com/settings/tokens'
397+
$SkipGitHubRelease = $true
398+
}
399+
if (-not $GitHubUserName) {
400+
write-build DarkYellow 'Task PublishGitHubRelease: $env:GitHubUserName was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -GitHubUser "MyGitHubUser" -GitHubAPIKey "MyAPIKeyString"}. Have you created a GitHub API key with minimum public_repo scope permissions yet? https://github.com/settings/tokens'
401+
$SkipGitHubRelease = $true
402+
}
403+
if ($SkipGitHubRelease) {
406404
write-build Magenta "Task $($task.name): Skipping Publish to GitHub Releases"
407405
} else {
408406
#TODO: Add Prerelease Logic when message commit says "!prerelease" or is in a release branch
@@ -448,23 +446,20 @@ task PublishGitHubRelease Package,{
448446
}
449447

450448
#TODO: Replace SkipPublish Logic with Proper invokebuild task skipping
451-
task PublishPSGallery {
452-
if (-not $SkipPublish) {
453-
if ($AppVeyor -and -not $NuGetAPIKey) {
454-
write-build DarkYellow "Couldn't find NuGetAPIKey in the Appveyor secure environment variables. Did you save your NuGet/Powershell Gallery API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://www.appveyor.com/docs/build-configuration/"
455-
$SkipPublish = $true
456-
}
457-
if (-not $NuGetAPIKey) {
458-
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
459-
write-build DarkYellow '$env:NuGetAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -NuGetAPIKey "MyAPIKeyString"}. Have you registered for a Powershell Gallery API key yet? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item'
460-
$SkipPublish = $true
461-
}
449+
task PublishPSGallery -if (-not $SkipPublish) {
450+
if ($AppVeyor -and -not $NuGetAPIKey) {
451+
write-build DarkYellow "Couldn't find NuGetAPIKey in the Appveyor secure environment variables. Did you save your NuGet/Powershell Gallery API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://www.appveyor.com/docs/build-configuration/"
452+
$SkipPSGallery = $true
453+
}
454+
if (-not $NuGetAPIKey) {
455+
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
456+
write-build DarkYellow '$env:NuGetAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -NuGetAPIKey "MyAPIKeyString"}. Have you registered for a Powershell Gallery API key yet? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item'
457+
$SkipPSGallery = $true
462458
}
463459

464460
if ($SkipPublish) {
465461
Write-Build Magenta "Task $($task.name)`: Skipping Powershell Gallery Publish"
466462
} else {
467-
468463
$publishParams = @{
469464
Path = $ProjectBuildPath
470465
NuGetApiKey = $NuGetAPIKey
@@ -478,13 +473,10 @@ task PublishPSGallery {
478473
}
479474
}
480475

481-
#Deploy Supertask
476+
### SuperTasks
477+
# These are the only supported items to run directly from Invoke-Build
482478
task Deploy PreDeploymentChecks,Package,PublishGitHubRelease,PublishPSGallery
483-
484-
#Build SuperTask
485479
task Build Clean,CopyFilesToBuildDir,UpdateMetadata
486-
487-
#Test SuperTask
488480
task Test Pester
489481

490482
#Default Task - Build, Test with Pester, Deploy

0 commit comments

Comments
 (0)