Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Automatic readme #91

Merged
merged 7 commits into from
Sep 20, 2017
Merged
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: 2 additions & 2 deletions AU/Public/Push-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
39 changes: 20 additions & 19 deletions AU/Public/Set-DescriptionFromReadme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)(\<description\>).*?(\</description\>)", "`${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()
}
12 changes: 8 additions & 4 deletions AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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" }
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion tests/Update-Package.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down