Skip to content

Commit 3c72508

Browse files
committed
Harden release workflow to use better runs
1 parent 2106ee9 commit 3c72508

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,30 @@ jobs:
4040
4141
Write-Host "Resolved ${{ github.ref_name }} to $commitSha"
4242
43-
$releases = gh run list -R ${{ github.repository }} -c $commitSha -w .github/workflows/build.yml -s success --json databaseId,startedAt `
43+
$releases = gh run list -R ${{ github.repository }} -c $commitSha -w .github/workflows/build.yml -s success --json databaseId,startedAt,event,headBranch `
4444
| ConvertFrom-Json | Sort-Object startedAt -Descending
4545
46+
$preferredReleases = $releases | Where-Object {
47+
$_.event -eq 'push' -and ($_.headBranch -eq 'main' -or $_.headBranch -match '^v\d+(?:\.\d+)?$')
48+
}
49+
4650
if ($releases.length -eq 0) {
4751
Write-Error "No successful builds found for ${{ github.ref }}."
48-
} elseif ($releases.length -gt 1) {
49-
Write-Warning "More than one successful run found for ${{ github.ref }}. Artifacts from the most recent successful run will ship."
50-
}
52+
} else {
53+
if ($preferredReleases.length -gt 0) {
54+
$selectedReleases = $preferredReleases
55+
$multipleRunsWarning = "More than one successful run found for ${{ github.ref }}. Preferring the most recent push build from a public-release branch."
56+
} else {
57+
$selectedReleases = $releases
58+
$multipleRunsWarning = "More than one successful run found for ${{ github.ref }} and none were from a public-release branch. Artifacts from the most recent successful run will ship."
59+
}
5160
52-
$runid = $releases[0].databaseId
61+
if ($releases.length -gt 1) {
62+
Write-Warning $multipleRunsWarning
63+
}
64+
65+
$runid = $selectedReleases[0].databaseId
66+
}
5367
}
5468
5569
Write-Host "Using artifacts from run-id: $runid"

0 commit comments

Comments
 (0)