|
| 1 | +param( |
| 2 | + [Parameter(Mandatory=$true)] |
| 3 | + [string]$Tag, |
| 4 | + |
| 5 | + [Parameter(Mandatory=$true)] |
| 6 | + [string]$Repository |
| 7 | +) |
| 8 | + |
| 9 | +function Write-GitHubActionsCommand { |
| 10 | + param( |
| 11 | + [Parameter(Mandatory=$true)] |
| 12 | + [string]$Command, |
| 13 | + |
| 14 | + [Parameter(Mandatory=$true)] |
| 15 | + [string]$Message, |
| 16 | + |
| 17 | + [Parameter(Mandatory=$true)] |
| 18 | + [string]$Title |
| 19 | + ) |
| 20 | + |
| 21 | + Write-Host "::$Command title=$Title::$Message" |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +function Write-GitHubActionsWarning { |
| 26 | + param( |
| 27 | + [Parameter(Mandatory=$true)] |
| 28 | + [string]$Message, |
| 29 | + |
| 30 | + [Parameter(Mandatory=$false)] |
| 31 | + [string]$Title = "Warning" |
| 32 | + ) |
| 33 | + |
| 34 | + if ($env:GITHUB_ACTIONS -eq "true") { |
| 35 | + Write-GitHubActionsCommand -Command "warning" -Message $Message -Title $Title |
| 36 | + } else { |
| 37 | + Write-Host "! Warning: $Message" -ForegroundColor Yellow |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +function Write-GitHubActionsError { |
| 42 | + param( |
| 43 | + [Parameter(Mandatory=$true)] |
| 44 | + [string]$Message, |
| 45 | + |
| 46 | + [Parameter(Mandatory=$false)] |
| 47 | + [string]$Title = "Error" |
| 48 | + ) |
| 49 | + |
| 50 | + if ($env:GITHUB_ACTIONS -eq "true") { |
| 51 | + Write-GitHubActionsCommand -Command "error" -Message $Message -Title $Title |
| 52 | + } else { |
| 53 | + Write-Host "x Error: $Message" -ForegroundColor Red |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +if ([string]::IsNullOrWhiteSpace($Tag)) { |
| 58 | + Write-GitHubActionsError -Message "Tag parameter is required" |
| 59 | + exit 1 |
| 60 | +} |
| 61 | + |
| 62 | +if ([string]::IsNullOrWhiteSpace($Repository)) { |
| 63 | + Write-GitHubActionsError -Message "Repository parameter is required" |
| 64 | + exit 1 |
| 65 | +} |
| 66 | + |
| 67 | +Write-Host "Validating $Repository release '$Tag'..." |
| 68 | + |
| 69 | +# Prepare headers for GitHub API |
| 70 | +$headers = @{ |
| 71 | + 'Accept' = 'application/vnd.github.v3+json' |
| 72 | + 'User-Agent' = 'VFSForGit-Build' |
| 73 | +} |
| 74 | + |
| 75 | +if ($env:GITHUB_TOKEN) { |
| 76 | + $headers['Authorization'] = "Bearer $env:GITHUB_TOKEN" |
| 77 | +} |
| 78 | + |
| 79 | +# Check if the tag exists in microsoft/git repository |
| 80 | +try { |
| 81 | + $releaseResponse = Invoke-RestMethod ` |
| 82 | + -Uri "https://api.github.com/repos/$Repository/releases/tags/$Tag" ` |
| 83 | + -Headers $headers |
| 84 | + |
| 85 | + Write-Host "✓ Tag '$Tag' found in $Repository" -ForegroundColor Green |
| 86 | + Write-Host " Release : $($releaseResponse.name)" |
| 87 | + Write-Host " Published : $($releaseResponse.published_at.ToString('u'))" |
| 88 | + |
| 89 | + # Check if this a pre-release |
| 90 | + if ($releaseResponse.prerelease -eq $true) { |
| 91 | + Write-GitHubActionsWarning ` |
| 92 | + -Message "Using a pre-released version of $Repository" ` |
| 93 | + -Title "Pre-release $Repository version" |
| 94 | + } |
| 95 | + |
| 96 | + # Get the latest release for comparison |
| 97 | + try { |
| 98 | + $latestResponse = Invoke-RestMethod ` |
| 99 | + -Uri "https://api.github.com/repos/$Repository/releases/latest" ` |
| 100 | + -Headers $headers |
| 101 | + $latestTag = $latestResponse.tag_name |
| 102 | + |
| 103 | + # Check if this is the latest release |
| 104 | + if ($Tag -eq $latestTag) { |
| 105 | + Write-Host "✓ Using the latest release" -ForegroundColor Green |
| 106 | + exit 0 |
| 107 | + } |
| 108 | + |
| 109 | + # Not the latest! |
| 110 | + $warningTitle = "Outdated $Repository release" |
| 111 | + $warningMsg = "Not using latest release of $Repository (latest: $latestTag)" |
| 112 | + Write-GitHubActionsWarning -Message $warningMsg -Title $warningTitle |
| 113 | + } catch { |
| 114 | + Write-GitHubActionsWarning -Message "Could not check latest release info for ${Repository}: $($_.Exception.Message)" |
| 115 | + } |
| 116 | +} catch { |
| 117 | + if ($_.Exception.Response.StatusCode -eq 404) { |
| 118 | + Write-GitHubActionsError -Message "Tag '$Tag' does not exist in $Repository" |
| 119 | + exit 1 |
| 120 | + } else { |
| 121 | + Write-GitHubActionsError -Message "Error validating release '$Tag': $($_.Exception.Message)" |
| 122 | + exit 1 |
| 123 | + } |
| 124 | +} |
0 commit comments