Skip to content

Commit bd4d44b

Browse files
fix(p0): clobber release assets on rerun (#31)
1 parent 67667fe commit bd4d44b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ jobs:
5757
if (-not (Test-Path artifacts/cloudsqlctl-windows-x64.zip)) { throw "Missing zip bundle" }
5858
if (-not (Test-Path artifacts/SHA256SUMS.txt)) { throw "Missing SHA256SUMS.txt" }
5959
60+
- name: Delete existing release assets (same tag)
61+
shell: pwsh
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
$tag = $env:GITHUB_REF -replace 'refs/tags/', ''
66+
$headers = @{
67+
Authorization = "Bearer $env:GITHUB_TOKEN"
68+
Accept = "application/vnd.github+json"
69+
}
70+
try {
71+
$release = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$env:GITHUB_REPOSITORY/releases/tags/$tag" -Headers $headers
72+
} catch {
73+
if ($_.Exception.Response.StatusCode.value__ -eq 404) {
74+
Write-Host "No existing release for $tag"
75+
exit 0
76+
}
77+
throw
78+
}
79+
80+
if (-not $release) {
81+
Write-Host "No existing release data for $tag"
82+
exit 0
83+
}
84+
85+
foreach ($asset in $release.assets) {
86+
Write-Host "Deleting asset $($asset.name)"
87+
Invoke-RestMethod -Method Delete -Uri "https://api.github.com/repos/$env:GITHUB_REPOSITORY/releases/assets/$($asset.id)" -Headers $headers
88+
}
89+
6090
- name: Release
6191
uses: softprops/action-gh-release@v2
6292
if: startsWith(github.ref, 'refs/tags/')

0 commit comments

Comments
 (0)