diff --git a/AU/Public/Push-Package.ps1 b/AU/Public/Push-Package.ps1 index 20ea16e7..070cc342 100644 --- a/AU/Public/Push-Package.ps1 +++ b/AU/Public/Push-Package.ps1 @@ -17,8 +17,8 @@ function Push-Package() { $package = ls *.nupkg | sort -Property CreationTime -Descending | select -First 1 if (!$package) { throw 'There is no nupkg file in the directory'} if ($api_key) { - cpush $package.Name --api-key $api_key --source https://push.chocolatey.org + cpush $package.Name --limit-output --api-key $api_key --source https://push.chocolatey.org } else { - cpush $package.Name --source https://push.chocolatey.org + cpush $package.Name --limit-output --source https://push.chocolatey.org } } diff --git a/AU/Public/Set-DescriptionFromReadme.ps1 b/AU/Public/Set-DescriptionFromReadme.ps1 index 415abe54..1406d293 100644 --- a/AU/Public/Set-DescriptionFromReadme.ps1 +++ b/AU/Public/Set-DescriptionFromReadme.ps1 @@ -5,31 +5,32 @@ .DESCRIPTION This script should be called in au_AfterUpdate to put the text in the README.md into description tag of the Nuspec file. The current description will be replaced. - Function will throw an error if README.md is not found. - -.PARAMETER SkipFirst - Number of start lines to skip from the README.md, by default 0. - - -.PARAMETER SkipLast - Number of end lines to skip from the README.md, by default 0. + + You need to call this function manually only if you want to pass it custom parameters. + In that case use NoReadme parameter of the Update-Package. .EXAMPLE - function global:au_AfterUpdate { Set-DescriptionFromReadme -SkipFirst 2 } + function global:au_AfterUpdate { Set-DescriptionFromReadme -Package $args[0] -SkipLast 2 -SkipFirst 2 } #> -function Set-DescriptionFromReadme([int]$SkipFirst=0, [int]$SkipLast=0) { - if (!(Test-Path README.md)) { throw 'Set-DescriptionFromReadme: README.md not found' } +function Set-DescriptionFromReadme{ + param( + [AUPackage] $Package, + # Number of start lines to skip from the README.md, by default 0. + [int] $SkipFirst=0, + # Number of end lines to skip from the README.md, by default 0. + [int] $SkipLast=0 + ) + + 'Setting package description from README.md' - Write-Host 'Setting README.md to Nuspec description tag' $description = gc README.md -Encoding UTF8 $endIdx = $description.Length - $SkipLast $description = $description | select -Index ($SkipFirst..$endIdx) | Out-String - $nuspecFileName = $Latest.PackageName + ".nuspec" - $nu = gc $nuspecFileName -Raw -Encoding UTF8 - $nu = $nu -replace "(?smi)(\).*?(\)", "`${1}$($description)`$2" + $cdata = $Package.NuspecXml.CreateCDataSection($description) + $xml_Description = $Package.NuspecXml.GetElementsByTagName('description')[0] + $xml_Description.RemoveAll() + $xml_Description.AppendChild($cdata) | Out-Null - $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False) - $NuPath = (Resolve-Path $NuspecFileName) - [System.IO.File]::WriteAllText($NuPath, $nu, $Utf8NoBomEncoding) -} + $Package.SaveNuspec() +} \ No newline at end of file diff --git a/AU/Public/Update-Package.ps1 b/AU/Public/Update-Package.ps1 index 7125cdd4..6ddf5cb0 100644 --- a/AU/Public/Update-Package.ps1 +++ b/AU/Public/Update-Package.ps1 @@ -91,8 +91,11 @@ function Update-Package { #Output variable. [string] $Result, - #Backup and restore package - [switch] $WhatIf + #Backup and restore package. + [switch] $WhatIf, + + #Disable automatic update of nuspec description from README.md files with first 2 lines skipped. + [switch] $NoReadme ) function check_urls() { @@ -362,9 +365,10 @@ function Update-Package { if ($WhatIf) { $package.Backup() } try { - if (Test-Path Function:\au_BeforeUpdate) { 'Running au_BeforeUpdate' | result; au_BeforeUpdate | result } + if (Test-Path Function:\au_BeforeUpdate) { 'Running au_BeforeUpdate' | result; au_BeforeUpdate $package | result } update_files - if (Test-Path Function:\au_AfterUpdate) { 'Running au_AfterUpdate' | result; au_AfterUpdate | result } + if (!$NoReadme -and (Test-Path "$($package.Path)\README.md")) { Set-DescriptionFromReadme $package -SkipFirst 2 | result } + if (Test-Path Function:\au_AfterUpdate) { 'Running au_AfterUpdate' | result; au_AfterUpdate $package | result } choco pack --limit-output | result if ($LastExitCode -ne 0) { throw "Choco pack failed with exit code $LastExitCode" } diff --git a/CHANGELOG.md b/CHANGELOG.md index ac80a874..881d479f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ ## Next -- Added new function `Set-DescriptionFromReadme`. +- `au_BeforeUpdate` and `au_BeforeUpdate` now provide parameter `Package` of type `[AUPackage]` which you can use to modify Nuspec data. +- Added new function `Set-DescriptionFromReadme` that is called automatically when README.md is present in the package folder ([#85](https://github.com/majkinetor/au/issues/85)). See [documentation](https://github.com/majkinetor/au/tree/automatic_readme#automatic-package-description-from-readmemd). ## 2017.8.30 - `Update-AUPackages` - - New options to handle update.ps1 errors: `IgnoreOn`, `RepeatOn`,`RepeatCount`,`RepeatSleep`. See [documentation](https://github.com/majkinetor/au#handling-update-errors). ([#76](https://github.com/majkinetor/au/issues/76)) + - New options to handle update.ps1 errors: `IgnoreOn`, `RepeatOn`,`RepeatCount`,`RepeatSleep`. See [documentation](https://github.com/majkinetor/au#handling-update-errors). ([#76](https://github.com/majkinetor/au/issues/76)). - New option `WhatIf` option that will trigger WhatIf on all packages. - New AUPackage properties: `Ignored` (boolean) and `IgnoreMessage`. - Report plugin: `IgnoreMessage` is added in the ignore section. @@ -245,4 +246,4 @@ Take a look at the [working example](https://github.com/majkinetor/au-packages/b ## 2016.2.19 -- First PoC version. +- First PoC version. \ No newline at end of file diff --git a/README.md b/README.md index 195598c5..23a6115c 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,13 @@ To see AU in action see [video tutorial](https://www.youtube.com/watch?v=m2XpV2L - Use only PowerShell to create automatic update script for given package. - Automatically downloads installers and provides/verifies checksums for x32 and x64 versions. - Verifies URLs, nuspec versions, remote repository existence etc. -- Keep nuspec descriptions in README.md files. -- Can use global variables to change functionality. -- Sugar functions for Chocolatey package maintainers. +- Automatically sets the Nuspec descriptions from a README.md files. - Update single package or any subset of previously created AU packages with a single command. - Multithread support when updating multiple packages. - Plugin system when updating everything, with few integrated plugins to send email notifications, save results to gist and push updated packages to git repository. +- Use of global variables to change functionality. +- Sugar functions for Chocolatey package maintainers. +- Extraordinary performance - hundreeds of packages can be checked and updated in several minutes. ## Installation @@ -138,6 +139,18 @@ Package updated This is best understood via the example - take a look at the real life package [installer script](https://github.com/majkinetor/au-packages/blob/master/dngrep/tools/chocolateyInstall.ps1) and its [AU updater](https://github.com/majkinetor/au-packages/blob/master/dngrep/update.ps1). +### Automatic package description from README.md + +If a package directory contains the `README.md` file, its content will be automatically set as description of the package with first 2 lines omitted - you can put on those lines custom content that will not be visible in the package description. + +To disable this option use `$NoReadme` with the `Update-Package` function. You can still call it manually from within `au_AfterUpdate`, which you may want to do in order to pass custom parameters to it: + +```powershell +function global:au_AfterUpdate ($Package) { + Set-DescriptionFromReadme $Package -SkipLast 2 -SkipFirst 5 +} +``` + ### Checks The `update` function does the following checks: diff --git a/tests/Update-Package.Tests.ps1 b/tests/Update-Package.Tests.ps1 index dbca9563..5e70aa9d 100644 --- a/tests/Update-Package.Tests.ps1 +++ b/tests/Update-Package.Tests.ps1 @@ -27,6 +27,7 @@ Describe 'Update-Package' -Tag update { $global:au_NoCheckChocoVersion = $true $global:au_ChecksumFor = 'none' $global:au_WhatIf = $false + $global:au_NoReadme = $false rv -Scope global Latest -ea ignore 'BeforeUpdate', 'AfterUpdate' | % { rm "Function:/au_$_" -ea ignore } @@ -37,7 +38,26 @@ Describe 'Update-Package' -Tag update { InModuleScope AU { Context 'Updating' { - It 'can backup and restore using WhatIf' { + + It 'can set description from README.md' { + $readme = 'dummy readme & test' + '','', $readme | Out-File $TestDrive\test_package\README.md + $res = update + + $res.Result -match 'Setting package description from README.md' | Should Be $true + (nuspec_file).package.metadata.description.InnerText.Trim() | Should Be $readme + } + + It 'deesnt set description from README.md with NoReadme parameter' { + $readme = 'dummy readme & test' + '','', $readme | Out-File $TestDrive\test_package\README.md + $res = update -NoReadme + + $res.Result -match 'Setting package description from README.md' | Should BeNullOrEmpty + (nuspec_file).package.metadata.description | Should Be 'This is a test package for Pester' + } + + It 'can backup and restore using WhatIf' { get_latest -Version 1.2.3 $global:au_Force = $true; $global:au_Version = '1.0' $global:au_WhatIf = $true