Skip to content

Commit

Permalink
adding psake to packages dir
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyself committed May 7, 2011
1 parent 1f12c1b commit c81a493
Show file tree
Hide file tree
Showing 45 changed files with 1,854 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/psake/.gitattributes
@@ -0,0 +1 @@
* -crlf
16 changes: 16 additions & 0 deletions packages/psake/README.txt
@@ -0,0 +1,16 @@

How to get started.

- Download and extract the project
- Open up a PowerShell V2 console window
- CD into the directory where you extracted the project (where the psake.psm1 file is)
> Import-Module .\psake.psm1
> Get-Help Invoke-psake -Full
- this will show you help and examples of how to use psake


> CD .\examples
> Invoke-psake
- This will execute the "default" task in the "default.ps1"
> Invoke-psake .\default.ps1 Clean
- will execute the single task in the default.ps1 script
38 changes: 38 additions & 0 deletions packages/psake/examples/checkvariables.ps1
@@ -0,0 +1,38 @@
Properties {
$x = 1
$y = 2
}

FormatTaskName "[{0}]"

Task default -Depends Verify

Task Verify -Description "This task verifies psake's variables" {

$assertions = @(
((Test-Path 'variable:\psake'), "'psake' variable was not exported from module"),
(($variable:psake.ContainsKey("build_success")), "psake variable does not contain 'build_success'"),
(($variable:psake.ContainsKey("use_exit_on_error")), "psake variable does not contain 'use_exit_on_error'"),
(($variable:psake.ContainsKey("log_error")), "psake variable does not contain 'log_error'"),
(($variable:psake.ContainsKey("version")), "psake variable does not contain 'version'"),
(($variable:psake.ContainsKey("build_script_file")), "psake variable does not contain 'build_script_file'"),
(($variable:psake.ContainsKey("framework_version")), "psake variable does not contain 'framework_version'"),
((!$variable:psake.build_success), 'psake.build_success should be $false'),
((!$variable:psake.use_exit_on_error), 'psake.use_exit_on_error should be $false'),
((!$variable:psake.log_error), 'psake.log_error should be $false'),
((![string]::IsNullOrEmpty($variable:psake.version)), 'psake.version was null or empty'),
(($variable:psake.build_script_file -ne $null), '$psake.build_script_file was null'),
(($variable:psake.build_script_file.Name -eq "checkvariables.ps1"), ("psake variable: {0} was not equal to 'VerifyVariables.ps1'" -f $psake.build_script_file.Name)),
((![string]::IsNullOrEmpty($variable:psake.framework_version)), 'psake variable: $psake.framework_version was null or empty'),
(($variable:context.Peek().tasks.Count -ne 0), 'psake variable: $tasks had length zero'),
(($variable:context.Peek().properties.Count -ne 0), 'psake variable: $properties had length zero'),
(($variable:context.Peek().includes.Count -eq 0), 'psake variable: $includes should have had length zero'),
(($variable:context.Peek().formatTaskNameString -eq "[{0}]"), 'psake variable: $formatTaskNameString was not set correctly'),
(($variable:context.Peek().currentTaskName -eq "Verify"), 'psake variable: $currentTaskName was not set correctly')
)

foreach ($assertion in $assertions)
{
Assert ( $assertion[0] ) $assertion[1]
}
}
14 changes: 14 additions & 0 deletions packages/psake/examples/continueonerror.ps1
@@ -0,0 +1,14 @@
Task default -Depends TaskA

Task TaskA -Depends TaskB {
"Task - A"
}

Task TaskB -Depends TaskC -ContinueOnError {
"Task - B"
throw "I failed on purpose!"
}

Task TaskC {
"Task - C"
}
19 changes: 19 additions & 0 deletions packages/psake/examples/default.ps1
@@ -0,0 +1,19 @@
properties {
$testMessage = 'Executed Test!'
$compileMessage = 'Executed Compile!'
$cleanMessage = 'Executed Clean!'
}

task default -depends Test

task Test -depends Compile, Clean {
$testMessage
}

task Compile -depends Clean {
$compileMessage
}

task Clean {
$cleanMessage
}
17 changes: 17 additions & 0 deletions packages/psake/examples/nested.ps1
@@ -0,0 +1,17 @@
Properties {
$x = 1
}

Task default -Depends RunNested1, RunNested2, CheckX

Task RunNested1 {
Invoke-psake .\nested\nested1.ps1
}

Task RunNested2 {
Invoke-psake .\nested\nested2.ps1
}

Task CheckX{
Assert ($x -eq 1) '$x was not 1'
}
1 change: 1 addition & 0 deletions packages/psake/examples/nested/nested1.ps1
@@ -0,0 +1 @@
Properties { $x = 100}Task default -Depends Nested1CheckXTask Nested1CheckX{ Assert ($x -eq 100) '$x was not 100' }
Expand Down
1 change: 1 addition & 0 deletions packages/psake/examples/nested/nested2.ps1
@@ -0,0 +1 @@
Properties { $x = 200}Task default -Depends Nested2CheckXTask Nested2CheckX{ Assert ($x -eq 200) '$x was not 200' }
Expand Down
9 changes: 9 additions & 0 deletions packages/psake/examples/parameters.ps1
@@ -0,0 +1,9 @@
properties {
$my_property = $p1 + $p2
}

