Skip to content

Commit

Permalink
Add IgnoreVersion parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
asheroto committed Jun 9, 2024
1 parent 7ec6682 commit 81bcbe9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
34 changes: 29 additions & 5 deletions Chocolatey-Package-Updater.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 0.0.10
.VERSION 0.0.11
.GUID 9b612c16-25c0-4a40-afc7-f876274e7e8c
Expand All @@ -23,6 +23,7 @@
[Version 0.0.8] - Improved help. Added Help parameter. Added loop to repeatedly attempt file deletion if it's in use, mitigating file deletion prevention by antivirus software scanning download.
[Version 0.0.9] - Improved ProductVersion/FileVersion detection, only returns applicable Chocolatey version number despite the version provided in the metadata of the file/installer.
[Version 0.0.10] - Added disable IPv6 to aria2c args.
[Version 0.0.11] - Added ignore version.
#>

Expand Down Expand Up @@ -79,7 +80,7 @@ To update a Chocolatey package with additional parameters, run the following com
UpdateChocolateyPackage -PackageName "fxsound" -FileUrl "https://download.fxsound.com/fxsoundlatest" -FileDownloadTempPath ".\fxsound_setup_temp.exe" -FileDestinationPath ".\tools\fxsound_setup.exe" -NuspecPath ".\fxsound.nuspec" -InstallScriptPath ".\tools\ChocolateyInstall.ps1" -VerificationPath ".\tools\VERIFICATION.txt" -Alert $true
.NOTES
- Version: 0.0.10
- Version: 0.0.11
- Created by: asheroto
- See project site for instructions on how to use including full parameter list and examples.
Expand All @@ -98,7 +99,7 @@ param (
# Initial vars
# ============================================================================ #

$CurrentVersion = '0.0.10'
$CurrentVersion = '0.0.11'
$RepoOwner = 'asheroto'
$RepoName = 'Chocolatey-Package-Updater'
$SoftwareName = 'Chocolatey Package Updater'
Expand Down Expand Up @@ -499,7 +500,10 @@ function UpdateChocolateyPackage {
[string]$DownloadUrlScrapePattern64,

[Parameter(Mandatory = $false)]
[string]$GitHubRepoUrl
[string]$GitHubRepoUrl,

[Parameter(Mandatory = $false)]
[string]$IgnoreVersion
)

function Try-DeleteFile {
Expand Down Expand Up @@ -644,7 +648,8 @@ function UpdateChocolateyPackage {
[string]$VerificationPath,
[string]$VerificationChecksum,
[string]$VerificationChecksum64,
[string]$FileUrl64
[string]$FileUrl64,
[string]$IgnoreVersion
)

$result = @{}
Expand Down Expand Up @@ -811,6 +816,12 @@ function UpdateChocolateyPackage {

Write-Output "Nuspec version: $NuspecVersion"

# If the version is the same as the ignore version, skip the comparison
if ($ProductVersion -eq $IgnoreVersion) {
Write-Output "IgnoreVersion specified, ignoring comparison for version: $IgnoreVersion"
return
}

Write-Output "New checksum: $NewChecksum"
if ($FileUrl64) {
Write-Output "New checksum (64-bit): $NewChecksum64"
Expand Down Expand Up @@ -911,6 +922,19 @@ function UpdateChocolateyPackage {
# Write the new version to the console
Write-Output "Updated to version $ProductVersion"

# Delete any nupkg files in the package folder if it exists
$nupkgFiles = Get-ChildItem -Path $ScriptPath -Filter "$PackageName.*.nupkg" -File
if ($nupkgFiles) {
foreach ($nupkgFile in $nupkgFiles) {
Write-Output "Deleting old nupkg file: $nupkgFile"
Remove-Item -Path $nupkgFile.FullName -Force
}
}

# Run 'choco pack' to create the nupkg file
Write-Output "Creating nupkg file..."
choco pack

# Send an alert if enabled
Write-Debug "Sending alert..."
SendAlert -Subject "$PackageName Package Updated" -Message "$PackageName has been updated to version $ProductVersion. It is now ready for testing." -Alert $Alert
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,23 @@ pwsh -Command "& 'C:\Projects\ChocolateyPackages\fxsound\update.ps1'"

## Function Parameters for `UpdateChocolateyPackage`

| Parameter | Type | Required | Description |
| ------------------------- | ------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-PackageName` | string | Yes | The name of the package. |
| `-FileUrl` | string | Yes | The URL to download the file from. If you're using `ScrapeUrl` and `ScrapePattern` you can specify `{VERSION}` in the `FileUrl` and it will download from that FileUrl. |
| `-FileUrl64` | string | Yes | The URL to download the file from. |
| `-FileDestinationPath` | string | Only required if EXE distributed in package | Absolute/relative path to move/rename the temporary file to (if EXE is distributed in package). |
| `-FileDestinationPath64` | string | Only required if url and url64 is used and EXE is distributed in package | Absolute/relative path to move/rename the temporary file to (if EXE is distributed in package). |
| `-GitHubRepoUrl` | string | No | The URL to the GitHub repository. If specified, the latest release will be downloaded using `{VERSION}` replacement in the `FileUrl`. |
| `-ScrapeUrl` | string | No | If the version number is not available in the download URL, you can specify a URL to scrape the version number from. |
| `-ScrapePattern` | string | No | The regex pattern to use when scraping the version number from the scrape URL. |
| `-Alert` | boolean | No | If the package is updated, send a message to the maintainer for review |
| `-NuspecPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the nuspec file |
| `-InstallScriptPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `ChocolateyInstall.ps1` script |
| `-VerificationPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `VERIFICATION.txt` file |
| `-FileDownloadTempPath` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
| `-FileDownloadTempPath64` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
| Parameter | Type | Required | Description |
| ------------------------- | ------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-PackageName` | string | Yes | The name of the package. |
| `-FileUrl` | string | Yes | The URL to download the file from. If you're using `ScrapeUrl` and `ScrapePattern` you can specify `{VERSION}` in the `FileUrl` and it will download from that FileUrl. |
| `-FileUrl64` | string | Yes | The URL to download the file from. |
| `-FileDestinationPath` | string | Only required if EXE distributed in package | Absolute/relative path to move/rename the temporary file to (if EXE is distributed in package). |
| `-FileDestinationPath64` | string | Only required if url and url64 is used and EXE is distributed in package | Absolute/relative path to move/rename the temporary file to (if EXE is distributed in package). |
| `-GitHubRepoUrl` | string | No | The URL to the GitHub repository. If specified, the latest release will be downloaded using `{VERSION}` replacement in the `FileUrl`. |
| `-ScrapeUrl` | string | No | If the version number is not available in the download URL, you can specify a URL to scrape the version number from. |
| `-ScrapePattern` | string | No | The regex pattern to use when scraping the version number from the scrape URL. |
| `-IgnoreVersion` | string | No | Ignore this version when attempting to update. This is useful for cases where you have modified the updater, such as `1.0.2.20240531`, and want to ignore version `1.0.2` because version checks would otherwise fail. |
| `-Alert` | boolean | No | If the package is updated, send a message to the maintainer for review |
| `-NuspecPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the nuspec file |
| `-InstallScriptPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `ChocolateyInstall.ps1` script |
| `-VerificationPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `VERIFICATION.txt` file |
| `-FileDownloadTempPath` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
| `-FileDownloadTempPath64` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |

`-ScrapeUrl64` and `-ScrapePattern64` are not options because the version number should be the same regardless of architecture.

Expand Down

0 comments on commit 81bcbe9

Please sign in to comment.