diff --git a/.gitignore b/.gitignore index 23660a889..a0d3f8e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ VERSION *.nupkg -obj \ No newline at end of file +obj +# ignore release dirs +/*.*.* diff --git a/appveyor.yml b/appveyor.yml index e8c513d16..38fe5aa4c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -48,6 +48,20 @@ test_script: $Error | Format-List * -Force exit 1; } + + # Build module and run test against it + $buildScriptPath = "$Env:APPVEYOR_BUILD_FOLDER\build.ps1" + & $buildScriptPath + $result = Invoke-Pester @pesterParams + if (Test-Path $testResultsFile) { + (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $testResultsFile) + } + if ($result.FailedCount -gt 0) { + # Terminate the script to fail the build + $Error | Format-List * -Force + exit 1; + } + $ErrorActionPreference = 'Stop' if (!(Test-Path Env:CA_KEY)) { Write-Host 'CA_KEY not set! (Expected on PR builds.)' diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 000000000..ab17e5228 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,41 @@ +$moduleVersion = (Import-LocalizedData -FileName 'posh-git.psd1' -BaseDirectory (Join-Path $PSScriptRoot 'src')).ModuleVersion +$outputFolder = (Join-Path $PSScriptRoot $moduleVersion) + +# Clean +if (Test-Path $outputFolder) { + Remove-Item $outputFolder -Recurse +} + +# Copy files to output folder +Copy-Item -Path (Join-Path $PSScriptRoot 'src') -Destination $outputFolder -Recurse + +$mainModulePath = (Join-Path $outputFolder 'posh-git.psm1') +$contentOfMainModule = Get-Content -Path $mainModulePath + +$PowerShellScriptsToBeMerged = Get-ChildItem -Path $outputFolder -Filter '*.ps1' +foreach ($powerShellScriptToBeMerged in $PowerShellScriptsToBeMerged) { + $NameOfScriptToBeMerged = $powerShellScriptToBeMerged.Name + $scriptContentToBeMerged = Get-Content -Path $powerShellScriptToBeMerged.FullName -Raw + $replaceSearchText = ". `$PSScriptRoot\$NameOfScriptToBeMerged" + if (-not $contentOfMainModule.Contains($replaceSearchText)) { + $replaceSearchText = ". `$PSScriptRoot\$NameOfScriptToBeMerged > `$null" + } + if (-not $contentOfMainModule.Contains($replaceSearchText)) { + continue + } + + if ($contentOfMainModule.Contains($replaceSearchText)) { + $contentOfMainModule = $contentOfMainModule.Replace($replaceSearchText, + @" +#region $($powerShellScriptToBeMerged.BaseName) +$scriptContentToBeMerged +#endregion + +"@) + Remove-Item $powerShellScriptToBeMerged.FullName + } +} + +Set-Content -Path $mainModulePath -Value $contentOfMainModule + +Write-Verbose "Module created at '$outputFolder'" -Verbose diff --git a/test/Shared.ps1 b/test/Shared.ps1 index 9b5c025a4..0c62e5857 100644 --- a/test/Shared.ps1 +++ b/test/Shared.ps1 @@ -1,5 +1,13 @@ $modulePath = Convert-Path $PSScriptRoot\..\src $moduleManifestPath = "$modulePath\posh-git.psd1" +# Test against built folder in CI (or just set $env:CI locally for that) +if ($env:CI) { + $moduleVersion = (Import-LocalizedData -FileName 'posh-git.psd1' -BaseDirectory ($modulePath)).ModuleVersion + $builtModulePath = [System.IO.Path]::Combine($PSScriptRoot, '..', $moduleVersion) + if (Test-Path $builtModulePath) { + $moduleManifestPath = "$builtModulePath\posh-git.psd1" + } +} $csi = [char]0x1b + "["