Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

254 lines (212 sloc) 7.207 kB
<#
.Synopsis
Build script (https://github.com/nightroman/Invoke-Build)
.Description
HOW TO USE THIS SCRIPT AND BUILD THE MODULE
Get and copy MongoDB.Bson.dll and MongoDB.Driver.dll to Module.
Get the utility script Invoke-Build.ps1:
https://github.com/nightroman/Invoke-Build
Copy it to the path. Set location to here. Build:
PS> Invoke-Build Build
The task Help fails if Helps.ps1 is missing.
Ignore this error or get Helps.ps1:
https://github.com/nightroman/Helps
#>
param(
$Configuration = 'Release',
$TargetFrameworkVersion = 'v3.5'
)
$ModuleName = 'Mdbc'
# Module directory.
$ModuleRoot = Join-Path ([Environment]::GetFolderPath('MyDocuments')) WindowsPowerShell\Modules\$ModuleName
# Use MSBuild.
use 4.0 MSBuild
# Get version from release notes.
function Get-Version {
switch -Regex -File Release-Notes.md {'##\s+v(\d+\.\d+\.\d+)' {return $Matches[1]} }
}
# Synopsis: Generate or update meta files.
task Meta -Inputs Release-Notes.md -Outputs Module\$ModuleName.psd1, Src\AssemblyInfo.cs {
$Version = Get-Version
$Project = 'https://github.com/nightroman/Mdbc'
$Summary = 'Mdbc module - MongoDB Cmdlets for PowerShell'
$Copyright = 'Copyright (c) 2011-2015 Roman Kuzmin'
Set-Content Module\$ModuleName.psd1 @"
@{
Author = 'Roman Kuzmin'
ModuleVersion = '$Version'
Description = '$Summary'
CompanyName = '$Project'
Copyright = '$Copyright'
ModuleToProcess = '$ModuleName.dll'
RequiredAssemblies = 'MongoDB.Driver.dll', 'MongoDB.Bson.dll'
PowerShellVersion = '2.0'
GUID = '12c81cd8-bde3-4c91-a292-e6c4f868106a'
}
"@
Set-Content Src\AssemblyInfo.cs @"
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyProduct("$ModuleName")]
[assembly: AssemblyVersion("$Version")]
[assembly: AssemblyTitle("$Summary")]
[assembly: AssemblyCompany("$Project")]
[assembly: AssemblyCopyright("$Copyright")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
"@
}
# Synopsis: Build, on post-build event copy files and make help.
task Build Meta, {
exec { MSBuild Src\$ModuleName.sln /t:Build /p:Configuration=$Configuration /p:TargetFrameworkVersion=$TargetFrameworkVersion}
}
# Synopsis: Copy files to the module, then make help.
# It is called from the post-build event.
task PostBuild {
exec { robocopy Module $ModuleRoot /s /np /r:0 /xf *-Help.ps1 } (0..3)
Copy-Item Src\Bin\$Configuration\$ModuleName.dll $ModuleRoot
},
(job Help -Safe)
# Synopsis: Remove temp files.
task Clean {
Remove-Item -Force -Recurse -ErrorAction 0 `
"$ModuleName.*.nupkg",
z, Src\bin, Src\obj, README.htm, Release-Notes.htm
}
# Synopsis: Build help by Helps (https://github.com/nightroman/Helps).
task Help -Inputs (
Get-Item Src\Commands\*, Module\en-US\$ModuleName.dll-Help.ps1
) -Outputs (
"$ModuleRoot\en-US\$ModuleName.dll-Help.xml"
) {
. Helps.ps1
Convert-Helps Module\en-US\$ModuleName.dll-Help.ps1 $Outputs
}
# Synopsis: Build and test help.
task TestHelpExample {
. Helps.ps1
Test-Helps Module\en-US\$ModuleName.dll-Help.ps1
}
# Synopsis: Docs by https://www.nuget.org/packages/MarkdownToHtml
task ConvertMarkdown {
exec { MarkdownToHtml from=README.md to=README.htm }
exec { MarkdownToHtml from=Release-Notes.md to=Release-Notes.htm }
}
# Synopsis: Set $script:Version.
task Version {
($script:Version = Get-Version)
# module version
assert ((Get-Module $ModuleName -ListAvailable).Version -eq ([Version]$script:Version))
# assembly version
assert ((Get-Item $ModuleRoot\$ModuleName.dll).VersionInfo.FileVersion -eq ([Version]"$script:Version.0"))
}
# Synopsis: Make the package in z\tools.
task Package ConvertMarkdown, (job UpdateScript -Safe), {
Remove-Item [z] -Force -Recurse
$null = mkdir z\tools\$ModuleName\en-US, z\tools\$ModuleName\Scripts
Copy-Item -Destination z\tools\$ModuleName `
LICENSE.txt,
README.htm,
Release-Notes.htm,
$ModuleRoot\$ModuleName.dll,
$ModuleRoot\$ModuleName.psd1,
$ModuleRoot\MongoDB.Bson.dll,
$ModuleRoot\MongoDB.Driver.dll
Copy-Item -Destination z\tools\$ModuleName\en-US `
$ModuleRoot\en-US\about_$ModuleName.help.txt,
$ModuleRoot\en-US\$ModuleName.dll-Help.xml
Copy-Item -Destination z\tools\$ModuleName\Scripts `
.\Scripts\Mdbc.ps1,
.\Scripts\Get-MongoFile.ps1,
.\Scripts\Update-MongoFiles.ps1,
.\Scripts\TabExpansionProfile.Mdbc.ps1
}
# Synopsis: Make NuGet package.
task NuGet Package, Version, {
$text = @'
Mdbc is the Windows PowerShell module based on the official MongoDB C# driver.
It makes MongoDB scripting in PowerShell easier and provides some extra
features like bson/json file collections which do not require MongoDB.
'@
# nuspec
Set-Content z\Package.nuspec @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$ModuleName</id>
<version>$Version</version>
<authors>Roman Kuzmin</authors>
<owners>Roman Kuzmin</owners>
<projectUrl>https://github.com/nightroman/Mdbc</projectUrl>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>$text</summary>
<description>$text</description>
<tags>Mongo MongoDB PowerShell Module Database</tags>
</metadata>
</package>
"@
# pack
exec { NuGet pack z\Package.nuspec -NoPackageAnalysis }
}
# Synopsis: Push to the repository with a version tag.
task PushRelease Version, {
$changes = exec { git status --short }
assert (!$changes) "Please, commit changes."
exec { git push }
exec { git tag -a "v$Version" -m "v$Version" }
exec { git push origin "v$Version" }
}
# Synopsis: Make and push the NuGet package.
task PushNuGet NuGet, {
exec { NuGet push "$ModuleName.$Version.nupkg" }
},
Clean
# Synopsis: Remove test.test* collections
task CleanTest {
Import-Module Mdbc
foreach($Collection in Connect-Mdbc . test *) {
if ($Collection.Name -like 'test*') {
$null = $Collection.Drop()
}
}
}
# Synopsis: Test synopsis of each cmdlet and warn about unexpected.
task TestHelpSynopsis {
Import-Module Mdbc
Get-Command *-Mdbc* -CommandType cmdlet | Get-Help | .{process{
if (!$_.Synopsis.EndsWith('.')) {
Write-Warning "$($_.Name) : unexpected/missing synopsis"
}
}}
}
# Synopsis: Update help then run help tests.
task TestHelp Help, TestHelpExample, TestHelpSynopsis
$UpdateScriptInputs = @(
'Get-MongoFile.ps1'
'Mdbc.ps1'
'TabExpansionProfile.Mdbc.ps1'
'Update-MongoFiles.ps1'
)
# Synopsis: Copy external scripts to the project.
# It fails if a script is missing.
task UpdateScript -Partial `
-Inputs { Get-Command $UpdateScriptInputs | .{process{ $_.Definition }} } `
-Outputs {process{ "Scripts\$(Split-Path -Leaf $_)" }} `
{process{ Copy-Item $_ $2 }}
# Synopsis: Check expected files.
task CheckFiles {
$Pattern = '\.(cs|csproj|md|ps1|psd1|psm1|ps1xml|sln|txt|xml|gitignore)$'
foreach ($file in git status -s) { if ($file -notmatch $Pattern) {
Write-Warning "Illegal file: '$file'."
}}
}
# Synopsis: Call tests and test the expected count.
task Test {
Invoke-Build ** Tests -Result result
assert (159 -eq $result.Tasks.Count) "Unexpected test count: $($result.Tasks.Count)."
},
CleanTest
# Synopsis: Build, test and clean all.
task . Build, TestHelp, Test, Clean, CheckFiles
Jump to Line
Something went wrong with that request. Please try again.