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

Update Package

Elouan edited this page Feb 21, 2018 · 4 revisions

Update-Package

NAME

Update-Package

SYNOPSIS

Update automatic package

SYNTAX

Update-Package [-NoCheckUrl] [-NoCheckChocoVersion] [[-ChecksumFor] <String>] [[-Timeout] <Int32>] [[-IncludeStream] <Array>] [-Force] [-NoHostOutput] [[-Result] <String>] [<CommonParameters>]

DESCRIPTION

This function is used to perform necessary updates to the specified files in the package. It shouldn't be used on its own but must be part of the script which defines two functions:

  • au_SearchReplace The function should return HashTable where keys are file paths and value is another HashTable where keys and values are standard search and replace strings
  • au_GetLatest Returns the HashTable where the script specifies information about new Version, new URLs and any other data. You can refer to this variable as the $Latest in the script. While Version is used to determine if updates to the package are needed, other arguments can be used in search and replace patterns or for whatever purpose.

With those 2 functions defined, calling Update-Package will:

  • Call your au_GetLatest function to get the remote version and other information.
  • If remote version is higher then the nuspec version, function will:
    • Check the returned URLs, Versions and Checksums (if defined) for validity (unless NoCheckXXX variables are specified)
    • Download files and calculate checksum(s), (unless already defined or ChecksumFor is set to 'none')
    • Update the nuspec with the latest version
    • Do the necessary file replacements
    • Pack the files into the nuget package

You can also define au_BeforeUpdate and au_AfterUpdate functions to integrate your code into the update pipeline.

PARAMETERS

-NoCheckUrl [<SwitchParameter>]
    Do not check URL and version for validity.
    
    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-NoCheckChocoVersion [<SwitchParameter>]
    Do not check if latest returned version already exists in the Chocolatey community feed.
    Ignored when Force is specified.
    
    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-ChecksumFor <String>
    Specify for which architectures to calculate checksum - all, 32 bit, 64 bit or none.
    
    Required?                    false
    Position?                    1
    Default value                all
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-Timeout <Int32>
    Timeout for all web operations, by default 100 seconds.
    
    Required?                    false
    Position?                    2
    Default value                0
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-IncludeStream <Array>
    Stream(s) to process, either a string or an array. If omitted, all streams are processed.
    A single stream is required when `Force` is specified.
    
    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-Force [<SwitchParameter>]
    Force package update even if no new version is found.
    
    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-NoHostOutput [<SwitchParameter>]
    Do not show any Write-Host output.
    
    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-Result <String>
    Output variable.
    
    Required?                    false
    Position?                    3
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see 
    about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 

INPUTS

OUTPUTS

PSCustomObject with type AUPackage.

NOTES

    All function parameters accept defaults via global variables with prefix `au_` (example: $global:au_Force = $true).

-------------------------- EXAMPLE 1 --------------------------

PS>notepad update.ps1

# The following script is used to update the package from the github releases page.
# After it defines the 2 functions, it calls the Update-Package.
# Checksums are automatically calculated for 32 bit version (the only one in this case)
import-module au

function global:au_SearchReplace {
    ".\tools\chocolateyInstall.ps1" = @{
        "(^[$]url32\s*=\s*)('.*')"          = "`$1'$($Latest.URL32)'"
        "(^[$]checksum32\s*=\s*)('.*')"     = "`$1'$($Latest.Checksum32)'"
        "(^[$]checksumType32\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType32)'"
    }
}

function global:au_GetLatest {
    $download_page = Invoke-WebRequest https://github.com/hluk/CopyQ/releases -UseBasicParsing

    $re  = "copyq-.*-setup.exe"
    $url = $download_page.links | ? href -match $re | select -First 1 -expand href
    $version = $url -split '-|.exe' | select -Last 1 -Skip 2

    return @{ URL32 = $url; Version = $version }
}

Update-Package -ChecksumFor 32

RELATED LINKS

Update-AUPackages 

NOTE: This documentation has been automatically generated from Get-Help Update-Package -Full.