Merge branch 'main' of https://git.azuze.fr/kawa/Sharepoint-Toolbox
This commit is contained in:
File diff suppressed because it is too large
Load Diff
111
release.ps1
111
release.ps1
@@ -1,111 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Build, tag, and publish a release to Gitea.
|
||||
.PARAMETER Version
|
||||
Version tag (e.g. "v2.0.0"). Required.
|
||||
.PARAMETER Token
|
||||
Gitea API token. If not provided, reads from GITEA_TOKEN env var.
|
||||
.EXAMPLE
|
||||
.\release.ps1 -Version v2.0.0
|
||||
.\release.ps1 -Version v2.1.0 -Token "your_token_here"
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Version,
|
||||
[string]$Token = $env:GITEA_TOKEN
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$GiteaUrl = "https://git.azuze.fr"
|
||||
$Repo = "kawa/Sharepoint-Toolbox"
|
||||
$Project = "SharepointToolbox/SharepointToolbox.csproj"
|
||||
$PublishDir = "publish"
|
||||
$ZipName = "SharePoint_Toolbox_$Version.zip"
|
||||
|
||||
# -- Validate --
|
||||
if (-not $Token) {
|
||||
Write-Error "No token provided. Pass -Token or set GITEA_TOKEN env var."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (git tag -l $Version) {
|
||||
Write-Error "Tag $Version already exists."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# -- Build --
|
||||
Write-Host ""
|
||||
Write-Host ">> Building Release..." -ForegroundColor Cyan
|
||||
dotnet publish $Project -c Release -p:PublishSingleFile=true -o $PublishDir
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
|
||||
# -- Package --
|
||||
Write-Host ""
|
||||
Write-Host ">> Packaging $ZipName..." -ForegroundColor Cyan
|
||||
$staging = "release_staging"
|
||||
if (Test-Path $staging) { Remove-Item $staging -Recurse -Force }
|
||||
New-Item -ItemType Directory -Path $staging | Out-Null
|
||||
New-Item -ItemType Directory -Path "$staging/examples" | Out-Null
|
||||
|
||||
Copy-Item "$PublishDir/SharepointToolbox.exe" "$staging/"
|
||||
Copy-Item "SharepointToolbox/Resources/*.csv" "$staging/examples/"
|
||||
|
||||
if (Test-Path $ZipName) { Remove-Item $ZipName }
|
||||
Compress-Archive -Path "$staging/*" -DestinationPath $ZipName
|
||||
Remove-Item $staging -Recurse -Force
|
||||
|
||||
$zipSize = [math]::Round((Get-Item $ZipName).Length / 1MB, 1)
|
||||
Write-Host " Created $ZipName ($zipSize MB)" -ForegroundColor Green
|
||||
|
||||
# -- Tag and Push --
|
||||
Write-Host ""
|
||||
Write-Host ">> Tagging $Version and pushing..." -ForegroundColor Cyan
|
||||
git tag $Version
|
||||
git push kawa main --tags
|
||||
|
||||
# -- Create Release --
|
||||
Write-Host ""
|
||||
Write-Host ">> Creating Gitea release..." -ForegroundColor Cyan
|
||||
|
||||
$releaseBody = ""
|
||||
|
||||
$jsonObj = @{ tag_name = $Version; name = "SharePoint Toolbox $Version"; body = $releaseBody }
|
||||
$jsonPath = [System.IO.Path]::GetTempFileName()
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
[System.IO.File]::WriteAllText($jsonPath, ($jsonObj | ConvertTo-Json -Depth 3), $utf8NoBom)
|
||||
|
||||
$releaseJson = curl.exe -s -w "`n%{http_code}" -X POST "$GiteaUrl/api/v1/repos/$Repo/releases" -H "Authorization: token $Token" -H "Content-Type: application/json" -d "@$jsonPath"
|
||||
Remove-Item $jsonPath
|
||||
|
||||
$lines = $releaseJson -split "`n"
|
||||
$httpCode = $lines[-1]
|
||||
$responseBody = ($lines[0..($lines.Length-2)] -join "`n")
|
||||
|
||||
if ($httpCode -ne "201") {
|
||||
Write-Host " HTTP $httpCode - $responseBody" -ForegroundColor Red
|
||||
Write-Error "Release creation failed."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$releaseId = ($responseBody | ConvertFrom-Json).id
|
||||
Write-Host " Release created (ID: $releaseId)" -ForegroundColor Green
|
||||
|
||||
# -- Upload Asset --
|
||||
Write-Host ""
|
||||
Write-Host ">> Uploading $ZipName..." -ForegroundColor Cyan
|
||||
$uploadUrl = "$GiteaUrl/api/v1/repos/$Repo/releases/$releaseId/assets"
|
||||
|
||||
curl.exe -sf -X POST $uploadUrl -H "Authorization: token $Token" -F "attachment=@$ZipName" | Out-Null
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Asset upload failed."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# -- Cleanup --
|
||||
Remove-Item $ZipName
|
||||
Remove-Item $PublishDir -Recurse -Force
|
||||
|
||||
Write-Host ""
|
||||
Write-Host ">> Done! Release published at:" -ForegroundColor Green
|
||||
Write-Host " $GiteaUrl/$Repo/releases/tag/$Version" -ForegroundColor Yellow
|
||||
Reference in New Issue
Block a user