Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VERSION
*.nupkg
obj
obj
# ignore release dirs
/*.*.*
14 changes: 14 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.)'
Expand Down
41 changes: 41 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/Shared.ps1
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Copy Markdown
Collaborator

@rkeithhill rkeithhill Sep 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works on a build machine. Can we also add a PowerShell variable check here like:

if ($env:CI -or $PoshGitBuild)

That way if we build & test from the build.ps1 script on a dev machine, it will run the Pester tests against the release dir. And because that $PoshGitBuild variable goes away after the build script exits, I can still run tests from the src folder module when I doing dev work.

$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 + "["

Expand Down