task default -depends TestParams

task TestParams {
Assert ($my_property -ne $null) '$my_property should not be null'
}
@@ -0,0 +1,3 @@
powershell -Command "& {Import-Module .\..\..\psake.psm1; Invoke-psake .\parameters.ps1 -parameters @{"buildConfiguration"='Release';} }"

Pause
22 changes: 22 additions & 0 deletions packages/psake/examples/passingParametersString/parameters.ps1
@@ -0,0 +1,22 @@
properties {
$buildOutputPath = ".\bin\$buildConfiguration"
}

task default -depends DoRelease

task DoRelease {
Assert ("$buildConfiguration" -ne $null) "buildConfiguration should not have been null"
Assert ("$buildConfiguration" -eq 'Release') "buildConfiguration=[$buildConfiguration] should have been 'Release'"

Write-Host ""
Write-Host ""
Write-Host ""
Write-Host -NoNewline "Would build output into path "
Write-Host -NoNewline -ForegroundColor Green "$buildOutputPath"
Write-Host -NoNewline " for build configuration "
Write-Host -ForegroundColor Green "$buildConfiguration"
Write-Host -NoNewline "."
Write-Host ""
Write-Host ""
Write-Host ""
}
13 changes: 13 additions & 0 deletions packages/psake/examples/preandpostaction.ps1
@@ -0,0 +1,13 @@
task default -depends Test

task Test -depends Compile, Clean -PreAction {"Pre-Test"} -Action {
"Test"
} -PostAction {"Post-Test"}

task Compile -depends Clean {
"Compile"
}

task Clean {
"Clean"
}
13 changes: 13 additions & 0 deletions packages/psake/examples/properties.ps1
@@ -0,0 +1,13 @@
properties {
$x = $null
$y = $null
$z = $null
}

task default -depends TestProperties

task TestProperties {
Assert ($x -ne $null) "x should not be null"
Assert ($y -ne $null) "y should not be null"
Assert ($z -eq $null) "z should be null"
}
Binary file added packages/psake/images/SakeBottle.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/psake/images/SakeBottleLicense.txt
@@ -0,0 +1,4 @@
SakeBottle.jpg
An American produced bottle of Ginjo Sake.
Shawn Clark Lazyeights Photography http://lazyeights.net/cpg/displayimage.php?pos=-122
This work is licensed under the Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/).
Binary file added packages/psake/images/psake.pdn
Binary file not shown.
Binary file added packages/psake/images/psake.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions packages/psake/psake-buildTester.ps1
@@ -0,0 +1,59 @@
function runBuilds{
$buildFiles = ls specs\*.ps1
$testResults = @()

#Add a fake build file to the $buildFiles array so that we can verify
#that Invoke-psake fails
$non_existant_buildfile = "" | select Name, FullName
$non_existant_buildfile.Name = "specifying_a_non_existant_buildfile_should_fail.ps1"
$non_existant_buildfile.FullName = "c:\specifying_a_non_existant_buildfile_should_fail.ps1"
$buildFiles += $non_existant_buildfile

foreach($buildFile in $buildFiles) {
$testResult = "" | select Name, Result
$testResult.Name = $buildFile.Name

Invoke-psake $buildFile.FullName -Parameters @{'p1'='v1'; 'p2'='v2'} -Properties @{'x'='1'; 'y'='2'} | Out-Null
$testResult.Result = (getResult $buildFile.Name $psake.build_success)
$testResults += $testResult
}

return $testResults
}

function getResult([string]$fileName, [bool]$buildSucceeded) {
$shouldSucceed = $null
if ($fileName.EndsWith("_should_pass.ps1")) {
$shouldSucceed = $true
} elseif ($fileName.EndsWith("_should_fail.ps1")) {
$shouldSucceed = $false
} else {
throw "Invalid specification syntax. Specs should end with _should_pass or _should_fail. $fileName"
}
if ($buildSucceeded -eq $shouldSucceed) {
"Passed"
} else {
"Failed"
}
}

Remove-Module psake -ea SilentlyContinue

Import-Module .\psake.psm1

$results = runBuilds

Remove-Module psake

""
$results | Sort 'Name' | % { if ($_.Result -eq "Passed") { write-host ($_.Name + " (Passed)") -ForeGroundColor 'GREEN'} else { write-host ($_.Name + " (Failed)") -ForeGroundColor 'RED'}}
""

$failed = $results | ? { $_.Result -eq "Failed" }
if ($failed) {
write-host "One or more of the build files failed" -ForeGroundColor 'RED'
exit 1
} else {
write-host "All Builds Passed" -ForeGroundColor 'GREEN'
exit 0
}
5 changes: 5 additions & 0 deletions packages/psake/psake.ps1
@@ -0,0 +1,5 @@
# Helper script for those who want to run
# psake without importing the module.
import-module .\psake.psm1
invoke-psake @args
remove-module psake

0 comments on commit c81a493

Please sign in to comment.