Skip to content

Commit

Permalink
Add AutoPush param
Browse files Browse the repository at this point in the history
  • Loading branch information
asheroto committed Jun 19, 2024
1 parent 81bcbe9 commit dc8085f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
36 changes: 32 additions & 4 deletions Chocolatey-Package-Updater.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 0.0.11
.VERSION 0.0.12
.GUID 9b612c16-25c0-4a40-afc7-f876274e7e8c
Expand All @@ -24,6 +24,7 @@
[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.
[Version 0.0.12] - Added AutoPush for automatic pushing to Chocolatey community repository.
#>

Expand Down Expand Up @@ -80,7 +81,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.11
- Version: 0.0.12
- Created by: asheroto
- See project site for instructions on how to use including full parameter list and examples.
Expand All @@ -99,7 +100,7 @@ param (
# Initial vars
# ============================================================================ #

$CurrentVersion = '0.0.11'
$CurrentVersion = '0.0.12'
$RepoOwner = 'asheroto'
$RepoName = 'Chocolatey-Package-Updater'
$SoftwareName = 'Chocolatey Package Updater'
Expand Down Expand Up @@ -503,7 +504,10 @@ function UpdateChocolateyPackage {
[string]$GitHubRepoUrl,

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

[Parameter(Mandatory = $false)]
[boolean]$AutoPush
)

function Try-DeleteFile {
Expand Down Expand Up @@ -674,6 +678,18 @@ function UpdateChocolateyPackage {
return $result
}

function Remove-LeadingZeroesFromVersion {
param (
[string]$VersionNumber
)

$versionParts = $VersionNumber -split '\.'
$cleanedVersionParts = $versionParts | ForEach-Object { [int]$_ }
$cleanedVersion = ($cleanedVersionParts -join '.')

return $cleanedVersion
}

# ============================================================================ #
# Main Script
# ============================================================================ #
Expand Down Expand Up @@ -767,6 +783,12 @@ function UpdateChocolateyPackage {
$ProductVersion64 = Get-ProductVersion -FileDownloadTempPath $FileDownloadTempPath64 -ForceVersionNumber $ForceVersionNumber
}

# Remove leading zeroes from version numbers
$ProductVersion = Remove-LeadingZeroesFromVersion -VersionNumber $ProductVersion
if ($ProductVersion64) {
$ProductVersion64 = Remove-LeadingZeroesFromVersion -VersionNumber $ProductVersion64
}

# Nuspec Version and Checksums
$NuspecContent = Get-Content $NuspecPath -Raw
$NuspecVersion = ([regex]::Match($NuspecContent, '<version>(.*?)<\/version>')).Groups[1].Value
Expand Down Expand Up @@ -935,6 +957,12 @@ function UpdateChocolateyPackage {
Write-Output "Creating nupkg file..."
choco pack

# If AutoPush is enabled, push the package to Chocolatey
if ($AutoPush) {
Write-Output "Pushing package to Chocolatey..."
choco push "$PackageName.$ProductVersion.nupkg"
}

# 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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ This method corresponds to the [example-package-github-repo](example-package-git
```powershell
# Create a hash table to store package information
$packageInfo = @{
PackageName = "ventoy"
FileUrl = "https://github.com/ventoy/Ventoy/releases/download/v{VERSION}/ventoy-{VERSION}-windows.zip"
GitHubRepoUrl = "https://github.com/ventoy/Ventoy"
PackageName = "ventoy" # Package name
FileUrl = "https://github.com/ventoy/Ventoy/releases/download/v{VERSION}/ventoy-{VERSION}-windows.zip" # URL to download the file from, using {VERSION} where the version number goes
GitHubRepoUrl = "https://github.com/ventoy/Ventoy" # GitHub repository URL
AutoPush = $true # Automatically push the package to the Chocolatey community repository
}
# Call the UpdateChocolateyPackage function and pass the hash table
Expand Down Expand Up @@ -284,6 +285,7 @@ pwsh -Command "& 'C:\Projects\ChocolateyPackages\fxsound\update.ps1'"
| `-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. |
| `-AutoPush` | boolean | No | Automatically performs "choco push" to push the package to the Chocolatey community repository. |
| `-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 |
Expand Down
7 changes: 4 additions & 3 deletions example-package-github-repo/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ $ParentPath = Split-Path -Parent $ScriptPath

# Create a hash table to store package information
$packageInfo = @{
PackageName = "ventoy"
FileUrl = "https://github.com/ventoy/Ventoy/releases/download/v{VERSION}/ventoy-{VERSION}-windows.zip"
GitHubRepoUrl = "https://github.com/ventoy/Ventoy"
PackageName = "ventoy" # Package name
FileUrl = "https://github.com/ventoy/Ventoy/releases/download/v{VERSION}/ventoy-{VERSION}-windows.zip" # URL to download the file from, using {VERSION} where the version number goes
GitHubRepoUrl = "https://github.com/ventoy/Ventoy" # GitHub repository URL
AutoPush = $true # Automatically push the package to the Chocolatey community repository
}

# Call the UpdateChocolateyPackage function and pass the hash table
Expand Down

0 comments on commit dc8085f

Please sign in to comment.