Skip to content

Conversation

@RAprogramm
Copy link
Owner

Summary

Added automated version comparison with crates.io to prevent publishing duplicate or older versions. The release workflow now checks if the local version is higher than the current crates.io version before attempting to publish.

Changes

Version Check Step

  • Fetches current version from crates.io API (/api/v1/crates/{crate}/)
  • Compares local tag version with crates.io max_version using semver sort (sort -V)
  • Sets should_publish output variable for conditional execution
  • Handles first-time publish when crate not found on crates.io

Conditional Publishing

  • All publish steps now conditional on should_publish == 'true'
  • Includes: Rust installation, template publish, derive publish, main crate publish
  • Skips all publish steps when version already exists

Version Comparison Logic

# Three scenarios:
1. LOCAL == CRATESIO  → should_publish=false, skip with message
2. LOCAL > CRATESIO   → should_publish=true, proceed
3. LOCAL < CRATESIO   → should_publish=false, fail with error

Benefits

  • Prevents Errors: No more duplicate version publish failures
  • Clear Feedback: Explicit messages for each scenario
  • Idempotent: Can re-run release workflow safely
  • Better DX: Automatic version conflict detection

Test Plan

  • Tested version comparison logic locally with various scenarios
  • Verified semver sort handles major/minor/patch correctly
  • Checked crates.io API response format
  • Workflow YAML validated
  • All existing tests pass (157 tests)

Testing Scenarios

LOCAL=0.24.18 vs CRATESIO=0.24.18 → EQUAL (skip)
LOCAL=0.24.19 vs CRATESIO=0.24.18 → HIGHER (publish)
LOCAL=0.24.17 vs CRATESIO=0.24.18 → LOWER (fail)
LOCAL=1.0.0   vs CRATESIO=0.24.18 → HIGHER (publish)

Next Steps

Workflow will be tested on next actual release tag push.

Closes #193

Prevent publishing versions that are equal to or lower than current crates.io version.

Changes:
- Add version check step that fetches current version from crates.io API
- Compare local tag version with crates.io version using semver sort
- Skip publish steps if version is equal or lower
- Fail workflow if attempting to publish older version
- Support first-time publish when crate not found on crates.io

Version comparison logic:
- Uses crates.io API endpoint to fetch max_version
- Implements semver comparison via sort -V
- Sets should_publish output variable for conditional execution
- All publish steps now conditional on version check result

Benefits:
- Prevents duplicate version publish errors
- Clear feedback on version conflicts
- Automatic skip for already-published versions
- Better developer experience with explicit version messages
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Replace sort -V with proper semver comparison using Rust semver crate.

Changes:
- Create temporary Rust project with semver dependency
- Use semver::Version::parse() for accurate version comparison
- Handle prerelease versions correctly (1.0.0 > 1.0.0-alpha)
- Proper comparison for all semver scenarios

Fixes:
- P1 issue: sort -V incorrectly orders prerelease versions
- Now correctly handles: stable vs prerelease, prerelease ordering
- Prevents publishing older versions in all cases

Testing:
- 1.0.0 > 1.0.0-alpha ✓
- 1.0.0-beta > 1.0.0-alpha ✓
- 0.24.19 > 0.24.18 ✓
@RAprogramm
Copy link
Owner Author

Fixed in commit f048f5a.

Replaced sort -V with proper semver comparison using Rust semver crate. The version check now:

  1. Creates temporary Rust project with semver = "1.0" dependency
  2. Uses semver::Version::parse() for accurate parsing
  3. Compares versions with proper prerelease handling

Correctly handles:

  • 1.0.0 > 1.0.0-alpha
  • 1.0.0-beta > 1.0.0-alpha
  • All stable version comparisons ✓

Tested scenarios:

0.24.19 vs 0.24.18: greater
0.24.18 vs 0.24.18: equal
0.24.17 vs 0.24.18: less
1.0.0 vs 1.0.0-alpha: greater
1.0.0-alpha vs 1.0.0: less
1.0.0-beta vs 1.0.0-alpha: greater

This eliminates the prerelease ordering issues mentioned in the P1 review.

@RAprogramm RAprogramm merged commit 1242ffa into main Oct 12, 2025
15 checks passed
@RAprogramm RAprogramm deleted the 193 branch October 12, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add version comparison with crates.io before publishing

2 participants