fix: mark pre-release versions correctly on GitHub releases - #32
fix: mark pre-release versions correctly on GitHub releases#32ThetaSinner wants to merge 1 commit into
Conversation
Pre-release versions are now created as pre-releases on GitHub and are never marked as the latest release. Other versions are only marked as the latest release when they are higher than the version of the current latest release. This stops a patch release from a release branch, such as v0.3.7, from replacing a newer release, such as v0.4.2, as the latest release. GitHub would otherwise mark every new release as the latest one, regardless of its version. Also check the exit status of the GitHub CLI when creating a release, which was previously ignored so that a failed release creation was reported as a successful release.
|
✔️ 2000db2 - Conventional commits check succeeded. |
WalkthroughRelease publishing now parses semver release tags, including optional 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/release_util/src/publish_release.rs`:
- Around line 124-158: Update get_latest_release_tag to capture stderr and
distinguish an absent release from other gh release view failures. Return
Ok(None) only when the command failure indicates no releases exist; otherwise
propagate a descriptive error containing the command failure details, preserving
successful JSON parsing and tag extraction.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 553ac20c-1013-4ba2-a4e9-00908f7f49a2
📒 Files selected for processing (2)
README.mdcrates/release_util/src/publish_release.rs
| /// Get the tag of the repository's current latest release, if it has one. | ||
| /// | ||
| /// Pre-releases and drafts are never the latest release, so they are not considered here. | ||
| fn get_latest_release_tag(dir: impl AsRef<Path>) -> anyhow::Result<Option<String>> { | ||
| let output = std::process::Command::new("gh") | ||
| .current_dir(dir) | ||
| .arg("release") | ||
| .arg("view") | ||
| .arg("--json") | ||
| .arg("tagName") | ||
| .stdout(std::process::Stdio::piped()) | ||
| .stderr(std::process::Stdio::inherit()) | ||
| .output() | ||
| .context("Failed to run `gh release view`")?; | ||
|
|
||
| // The command fails when the repository has no releases yet, which is not an error here. | ||
| if !output.status.success() { | ||
| println!("No current latest release found, this release will become the latest."); | ||
| return Ok(None); | ||
| } | ||
|
|
||
| let value = serde_json::from_slice::<serde_json::Value>(&output.stdout) | ||
| .context("Failed to parse `gh release view` output")?; | ||
|
|
||
| Ok(Some( | ||
| value | ||
| .as_object() | ||
| .context("Expected a JSON object as release view output")? | ||
| .get("tagName") | ||
| .context("Missing 'tagName' in release data")? | ||
| .as_str() | ||
| .context("Expected the tag name to be a string")? | ||
| .to_string(), | ||
| )) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Files:\n'
git ls-files | rg 'crates/release_util/src/publish_release\.rs|Cargo\.toml|README|gh|release' | head -200 || true
printf '\nRelevant function and callers:\n'
wc -l crates/release_util/src/publish_release.rs
sed -n '1,230p' crates/release_util/src/publish_release.rs
printf '\nSearch for should_be_latest_release references:\n'
rg -n "should_be_latest_release|get_latest_release_tag|release view|latest release" -S .Repository: holochain/release-integration
Length of output: 11597
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect gh installation/version if available without running repo code.
if command -v gh >/dev/null 2>&1; then
printf 'gh path:\n'
command -v gh
printf '\ngh version:\n'
gh version
printf '\ngh help release view relevant output:\n'
gh help release view | sed -n '1,220p'
else
printf 'gh not installed in sandbox\n'
fiRepository: holochain/release-integration
Length of output: 1478
🌐 Web query:
GitHub CLI gh release view no release error exit code message
💡 Result:
When the GitHub CLI (gh) command gh release view fails to find a specified release (or the latest release), it exits with exit code 1 [1][2]. The specific error message typically displayed is: release not found [3][2] In accordance with general GitHub CLI conventions, any command failure, including this "not found" scenario, results in an exit code of 1 [4][5]. Because this is a standard error behavior, it is generally recommended to avoid relying on brittle string matching of the error message in scripts [6]. Instead, checking the command's exit code is the standard way to handle such failures [6]. For example, you can handle this condition in a shell script as follows: if! gh release view "$TAG" > /dev/null 2>&1; then echo "Release $TAG does not exist." fi If you specifically need to distinguish between a "not found" error and other potential errors (such as network issues or authentication failures), you would currently need to inspect the stderr output, though this is discouraged as the exact message is subject to change [1][6].
Citations:
- 1: Document exit codes for
gh releasecli/cli#6024 - 2: https://stackoverflow.com/questions/73780525/release-not-found-by-github-cli-when-attempting-to-download-a-named-release-by
- 3: fix error for ErrReleaseNotFound when fetching ref cli/cli#11451
- 4: https://cli.github.com/manual/gh_help_exit-codes
- 5: Document exit codes used by gh cli/cli#6081
- 6:
gh release delete --ignore-if-not-foundcli/cli#6964
🌐 Web query:
GitHub CLI gh release view prerelease draft exit code "release not found"
💡 Result:
When the GitHub CLI (gh) fails to find a specified release, it typically exits with exit code 1 [1][2][3]. Key details regarding this behavior and potential causes: Exit Code 1: Like most gh commands, gh release view returns 1 when it encounters an error, including when the requested release tag cannot be found [1][3][4]. API Inconsistency (Replication Lag): Even if a release exists (such as a draft or a recently created release), gh may return a "release not found" error if the command is executed immediately after the release is created [5][6]. This occurs because of transient replication lag between the GitHub APIs (e.g., GraphQL vs. REST) [5]. To resolve this, it is common practice to implement a retry mechanism with exponential backoff or add a short sleep (e.g., 2-3 seconds) after the release creation command [5][6]. Prereleases and Drafts: - Prereleases: If you run gh release view without arguments, it defaults to the "latest" release [7]. Because GitHub does not consider prereleases to be the "latest" release, the command will fail to find them unless you explicitly provide the specific tag name [7]. - Drafts: Similarly, draft releases are not "latest" and must be referenced by their specific tag name [7]. Troubleshooting: - Ensure you are providing the correct Git tag name, not a display name, as the identifier for the command [2]. - If you are running this in an automated workflow immediately after creating a release, use a retry loop that checks for success and handles "not found" errors by waiting [6]. Top Results: [1][3][5][6]
Citations:
- 1: Document exit codes for
gh releasecli/cli#6024 - 2: https://stackoverflow.com/questions/73780525/release-not-found-by-github-cli-when-attempting-to-download-a-named-release-by
- 3: https://cli.github.com/manual/gh_help_exit-codes
- 4: https://www.mankier.com/1/gh-release
- 5: Uploading an artificat to a draft release doesn't work (not found) cli/cli#6198
- 6: Harden release workflow with retry/backoff for release ID resolution github/gh-aw#31236
- 7: Does "gh release view/download" fail if there are only prerelease releases available? cli/cli#5131
Distinguish not-found from gh release view failures.
gh release view returns 1 for missing releases, but it also returns non-zero for transient/other failures, and every such failure currently returns None to should_be_latest_release. That can make an older release appear newer and be created as latest via --latest=false. Capture stderr so only the intentional “no latest release” cases are converted to None, and let auth/network/type errors fail clearly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/release_util/src/publish_release.rs` around lines 124 - 158, Update
get_latest_release_tag to capture stderr and distinguish an absent release from
other gh release view failures. Return Ok(None) only when the command failure
indicates no releases exist; otherwise propagate a descriptive error containing
the command failure details, preserving successful JSON parsing and tag
extraction.
Summary
v0.5.0-dev.0, are now created as pre-releases on GitHub and are never marked as the latest release.v0.3.7, from replacing a newer release, such asv0.4.2, as the latest release. GitHub marks every new release as the latest one by default, regardless of its version, so this needs to be requested explicitly.Notes
ghinvocation itself has no automated coverage, since the integration tests run against Gitea and skip GitHub release creation.gh release create --helpand the REST API documentation formake_latest.