ci(release): skip duplicate Gitea release creation
- check tag existence on origin via ls-remote - stop workflow when release for tag already exists
This commit is contained in:
@@ -53,7 +53,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
$version = "${{ steps.extract_version.outputs.version }}"
|
$version = "${{ steps.extract_version.outputs.version }}"
|
||||||
$tag = "v$version"
|
$tag = "v$version"
|
||||||
git show-ref --tags --quiet --verify "refs/tags/$tag"
|
git ls-remote --tags origin "refs/tags/$tag" | Out-Null
|
||||||
$tagExists = ($LASTEXITCODE -eq 0)
|
$tagExists = ($LASTEXITCODE -eq 0)
|
||||||
$global:LASTEXITCODE = 0
|
$global:LASTEXITCODE = 0
|
||||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||||
@@ -66,6 +66,25 @@ jobs:
|
|||||||
}
|
}
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
- name: Stop if release already exists
|
||||||
|
if: env.CONTINUE == 'true'
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
$version = "${{ steps.extract_version.outputs.version }}"
|
||||||
|
$tag = "v$version"
|
||||||
|
$apiUrl = "https://git.daemonlord.ru/api/v1/repos/${{ gitea.repository }}/releases/tags/$tag"
|
||||||
|
$headers = @{ Authorization = "token ${{ secrets.API_TOKEN }}" }
|
||||||
|
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||||
|
try {
|
||||||
|
$response = Invoke-WebRequest -Uri $apiUrl -Headers $headers -Method Get -UseBasicParsing
|
||||||
|
if ($response.StatusCode -eq 200) {
|
||||||
|
Write-Host "Release $tag already exists, stopping job."
|
||||||
|
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "CONTINUE=false`n", $utf8NoBom)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host "Release $tag not found, continuing workflow..."
|
||||||
|
}
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
if: env.CONTINUE == 'true'
|
if: env.CONTINUE == 'true'
|
||||||
shell: powershell
|
shell: powershell
|
||||||
|
|||||||
Reference in New Issue
Block a user