@@ -32,7 +32,11 @@ Param(
3232 # -whatif switch to not actually make changes
3333
3434 # Path to the vendor configuration source file
35- [string ]$sourcesPath = " $PSScriptRoot \..\vendor\sources.json"
35+ [string ]$sourcesPath = " $PSScriptRoot \..\vendor\sources.json" ,
36+
37+ # Include pre-release versions (RC, beta, alpha, etc.)
38+ # By default, only stable releases are considered
39+ [switch ]$IncludePrerelease = $false
3640)
3741
3842# Get the root directory of the cmder project.
@@ -79,11 +83,39 @@ function Match-Filenames {
7983 return $position
8084}
8185
86+ # Checks if a release is a pre-release based on GitHub API flag and version tag keywords
87+ # Pre-release keywords include: -rc (release candidate), -beta, -alpha, -preview, -pre
88+ function Test-IsPrerelease {
89+ param (
90+ [Parameter (Mandatory = $true )]
91+ $release
92+ )
93+
94+ # Check if marked as pre-release by GitHub
95+ if ($release.prerelease -eq $true ) {
96+ return $true
97+ }
98+
99+ # Check for common pre-release keywords in tag name
100+ # This catches versions like v2.50.0-rc, v1.0.0-beta, v1.0.0-alpha, etc.
101+ $prereleaseKeywords = @ (' -rc' , ' -beta' , ' -alpha' , ' -preview' , ' -pre' )
102+ foreach ($keyword in $prereleaseKeywords ) {
103+ if ($release.tag_name -ilike " *$keyword *" ) {
104+ return $true
105+ }
106+ }
107+
108+ return $false
109+ }
110+
82111# Uses the GitHub api in order to fetch the current download links for the latest releases of the repo.
83112function Fetch-DownloadUrl {
84113 param (
85114 [Parameter (Mandatory = $true )]
86- $urlStr
115+ $urlStr ,
116+
117+ [Parameter (Mandatory = $false )]
118+ [bool ]$includePrerelease = $false
87119 )
88120
89121 $url = [uri ] $urlStr
@@ -127,6 +159,13 @@ function Fetch-DownloadUrl {
127159 }
128160
129161 :loop foreach ($i in $info ) {
162+ # Skip pre-release versions unless explicitly included
163+ # Pre-releases include RC (Release Candidate), beta, alpha, and other test versions
164+ if (-not $includePrerelease -and (Test-IsPrerelease $i )) {
165+ Write-Verbose " Skipping pre-release version: $ ( $i.tag_name ) "
166+ continue
167+ }
168+
130169 if (-not ($i.assets -is [array ])) {
131170 continue
132171 }
@@ -164,12 +203,26 @@ function Fetch-DownloadUrl {
164203
165204 # Special case for archive downloads of repository
166205 if (($null -eq $downloadLinks ) -or (-not $downloadLinks )) {
167- if ((($p | ForEach-Object { $_.Trim (' /' ) }) -contains " archive" ) -and $info [0 ].tag_name) {
168- for ($i = 0 ; $i -lt $p.Length ; $i ++ ) {
169- if ($p [$i ].Trim(' /' ) -eq " archive" ) {
170- $p [$i + 1 ] = $info [0 ].tag_name + " .zip"
171- $downloadLinks = $url.Scheme + " ://" + $url.Host + ($p -join ' ' )
172- return $downloadLinks
206+ if ((($p | ForEach-Object { $_.Trim (' /' ) }) -contains " archive" )) {
207+ # Find the first release that matches our pre-release filtering criteria
208+ $selectedRelease = $null
209+ foreach ($release in $info ) {
210+ # Apply the same filtering logic
211+ if (-not $includePrerelease -and (Test-IsPrerelease $release )) {
212+ continue
213+ }
214+ # Use the first release that passes the filter
215+ $selectedRelease = $release
216+ break
217+ }
218+
219+ if ($selectedRelease -and $selectedRelease.tag_name ) {
220+ for ($i = 0 ; $i -lt $p.Length ; $i ++ ) {
221+ if ($p [$i ].Trim(' /' ) -eq " archive" ) {
222+ $p [$i + 1 ] = $selectedRelease.tag_name + " .zip"
223+ $downloadLinks = $url.Scheme + " ://" + $url.Host + ($p -join ' ' )
224+ return $downloadLinks
225+ }
173226 }
174227 }
175228 }
@@ -215,7 +268,7 @@ foreach ($s in $sources) {
215268
216269 Write-Verbose " Old Link: $ ( $s.url ) "
217270
218- $downloadUrl = Fetch- DownloadUrl $s.url
271+ $downloadUrl = Fetch- DownloadUrl $s.url - includePrerelease $IncludePrerelease
219272
220273 if (($null -eq $downloadUrl ) -or ($downloadUrl -eq ' ' )) {
221274 Write-Verbose " No new links were found"
0 commit comments