-
Notifications
You must be signed in to change notification settings - Fork 0
Add release script wrapping cargo release #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/usr/bin/env bash | ||
| # release.sh — two-phase release wrapper around cargo-release | ||
| # | ||
| # Usage: | ||
| # scripts/release.sh prepare <version> # steps 0-2: branch, bump, push PR | ||
| # scripts/release.sh finish # step 4: tag, publish, trigger dist | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| COMMAND="${1:-}" | ||
| VERSION="${2:-}" | ||
|
|
||
| usage() { | ||
| echo "Usage:" | ||
| echo " scripts/release.sh prepare <version> # create release branch and open PR" | ||
| echo " scripts/release.sh finish # tag and publish from main" | ||
| exit 1 | ||
| } | ||
|
|
||
| require_clean_tree() { | ||
| if ! git diff --quiet || ! git diff --cached --quiet; then | ||
| echo "error: working tree is not clean. Commit or stash your changes first." | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| case "$COMMAND" in | ||
| prepare) | ||
| if [ -z "$VERSION" ]; then | ||
| echo "error: version required (e.g. scripts/release.sh prepare 0.2.0)" | ||
| usage | ||
| fi | ||
|
|
||
| BRANCH="release/$VERSION" | ||
|
|
||
| require_clean_tree | ||
|
|
||
| # step 0: create release branch | ||
| echo "→ Creating branch $BRANCH" | ||
| git checkout -b "$BRANCH" | ||
|
|
||
| # step 2: bump versions, commit, push branch | ||
| echo "" | ||
| echo "→ Running cargo release (no publish, no tag)..." | ||
| cargo release --no-publish --no-tag --allow-branch="$BRANCH" "$VERSION" | ||
|
|
||
| echo "" | ||
| echo "→ Opening pull request..." | ||
| PR_URL=$(gh pr create \ | ||
| --title "chore: Release hotdata-cli version $VERSION" \ | ||
| --base main \ | ||
| --head "$BRANCH") | ||
|
|
||
| echo "" | ||
| echo "✓ PR created: $PR_URL" | ||
| if command -v xdg-open &>/dev/null; then | ||
| xdg-open "$PR_URL" || true | ||
| elif command -v open &>/dev/null; then | ||
| open "$PR_URL" || true | ||
| fi | ||
| echo "" | ||
| echo "Next steps:" | ||
| echo " 1. Review and merge the PR (use 'Squash and merge')" | ||
| echo " 2. Run: scripts/release.sh finish" | ||
| ;; | ||
|
|
||
| finish) | ||
| require_clean_tree | ||
|
|
||
| CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" | ||
| if [ "$CURRENT_BRANCH" != "main" ]; then | ||
| echo "→ Switching to main..." | ||
| git checkout main | ||
| fi | ||
|
|
||
| echo "→ Pulling latest main..." | ||
| git pull | ||
|
|
||
| echo "" | ||
| echo "→ Running cargo release (tagging release)..." | ||
| cargo release | ||
|
|
||
| echo "" | ||
| echo "✓ Release complete. Tag pushed and dist workflow triggered." | ||
| ;; | ||
|
|
||
| *) | ||
| usage | ||
| ;; | ||
| esac | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,14 +118,21 @@ fn do_upload<R: std::io::Read + Send + 'static>( | |||||||||||||||
| content_type: &str, | ||||||||||||||||
| reader: R, | ||||||||||||||||
| pb: ProgressBar, | ||||||||||||||||
| content_length: Option<u64>, | ||||||||||||||||
| ) -> String { | ||||||||||||||||
| let url = format!("{api_url}/files"); | ||||||||||||||||
|
|
||||||||||||||||
| let resp = match client | ||||||||||||||||
| let mut req = client | ||||||||||||||||
| .post(&url) | ||||||||||||||||
| .header("Authorization", format!("Bearer {api_key}")) | ||||||||||||||||
| .header("X-Workspace-Id", workspace_id) | ||||||||||||||||
| .header("Content-Type", content_type) | ||||||||||||||||
| .header("Content-Type", content_type); | ||||||||||||||||
|
|
||||||||||||||||
| if let Some(len) = content_length { | ||||||||||||||||
| req = req.header("Content-Length", len); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| let resp = match req | ||||||||||||||||
| .body(reqwest::blocking::Body::new(reader)) | ||||||||||||||||
| .send() | ||||||||||||||||
| { | ||||||||||||||||
|
|
@@ -190,7 +197,7 @@ fn upload_from_file( | |||||||||||||||
| let pb = make_progress_bar(file_size); | ||||||||||||||||
| let reader = pb.wrap_read(f); | ||||||||||||||||
|
|
||||||||||||||||
| let id = do_upload(client, api_key, workspace_id, api_url, ft.content_type, reader, pb); | ||||||||||||||||
| let id = do_upload(client, api_key, workspace_id, api_url, ft.content_type, reader, pb, Some(file_size)); | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Consider computing the optional length separately so metadata failure means "omit the header" rather than "send 0":
Suggested change
Non-blocking — metadata failure on an already-opened file is rare in practice. |
||||||||||||||||
| (id, ft.format) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -216,7 +223,7 @@ fn upload_from_stdin( | |||||||||||||||
| pb.enable_steady_tick(std::time::Duration::from_millis(80)); | ||||||||||||||||
| let reader = pb.wrap_read(reader); | ||||||||||||||||
|
|
||||||||||||||||
| let id = do_upload(client, api_key, workspace_id, api_url, ft.content_type, reader, pb); | ||||||||||||||||
| let id = do_upload(client, api_key, workspace_id, api_url, ft.content_type, reader, pb, None); | ||||||||||||||||
| (id, ft.format) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider calling
require_clean_treebefore checking out the new branch.cargo releasewill modifyCargo.toml/CHANGELOG.md, so starting from a dirty tree can produce confusing diffs or cause cargo-release to abort mid-run.