You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Skips waiting for the release run. The tag is still pushed, but nothing confirms a package
# reached nuget.org; use it only if you are checking the run yourself.
[switch]$SkipPublishVerification
)
$InformationPreference='Continue'
# Ensure we are on the main branch
$branch= git rev-parse --abbrev-ref HEAD
if ($branch-ne'main') {
Write-Error"Not on main branch. Current branch: $branch"
exit1
}
# Ensure working tree is clean
$status= git status --porcelain
if ($status) {
Write-Error"Working tree is not clean."
exit1
}
# Ensure we are up to date with origin
git fetch origin main --quiet
$behind= git rev-list --count HEAD..origin/main
if ($behind-gt0) {
Write-Error"Local branch is behind origin/main by $behind commit(s)."
exit1
}
# Checked before anything is pushed, because pushing the tag is the step that cannot be taken back.
# Without the GitHub CLI there is no way to confirm the release run succeeded, and an unverified
# publish is how repositories end up months behind their newest tag with nobody noticing.
if (-not$SkipPublishVerification) {
$gh=Get-Command gh -ErrorAction SilentlyContinue
if (-not$gh) {
Write-Error"The GitHub CLI (gh) is required to verify that the package publishes. Install it from https://cli.github.com, or re-run with -SkipPublishVerification to publish without verification."
exit1
}
# This only reads the stored login. The "status" subcommand makes an API call instead, so a GitHub
# rate limit makes it report "The token in keyring is invalid" for a perfectly good login.
gh auth token 2>&1|Out-Null
if ($LASTEXITCODE-ne0) {
Write-Error"The GitHub CLI has no stored login. Run 'gh auth login', or re-run with -SkipPublishVerification to publish without verification."
exit1
}
}
# Get version from Nerdbank.GitVersioning via the project's MSBuild targets (the
# referenced NuGet package), so this does not depend on the global 'nbgv' CLI tool
# being installed or on PATH.
#
# Only projects git tracks in this checkout are considered. A recursive file search also walks
# git-ignored folders such as .claude/worktrees/, where each agent worktree holds a full checkout
# on its own branch: versioning one of those yields a version that is not a public release.
Write-Information"Waiting for the release run for $version..."
# The run takes a few seconds to appear after the tag push.
$runId=$null
for ($attempt=1; $attempt-le12-and-not$runId; $attempt++) {
Start-Sleep-Seconds 5
# A tag push can start several workflows; only the release workflow's run is the one to watch.
$runListJson= gh run list --repo $repoFullName--workflow ci.yml --branch $version--limit 1--json databaseId 2>$null
if ($LASTEXITCODE-eq0-and$runListJson) {
$runList=$runListJson|ConvertFrom-Json
if ($runList.Count-gt0) { $runId=$runList[0].databaseId }
}
}
if (-not$runId) {
Write-Error"Tag $version was pushed but no run appeared for it. Check https://github.com/$repoFullName/actions: the workflow may not trigger on tags, or GitHub may be rate-limiting the lookups."