Skip to content

Commit ed39fe3

Browse files
authored
ci: check if the release is not already published before attempting to publish it (#600)
1 parent ac13f2b commit ed39fe3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

DubUrl.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{95E83BA6
1414
appveyor.yml = appveyor.yml
1515
Directory.Build.props = Directory.Build.props
1616
Directory.Build.targets = Directory.Build.targets
17+
github.ps1 = github.ps1
1718
GitVersion.yml = GitVersion.yml
18-
github-actions.ps1 = github-actions.ps1
1919
EndProjectSection
2020
EndProject
2121
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project", "Project", "{09BDFA96-353F-419D-890A-D9B9045E66DD}"

appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ on_success:
9090
Owner = ($env:APPVEYOR_REPO_NAME -Split '/')[0]
9191
Repository = ($env:APPVEYOR_REPO_NAME -Split '/')[1]
9292
SecretToken = $env:github_access_token
93-
} | Publish-Release `
93+
}
94+
if ( -not ($context | Check-Release-Published -Tag "v$($env:GitVersion_SemVer)")) {
95+
$context | Publish-Release `
9496
-Tag "v$($env:GitVersion_SemVer)" `
9597
-Name "$(($env:APPVEYOR_REPO_NAME -Split '/')[1]) $($env:GitVersion_SemVer)" `
9698
-ReleaseNotes `
9799
-DiscussionCategory 'Announcements'
100+
}
98101
} else {
99102
Write-Host "No release published on GitHub."
100103
}

github.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ function Get-Commit-Associated-Pull-Requests {
9191
return ($response.Content | ConvertFrom-Json).number
9292
}
9393

94+
function Check-Release-Published {
95+
[CmdletBinding()]
96+
Param(
97+
[Parameter(Mandatory=$true, ValueFromPipeline = $true, Position=0 )]
98+
[object] $context,
99+
[Parameter(Mandatory=$true)]
100+
[string] $tag
101+
)
102+
$response = Send-GitHub-Get-Request `
103+
-Owner $context.Owner `
104+
-Repository $context.Repository `
105+
-Segments @('releases') `
106+
-Headers $($context.SecretToken | Get-GitHub-Headers)
107+
$existing = ($response.Content | ConvertFrom-Json) `
108+
| ? {$_.tag_name -eq $tag}`
109+
| Select-Object -Unique -ExpandProperty 'published_at'
110+
if ($existing) {
111+
Write-Host "Release already published at $existing"
112+
return $true
113+
}
114+
return $false
115+
}
116+
94117
function Post-Pull-Request-Labels {
95118
[CmdletBinding()]
96119
Param(

0 commit comments

Comments
 (0)