Merge branch 'main' of https://git.azuze.fr/kawa/Sharepoint-Toolbox
Cleaned the repo
This commit is contained in:
94
release.ps1
94
release.ps1
@@ -1,19 +1,10 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Build, tag, and publish a release to Gitea.
|
||||
|
||||
.DESCRIPTION
|
||||
1. Builds a self-contained single-file EXE
|
||||
2. Packages it with example CSVs into a zip
|
||||
3. Creates a git tag and pushes it
|
||||
4. Creates a Gitea Release and uploads the zip
|
||||
|
||||
.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"
|
||||
@@ -31,7 +22,7 @@ $Project = "SharepointToolbox/SharepointToolbox.csproj"
|
||||
$PublishDir = "publish"
|
||||
$ZipName = "SharePoint_Toolbox_$Version.zip"
|
||||
|
||||
# ── Validate ──────────────────────────────────────────────────────────────────
|
||||
# -- Validate --
|
||||
if (-not $Token) {
|
||||
Write-Error "No token provided. Pass -Token or set GITEA_TOKEN env var."
|
||||
exit 1
|
||||
@@ -42,13 +33,15 @@ if (git tag -l $Version) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ── Build ─────────────────────────────────────────────────────────────────────
|
||||
Write-Host "`n>> Building Release..." -ForegroundColor Cyan
|
||||
# -- 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 "`n>> Packaging $ZipName..." -ForegroundColor Cyan
|
||||
# -- 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
|
||||
@@ -64,62 +57,55 @@ Remove-Item $staging -Recurse -Force
|
||||
$zipSize = [math]::Round((Get-Item $ZipName).Length / 1MB, 1)
|
||||
Write-Host " Created $ZipName ($zipSize MB)" -ForegroundColor Green
|
||||
|
||||
# ── Tag & Push ────────────────────────────────────────────────────────────────
|
||||
Write-Host "`n>> Tagging $Version and pushing..." -ForegroundColor Cyan
|
||||
# -- 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 "`n>> Creating Gitea release..." -ForegroundColor Cyan
|
||||
$headers = @{
|
||||
"Authorization" = "token $Token"
|
||||
"Content-Type" = "application/json"
|
||||
# -- 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
|
||||
}
|
||||
|
||||
$body = @{
|
||||
tag_name = $Version
|
||||
name = "SharePoint Toolbox $Version"
|
||||
body = @"
|
||||
## Installation
|
||||
|
||||
1. Download **$ZipName** below
|
||||
2. Extract the archive
|
||||
3. Launch **SharepointToolbox.exe** (requires .NET 10 runtime)
|
||||
|
||||
## Included
|
||||
|
||||
- ``SharepointToolbox.exe`` — desktop application
|
||||
- ``examples/`` — sample CSV templates for bulk operations
|
||||
"@
|
||||
} | ConvertTo-Json -Compress
|
||||
|
||||
$release = Invoke-RestMethod `
|
||||
-Uri "$GiteaUrl/api/v1/repos/$Repo/releases" `
|
||||
-Method Post `
|
||||
-Headers $headers `
|
||||
-Body $body
|
||||
|
||||
$releaseId = $release.id
|
||||
$releaseId = ($responseBody | ConvertFrom-Json).id
|
||||
Write-Host " Release created (ID: $releaseId)" -ForegroundColor Green
|
||||
|
||||
# ── Upload Asset ──────────────────────────────────────────────────────────────
|
||||
Write-Host "`n>> Uploading $ZipName..." -ForegroundColor Cyan
|
||||
# -- Upload Asset --
|
||||
Write-Host ""
|
||||
Write-Host ">> Uploading $ZipName..." -ForegroundColor Cyan
|
||||
$uploadUrl = "$GiteaUrl/api/v1/repos/$Repo/releases/$releaseId/assets"
|
||||
|
||||
# Use curl for multipart upload (Invoke-RestMethod multipart is clunky)
|
||||
curl.exe -sf `
|
||||
-X POST $uploadUrl `
|
||||
-H "Authorization: token $Token" `
|
||||
-F "attachment=@$ZipName" | Out-Null
|
||||
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 ───────────────────────────────────────────────────────────────────
|
||||
# -- Cleanup --
|
||||
Remove-Item $ZipName
|
||||
Remove-Item $PublishDir -Recurse -Force
|
||||
|
||||
Write-Host "`n>> Done! Release published at:" -ForegroundColor Green
|
||||
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