@@ -59,6 +59,32 @@ Function Cleanup() {
5959 New-Item - Path $cache_dir - ItemType " directory"
6060}
6161
62+ Function Get-LatestGitTag () {
63+ param (
64+ [Parameter (Position = 0 , Mandatory = $true )]
65+ [ValidateNotNull ()]
66+ [ValidateLength (1 , [int ]::MaxValue)]
67+ [string ]
68+ $repo
69+ )
70+ $lsRemoteOutput = git ls- remote -- tags $repo 2>&1
71+ $versionTags = @ ()
72+ foreach ($line in $lsRemoteOutput -split " `n " ) {
73+ $line = $line.Trim ()
74+ if (-not $line ) { continue }
75+ $match = [regex ]::Match($line , ' \d+\.\d+(?:\.\d+)?(?:\.\d+)?' )
76+ if ($match.Success ) {
77+ $versionObj = [version ]$match.Value
78+ $versionTags += [PSCustomObject ]@ {
79+ Tag = $match.Value
80+ Version = $versionObj
81+ }
82+ }
83+ }
84+
85+ return ($versionTags | Sort-Object Version - Descending | Select-Object - First 1 ).Tag
86+ }
87+
6288Function Get-Extension () {
6389 if ($repo -like " *pecl.php.net*" ) {
6490 if ($branch -eq ' latest' ) {
@@ -76,8 +102,11 @@ Function Get-Extension() {
76102 Copy-Item - Path " $ext_dir \$extension -$branch \*" - Destination $ext_dir - Recurse - Force
77103 Remove-Item - Path " $ext_dir \$extension -$branch " - Recurse - Force
78104 (Get-Content $ext_dir \config.w32) -replace ' /sdl' , ' ' | Set-Content $ext_dir \config.w32
79- } else {
105+ } else {
80106 if ($php -ne $nightly_version ) {
107+ if ($branch -eq ' latest_stable_tag' ) {
108+ $branch = Get-LatestGitTag $github / $repo.git
109+ }
81110 git clone -- branch= $branch $github / $repo.git $ext_dir
82111 } else {
83112 git clone -- branch= $dev_branch $github / $repo.git $ext_dir
0 commit comments