diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c7c5db6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,14 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v1 + - name: Invoke-Build + run: .\build.ps1 + shell: powershell diff --git a/PoshWyam.build.ps1 b/PoshWyam.build.ps1 index 25e9c56..ecb3295 100644 --- a/PoshWyam.build.ps1 +++ b/PoshWyam.build.ps1 @@ -52,9 +52,7 @@ Task RunTests InstallDependencies, Stage, { } - $testResults = Invoke-Pester @invokePesterParams - - $testResults | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $Artifacts 'PesterResults.json') + Invoke-Pester -OutputFile (Join-Path $Artifacts 'PesterResults.xml') } Task ConfirmTestsPassed { diff --git a/PoshWyam/Private/ConvertFrom-Yaml.ps1 b/PoshWyam/Private/ConvertFrom-Yaml.ps1 index 7736d7d..3fe510f 100644 --- a/PoshWyam/Private/ConvertFrom-Yaml.ps1 +++ b/PoshWyam/Private/ConvertFrom-Yaml.ps1 @@ -9,9 +9,9 @@ function ConvertFrom-Yaml { if ($Yaml) { $stringReader = New-Object System.IO.StringReader($Yaml) try { - $deserializer = [YamlDotNet.Serialization.Deserializer]::new() + $deserializer = [YamlDotNet.Serialization.DeserializerBuilder]::new().Build() $yamlObject = $deserializer.Deserialize($stringReader); - $serializer = [YamlDotNet.Serialization.Serializer]::new('JsonCompatible') + $serializer = [YamlDotNet.Serialization.SerializerBuilder]::new().JsonCompatible().Build() $stringBuilder = [System.Text.StringBuilder]::new() $stringWriter = [System.IO.StringWriter]::new($stringBuilder) $serializer.Serialize($stringWriter, $yamlObject) diff --git a/PoshWyam/Public/Invoke-Wyam.ps1 b/PoshWyam/Public/Invoke-Wyam.ps1 index a27272d..35074bb 100644 --- a/PoshWyam/Public/Invoke-Wyam.ps1 +++ b/PoshWyam/Public/Invoke-Wyam.ps1 @@ -255,7 +255,7 @@ function Invoke-Wyam { if (-not $root -or -not (Test-Path $root)) { $root = Join-Path $ModuleRoot 'Wyam' } - $wyam = Get-ChildItem -Path $root -Include wyam.exe -Recurse | Select-Object -First 1 + $wyam = Get-ChildItem -Path $root -Include wyam.dll -Recurse | Select-Object -First 1 $wyam = Resolve-Path $wyam Write-Verbose "Invoke-Wyam: Tool located at '$wyam'" $Arguments = ($Arguments | Quote) -join ' ' @@ -266,7 +266,7 @@ function Invoke-Wyam { Install-Wyam -Root $root } - $expr = "&`"$wyam`" $Arguments" + $expr = "&`"dotnet`" `"$wyam`" $Arguments" Write-Verbose "Invoke-Wyam: Running command '$expr'" Invoke-Expression $expr } diff --git a/PoshWyam/Public/New-BlogPost.ps1 b/PoshWyam/Public/New-BlogPost.ps1 index 640efe7..85d0461 100644 --- a/PoshWyam/Public/New-BlogPost.ps1 +++ b/PoshWyam/Public/New-BlogPost.ps1 @@ -11,12 +11,15 @@ function New-BlogPost { [Parameter(Position=0, Mandatory=$True)] [string] $Title, - + # The tags to include in the blog post. [Parameter(Position=1, Mandatory=$False)] [string[]] $Tag = @(), + [switch] + $IncludeDateInFileName, + # The Wyam project root. $Root = (Get-WyamRoot), @@ -24,10 +27,10 @@ function New-BlogPost { [switch] $Draft ) - + begin { } - + process { # Get directory $parms = @{ 'Root' = $Root } @@ -36,8 +39,13 @@ function New-BlogPost { } $posts = Get-BlogPostsLocation @parms + $fileName = Get-FileName -Title $Title -Extension ".md" + + if($IncludeDateInFileName){ + $fileName = "$((Get-Date).ToString("yyyy-MM-dd"))-$fileName" + } # Get path to post to create - $path = Join-Path $posts (Get-BlogPostName $Title) + $path = Join-Path $posts $fileName # Create post $content = @" @@ -52,7 +60,7 @@ Tags: [$(($Tag | ForEach-Object { """$_""" }) -join ', ')] Set-Content -Path $path -Value $content Resolve-Path $path } - + end { } } diff --git a/build.ps1 b/build.ps1 index 27754f0..6900d53 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,7 +1,7 @@ if (-not (Get-Module InvokeBuild)) { Import-Module InvokeBuild -ErrorAction SilentlyContinue if (-not (Get-Module InvokeBuild)) { - Install-Module InvokeBuild -Scope CurrentUser + Install-Module InvokeBuild -Scope CurrentUser -Force Import-Module InvokeBuild -ErrorAction Stop } } diff --git a/tests/Public/New-BlogPost.tests.ps1 b/tests/Public/New-BlogPost.tests.ps1 new file mode 100644 index 0000000..5f5364d --- /dev/null +++ b/tests/Public/New-BlogPost.tests.ps1 @@ -0,0 +1,27 @@ +Import-Module "$Artifacts\PoshWyam\PoshWyam.psd1" -Force + +Describe "New-BlogPost" { + + BeforeAll { + [void](New-Item -Path "TestDrive:\config.wyam" -ItemType File) + [void](New-Item -Path "TestDrive:\input\posts" -ItemType Directory) + + Push-Location "TestDrive:\" + } + + AfterAll { + Pop-Location + } + + Context "With -Title" { + It "runs without error" { + + $before = (Get-ChildItem "TestDrive:\input\posts").Count + New-BlogPost -Title "test post" + + (Get-ChildItem "TestDrive:\input\posts").Count | Should be ($before + 1) + + } + } + +} \ No newline at end of file