Skip to content

Commit 81bcbe9

Browse files
committed
Add IgnoreVersion parameter.
1 parent 7ec6682 commit 81bcbe9

2 files changed

Lines changed: 46 additions & 21 deletions

File tree

Chocolatey-Package-Updater.ps1

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<#PSScriptInfo
22
3-
.VERSION 0.0.10
3+
.VERSION 0.0.11
44
55
.GUID 9b612c16-25c0-4a40-afc7-f876274e7e8c
66
@@ -23,6 +23,7 @@
2323
[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.
2424
[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.
2525
[Version 0.0.10] - Added disable IPv6 to aria2c args.
26+
[Version 0.0.11] - Added ignore version.
2627
2728
#>
2829

@@ -79,7 +80,7 @@ To update a Chocolatey package with additional parameters, run the following com
7980
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
8081
8182
.NOTES
82-
- Version: 0.0.10
83+
- Version: 0.0.11
8384
- Created by: asheroto
8485
- See project site for instructions on how to use including full parameter list and examples.
8586
@@ -98,7 +99,7 @@ param (
9899
# Initial vars
99100
# ============================================================================ #
100101

101-
$CurrentVersion = '0.0.10'
102+
$CurrentVersion = '0.0.11'
102103
$RepoOwner = 'asheroto'
103104
$RepoName = 'Chocolatey-Package-Updater'
104105
$SoftwareName = 'Chocolatey Package Updater'
@@ -499,7 +500,10 @@ function UpdateChocolateyPackage {
499500
[string]$DownloadUrlScrapePattern64,
500501

501502
[Parameter(Mandatory = $false)]
502-
[string]$GitHubRepoUrl
503+
[string]$GitHubRepoUrl,
504+
505+
[Parameter(Mandatory = $false)]
506+
[string]$IgnoreVersion
503507
)
504508

505509
function Try-DeleteFile {
@@ -644,7 +648,8 @@ function UpdateChocolateyPackage {
644648
[string]$VerificationPath,
645649
[string]$VerificationChecksum,
646650
[string]$VerificationChecksum64,
647-
[string]$FileUrl64
651+
[string]$FileUrl64,
652+
[string]$IgnoreVersion
648653
)
649654

650655
$result = @{}
@@ -811,6 +816,12 @@ function UpdateChocolateyPackage {
811816

812817
Write-Output "Nuspec version: $NuspecVersion"
813818

819+
# If the version is the same as the ignore version, skip the comparison
820+
if ($ProductVersion -eq $IgnoreVersion) {
821+
Write-Output "IgnoreVersion specified, ignoring comparison for version: $IgnoreVersion"
822+
return
823+
}
824+
814825
Write-Output "New checksum: $NewChecksum"
815826
if ($FileUrl64) {
816827
Write-Output "New checksum (64-bit): $NewChecksum64"
@@ -911,6 +922,19 @@ function UpdateChocolateyPackage {
911922
# Write the new version to the console
912923
Write-Output "Updated to version $ProductVersion"
913924

925+
# Delete any nupkg files in the package folder if it exists
926+
$nupkgFiles = Get-ChildItem -Path $ScriptPath -Filter "$PackageName.*.nupkg" -File
927+
if ($nupkgFiles) {
928+
foreach ($nupkgFile in $nupkgFiles) {
929+
Write-Output "Deleting old nupkg file: $nupkgFile"
930+
Remove-Item -Path $nupkgFile.FullName -Force
931+
}
932+
}
933+
934+
# Run 'choco pack' to create the nupkg file
935+
Write-Output "Creating nupkg file..."
936+
choco pack
937+
914938
# Send an alert if enabled
915939
Write-Debug "Sending alert..."
916940
SendAlert -Subject "$PackageName Package Updated" -Message "$PackageName has been updated to version $ProductVersion. It is now ready for testing." -Alert $Alert

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,23 @@ pwsh -Command "& 'C:\Projects\ChocolateyPackages\fxsound\update.ps1'"
273273

274274
## Function Parameters for `UpdateChocolateyPackage`
275275

276-
| Parameter | Type | Required | Description |
277-
| ------------------------- | ------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
278-
| `-PackageName` | string | Yes | The name of the package. |
279-
| `-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. |
280-
| `-FileUrl64` | string | Yes | The URL to download the file from. |
281-
| `-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). |
282-
| `-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). |
283-
| `-GitHubRepoUrl` | string | No | The URL to the GitHub repository. If specified, the latest release will be downloaded using `{VERSION}` replacement in the `FileUrl`. |
284-
| `-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. |
285-
| `-ScrapePattern` | string | No | The regex pattern to use when scraping the version number from the scrape URL. |
286-
| `-Alert` | boolean | No | If the package is updated, send a message to the maintainer for review |
287-
| `-NuspecPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the nuspec file |
288-
| `-InstallScriptPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `ChocolateyInstall.ps1` script |
289-
| `-VerificationPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `VERIFICATION.txt` file |
290-
| `-FileDownloadTempPath` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
291-
| `-FileDownloadTempPath64` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
276+
| Parameter | Type | Required | Description |
277+
| ------------------------- | ------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
278+
| `-PackageName` | string | Yes | The name of the package. |
279+
| `-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. |
280+
| `-FileUrl64` | string | Yes | The URL to download the file from. |
281+
| `-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). |
282+
| `-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). |
283+
| `-GitHubRepoUrl` | string | No | The URL to the GitHub repository. If specified, the latest release will be downloaded using `{VERSION}` replacement in the `FileUrl`. |
284+
| `-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. |
285+
| `-ScrapePattern` | string | No | The regex pattern to use when scraping the version number from the scrape URL. |
286+
| `-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. |
287+
| `-Alert` | boolean | No | If the package is updated, send a message to the maintainer for review |
288+
| `-NuspecPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the nuspec file |
289+
| `-InstallScriptPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `ChocolateyInstall.ps1` script |
290+
| `-VerificationPath` | string | No | **Not recommended. Recommended using default Choco paths.** Absolute/relative path to the `VERIFICATION.txt` file |
291+
| `-FileDownloadTempPath` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
292+
| `-FileDownloadTempPath64` | string | No | **Not recommended. Recommended using default paths.**Absolute/relative path to save the file to |
292293

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

0 commit comments

Comments
 (0)