Deduplicate assets on upload, fix release accumulation
This commit is contained in:
@@ -65,6 +65,13 @@ jobs:
|
||||
)
|
||||
$names = @("LotusChat-x86_64-setup.exe", "LotusChat-x86_64-setup.nsis.zip", "LotusChat-x86_64-setup.nsis.zip.sig")
|
||||
for ($i = 0; $i -lt $files.Length; $i++) {
|
||||
# Delete existing asset with same name if present
|
||||
$existing = (Invoke-RestMethod -Uri "$env:GITEA_URL/api/v1/repos/$env:REPO/releases/$releaseId/assets" `
|
||||
-Headers @{ Authorization = "token $env:TOKEN" }) | Where-Object { $_.name -eq $names[$i] }
|
||||
if ($existing) {
|
||||
Invoke-RestMethod -Uri "$env:GITEA_URL/api/v1/repos/$env:REPO/releases/$releaseId/assets/$($existing.id)" `
|
||||
-Method Delete -Headers @{ Authorization = "token $env:TOKEN" }
|
||||
}
|
||||
$bytes = [System.IO.File]::ReadAllBytes($files[$i])
|
||||
Invoke-RestMethod -Uri "$env:GITEA_URL/api/v1/repos/$env:REPO/releases/$releaseId/assets?name=$($names[$i])" `
|
||||
-Method Post `
|
||||
@@ -144,6 +151,14 @@ jobs:
|
||||
"LotusChat-x86_64.AppImage.tar.gz.sig|${APPIMAGE}.tar.gz.sig"; do
|
||||
name="${file%%|*}"
|
||||
path="${file##*|}"
|
||||
# Delete existing asset with same name if present
|
||||
existing_id=$(curl -sf "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
| python3 -c "import sys,json; assets=json.load(sys.stdin); print(next((str(a['id']) for a in assets if a['name']=='$name'), ''))" 2>/dev/null || true)
|
||||
if [ -n "$existing_id" ]; then
|
||||
curl -sf -X DELETE "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets/$existing_id" \
|
||||
-H "Authorization: token $TOKEN" || true
|
||||
fi
|
||||
echo "Uploading $name"
|
||||
curl -sf -X POST \
|
||||
"$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" \
|
||||
|
||||
Reference in New Issue
Block a user