Skip to content

Commit f0375b6

Browse files
committed
Change encoding to UTF-8
1 parent 22612ca commit f0375b6

File tree

1 file changed

+83
-76
lines changed

1 file changed

+83
-76
lines changed

Tests/build.ps1

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,83 @@
1-
# Pester. Let's run some tests!
2-
# https://github.com/pester/Pester/wiki/Showing-Test-Results-in-CI-(TeamCity,-AppVeyor)
3-
# https://www.appveyor.com/docs/running-tests/#build-worker-api
4-
5-
# Invoke-Pester runs all .Tests.ps1 in the order found by "Get-ChildItem -Recurse"
6-
$TestResults = Invoke-Pester -OutputFormat NUnitXml -OutputFile ".\TestResults.xml" -PassThru
7-
# Upload the XML file of test results to the current AppVeyor job
8-
(New-Object 'System.Net.WebClient').UploadFile(
9-
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)",
10-
(Resolve-Path ".\TestResults.xml") )
11-
# If a Pester test failed, use "throw" to end the script here, before deploying
12-
If ($TestResults.FailedCount -gt 0) {
13-
throw "$($TestResults.FailedCount) Pester test(s) failed."
14-
}
15-
16-
# Line break for readability in AppVeyor console
17-
Write-Host ''
18-
19-
# Stop here if this isn't the master branch, or if this is a pull request
20-
If ($env:APPVEYOR_REPO_BRANCH -ne 'master') {
21-
Write-Warning "Skipping version increment and gallery publish for branch $env:APPVEYOR_REPO_BRANCH"
22-
} ElseIf ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0) {
23-
Write-Warning "Skipping version increment and gallery publish for pull request #$env:APPVEYOR_PULL_REQUEST_NUMBER"
24-
} Else {
25-
# Hopefully everything's good, because this is headed out to the world
26-
# First, update the module's version
27-
28-
Try {
29-
# Use the major/minor module version defined in source control
30-
$Manifest = Test-ModuleManifest .\ConfluencePS\ConfluencePS.psd1
31-
# Append the current build number
32-
[Version]$Version = "$($Manifest.Version).$env:APPVEYOR_BUILD_NUMBER"
33-
# Update the .psd1 with the current major/minor/build SemVer
34-
# And placeholder text for Functions, because Update-ModuleManifest is the worst
35-
$UMM = @{
36-
Path = '.\ConfluencePS\ConfluencePS.psd1'
37-
ModuleVersion = $Version
38-
FunctionsToExport = 'I hate you, stupid Update-ModuleManifest'
39-
ErrorAction = 'Stop'
40-
}
41-
Update-ModuleManifest @UMM
42-
43-
# Fix the mangling of FunctionsToExport
44-
$Functions = $Manifest.ExportedCommands.Keys
45-
# Join the functions and apply new lines "`n" and tabs "`t" to match original formatting
46-
$FunctionString = "@(`n`t'$($Functions -join "',`n`t'")'`n)"
47-
# Replace the placeholder text
48-
(Get-Content .\ConfluencePS\ConfluencePS.psd1) ` -replace 'I hate you, stupid Update-ModuleManifest', $FunctionString | Set-Content .\ConfluencePS\ConfluencePS.psd1 -ErrorAction Stop # Now, have to get rid of the '' quotes wrapping the function array # Two replaces because the quotes are on separate lines (Get-Content .\ConfluencePS\ConfluencePS.psd1) ` -replace "(FunctionsToExport = )(')",'$1' -replace "\)'",')' | Set-Content .\ConfluencePS\ConfluencePS.psd1 -ErrorAction Stop
49-
} Catch {
50-
throw 'Version update failed. Skipping publish to gallery'
51-
}
52-
53-
Import-Module .\ConfluencePS\ConfluencePS.psd1
54-
$Count1 = (Get-Command -Module ConfluencePS).Count
55-
$Count2 = (Test-ModuleManifest .\ConfluencePS\ConfluencePS.psd1).ExportedCommands.Count
56-
$Count3 = (Get-ChildItem .\ConfluencePS\Public).Count
57-
If ($Count1 -ne $Count2) {
58-
throw "Expected $Count2 commands to be exported, but found $Count1 instead"
59-
} ElseIf ($Count1 -ne $Count3) {
60-
throw "Expected $Count3 commands to be exported, but found $Count1 instead"
61-
}
62-
63-
Try {
64-
# Now, publish the update to the PowerShell Gallery
65-
$PM = @{
66-
Path = '.\ConfluencePS'
67-
NuGetApiKey = $env:PSGalleryAPIKey
68-
ErrorAction = 'Stop'
69-
}
70-
Publish-Module @PM
71-
72-
Write-Host "ConfluencePS version $Version published to the PowerShell Gallery." -ForegroundColor Cyan
73-
} Catch {
74-
throw "Publishing update $Version to the PowerShell Gallery failed."
75-
}
76-
}
1+
# Pester. Let's run some tests!
2+
# https://github.com/pester/Pester/wiki/Showing-Test-Results-in-CI-(TeamCity,-AppVeyor)
3+
# https://www.appveyor.com/docs/running-tests/#build-worker-api
4+
5+
# Invoke-Pester runs all .Tests.ps1 in the order found by "Get-ChildItem -Recurse"
6+
$TestResults = Invoke-Pester -OutputFormat NUnitXml -OutputFile ".\TestResults.xml" -PassThru
7+
# Upload the XML file of test results to the current AppVeyor job
8+
(New-Object 'System.Net.WebClient').UploadFile(
9+
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)",
10+
(Resolve-Path ".\TestResults.xml") )
11+
# If a Pester test failed, use "throw" to end the script here, before deploying
12+
If ($TestResults.FailedCount -gt 0) {
13+
throw "$($TestResults.FailedCount) Pester test(s) failed."
14+
}
15+
16+
# Line break for readability in AppVeyor console
17+
Write-Host ''
18+
19+
# Stop here if this isn't the master branch, or if this is a pull request
20+
If ($env:APPVEYOR_REPO_BRANCH -ne 'master') {
21+
Write-Warning "Skipping version increment and gallery publish for branch $env:APPVEYOR_REPO_BRANCH"
22+
} ElseIf ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0) {
23+
Write-Warning "Skipping version increment and gallery publish for pull request #$env:APPVEYOR_PULL_REQUEST_NUMBER"
24+
} Else {
25+
# Hopefully everything's good, because this is headed out to the world
26+
# First, update the module's version
27+
28+
Try {
29+
# Use the major/minor module version defined in source control
30+
$Manifest = Test-ModuleManifest .\ConfluencePS\ConfluencePS.psd1
31+
# Append the current build number
32+
[Version]$Version = "$($Manifest.Version).$env:APPVEYOR_BUILD_NUMBER"
33+
# Update the .psd1 with the current major/minor/build SemVer
34+
# And placeholder text for Functions, because Update-ModuleManifest is the worst
35+
$UMM = @{
36+
Path = '.\ConfluencePS\ConfluencePS.psd1'
37+
ModuleVersion = $Version
38+
FunctionsToExport = 'I hate you, stupid Update-ModuleManifest'
39+
ErrorAction = 'Stop'
40+
}
41+
Update-ModuleManifest @UMM
42+
43+
# Fix the mangling of FunctionsToExport
44+
$Functions = $Manifest.ExportedCommands.Keys
45+
# Join the functions and apply new lines "`n" and tabs "`t" to match original formatting
46+
$FunctionString = "@(`n`t'$($Functions -join "',`n`t'")'`n)"
47+
# Replace the placeholder text
48+
(Get-Content .\ConfluencePS\ConfluencePS.psd1) `
49+
-replace 'I hate you, stupid Update-ModuleManifest', $FunctionString |
50+
Set-Content .\ConfluencePS\ConfluencePS.psd1 -ErrorAction Stop
51+
# Now, have to get rid of the '' quotes wrapping the function array
52+
# Two replaces because the quotes are on separate lines
53+
(Get-Content .\ConfluencePS\ConfluencePS.psd1) `
54+
-replace "(FunctionsToExport = )(')",'$1' -replace "\)'",')' |
55+
Set-Content .\ConfluencePS\ConfluencePS.psd1 -ErrorAction Stop
56+
} Catch {
57+
throw 'Version update failed. Skipping publish to gallery'
58+
}
59+
60+
Import-Module .\ConfluencePS\ConfluencePS.psd1
61+
$Count1 = (Get-Command -Module ConfluencePS).Count
62+
$Count2 = (Test-ModuleManifest .\ConfluencePS\ConfluencePS.psd1).ExportedCommands.Count
63+
$Count3 = (Get-ChildItem .\ConfluencePS\Public).Count
64+
If ($Count1 -ne $Count2) {
65+
throw "Expected $Count2 commands to be exported, but found $Count1 instead"
66+
} ElseIf ($Count1 -ne $Count3) {
67+
throw "Expected $Count3 commands to be exported, but found $Count1 instead"
68+
}
69+
70+
Try {
71+
# Now, publish the update to the PowerShell Gallery
72+
$PM = @{
73+
Path = '.\ConfluencePS'
74+
NuGetApiKey = $env:PSGalleryAPIKey
75+
ErrorAction = 'Stop'
76+
}
77+
Publish-Module @PM
78+
79+
Write-Host "ConfluencePS version $Version published to the PowerShell Gallery." -ForegroundColor Cyan
80+
} Catch {
81+
throw "Publishing update $Version to the PowerShell Gallery failed."
82+
}
83+
}

0 commit comments

Comments
 (0)