Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 12, 2025

Implementation Plan for semver sort Subcommand

  • Create src/commands/sort.ts with the sort command implementation
    • Accept variadic versions as arguments (e.g., semver sort 2.0.0 1.0.0 3.0.0)
    • Support --asc / -a flag for ascending sort
    • Default to descending sort (highest to lowest)
    • Support -- flag to read versions from stdin
    • Use Deno std semver library's comparison functions for sorting
    • Output sorted versions one per line
    • Support space-separated versions in single string arguments
  • Create src/commands/sort.test.ts with comprehensive test coverage
    • Test ascending sort
    • Test descending order by default
    • Test with prerelease versions
    • Test with build metadata (captures actual behavior per semver spec)
    • Test with complex semver versions
    • Test with single version
    • Test with empty versions array
    • Test with null versions
    • Test with undefined versions
    • Test with space-separated versions in single string
  • Export sort command in src/commands/mod.ts
  • Register sort command in main.ts
  • Validate implementation with manual tests
    • Test basic sorting (descending by default)
    • Test with -a flag (ascending)
    • Test stdin input with --
    • Test with prerelease versions
    • Test error handling with invalid versions
    • Test with no arguments (exit gracefully)
    • Test with space-separated versions
  • Run linter and tests to ensure no regressions
  • Update README documentation with sort command examples
  • Integrate with GitHub Action
    • Add sort to action.yml command options
    • Add docker-action integration test for sort command
    • Update copilot instructions with guidelines for adding new subcommands
    • Update value input description to include sort command usage
  • Address PR feedback
    • Return 0 with no output when no versions provided
    • Handle null/undefined versions gracefully by setting versionList to []
    • Throw error for invalid versions argument types
    • Update test to enumerate expected output for build metadata
    • Update @std/semver to latest version (1.0.6)
    • Simplify increment.ts by removing special case logic for prerelease
    • Add comprehensive tests for build metadata in None increment
    • Split version strings by whitespace to handle space-separated versions
    • Remove --desc option since descending is the default

Summary

Successfully implemented the semver sort subcommand with all required features and addressed all PR feedback:

Changes in Latest Commit

Removed the --desc / -d option to simplify the interface:

  • Removed the desc option from the command builder
  • Simplified the handler logic - now just checks !asc to determine descending sort
  • Updated SORT02 test description to reflect it tests default behavior
  • Removed desc: false from all test cases
  • The help output now only shows -a, --asc as the available flag
  • This makes the interface cleaner since descending is the default behavior

Code Simplification

Simplified src/util/increment.ts by removing custom prerelease handling logic:

  • Removed bumpPrerelease() function and its helper functions (parsePrerelease, bumpPrereleaseNumber, isValidNumber)
  • The latest @std/semver@1.0.6 now properly handles prerelease metadata during increment operations
  • For the None increment case with prerelease, now simply uses inc(version, "pre", { prerelease, build })
  • Reduced code from 119 lines to 48 lines (~60% reduction)
  • All existing tests continue to pass

Features

  • Sorts versions in descending order by default (highest to lowest)
  • Supports -a/--asc for ascending sort (lowest first)
  • Supports -- to read versions from stdin
  • Handles prerelease versions and build metadata correctly per semver spec
  • Proper error handling for invalid versions
  • Gracefully handles empty/null/undefined versions
  • Supports space-separated versions in arguments (e.g., "2.0.0 1.0.0")
  • Fully integrated into GitHub Action for use in workflows

GitHub Action Integration

  • Added sort to the command options in action.yml
  • Updated value input description to document sort command usage
  • Added "Sort" integration test step in docker-action job in .github/workflows/checks.yml
  • Tests that sort command works correctly via Docker action with sample values
  • Updated .github/copilot-instructions.md with new "Adding New Subcommands" section
    • Documents requirements for updating action.yml and adding docker-action tests
    • Provides guidelines for maintaining consistency across the codebase

Testing

  • All 11 sort unit tests pass
  • All 20 increment unit tests pass (4 tests added for build metadata)
  • No regressions in existing tests (47 tests pass, 1 pre-existing failure unrelated to this PR)
  • No formatting or linting issues
  • Manual testing confirms all examples work correctly including edge cases
  • Docker action integration test added to CI pipeline

Fixes #41

Original prompt

This section details on the original issue you should resolve

<issue_title>feature: Merge the semver-sort functionality into this repo as a subcommand semver sort ...</issue_title>
<issue_description># Feature Request

Add the sort subcommand to this cli. It should accept a set of 1 or more versions as inputs and it should return them in a sorted order, one version per line.

The sort algorithm should purely just use the deno std semver library to sort a standard array.

Options

This sort command should support the following options:

  • --asc, -a for ascending sort order (default)
  • --desc, -d for descending sort order
  • -- which should tell the sort command to read the versions from stdin instead of from arguments.

Examples

> semver sort 2.0.0 1.0.0 3.0.0
3.0.0
2.0.0
1.0.0
> semver sort -a 2.0.0 1.0.0 3.0.0
1.0.0
2.0.0
3.0.0
> cat > versions <EOF
2.0.0
1.0.0
3.0.0
EOF

> cat versions | semver sort --
3.0.0
2.0.0
1.0.0

</issue_description>

<agent_instructions>Please implement this new feature along with the corresponding tests.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #41


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLAassistant commented Oct 12, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ justinmchase
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 3 commits October 12, 2025 21:46
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI changed the title [WIP] Add semver sort functionality as a subcommand Add semver sort subcommand for sorting semantic versions Oct 12, 2025
Copilot AI requested a review from justinmchase October 12, 2025 21:53
Copilot finished work on behalf of justinmchase October 12, 2025 21:53
Copy link
Collaborator

@justinmchase justinmchase left a comment

Choose a reason for hiding this comment

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

@copilot Please address the PR feedback.

@justinmchase justinmchase marked this pull request as ready for review October 13, 2025 22:00
@github-actions github-actions bot added dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation labels Oct 13, 2025
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI requested a review from justinmchase October 13, 2025 22:07
Copilot finished work on behalf of justinmchase October 13, 2025 22:07
Copy link
Collaborator

@justinmchase justinmchase left a comment

Choose a reason for hiding this comment

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

@copilot very good, can you address the rest of this feedback?

….0.6

Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI requested a review from justinmchase October 13, 2025 22:17
Copilot finished work on behalf of justinmchase October 13, 2025 22:17
@justinmchase
Copy link
Collaborator

@copilot Can you also do the following:

  1. Add a step to the docker-action job in the check-docker workflow that will run an integration tests for the sort sub-command
  2. Update the action.yml file to include the sort subcommand
  3. Modify the copilot instructions file to include a section about always updating the action and action tests when adding new subcommands

@justinmchase
Copy link
Collaborator

@copilot In the latest version of @std/semver it now supports setting prerelease metadata during an increment.

Please update the code in ./src/util/increment.ts to no longer require special casing logic for prerelease data on the none increment.

…t instructions

Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot Can you also do the following:

  1. Add a step to the docker-action job in the check-docker workflow that will run an integration tests for the sort sub-command
    ...

Completed all three tasks in commit a4b7f82:

  1. Added "Sort" integration test step to docker-action job in .github/workflows/checks.yml that tests the sort command with sample values
  2. Added sort to the command options list in action.yml, making it available in the GitHub Action
  3. Added new "Adding New Subcommands" section to .github/copilot-instructions.md that documents the requirement to update both action.yml and docker-action tests when adding new subcommands, with the sort command as an example

Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot In the latest version of @std/semver it now supports setting prerelease metadata during an increment.

Please update the code in ./src/util/increment.ts to no longer require special casin...

Fixed in commit 7f9a3e1. Removed the special case logic for prerelease handling in the none increment. The code now uses inc(version, "pre", { prerelease, build }) directly, which is properly supported by @std/semver@1.0.6. Removed the custom bumpPrerelease(), parsePrerelease(), bumpPrereleaseNumber(), and isValidNumber() functions that are no longer needed. All tests continue to pass.

Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot finished work on behalf of justinmchase October 14, 2025 01:15
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI requested a review from justinmchase October 14, 2025 04:30
Copilot finished work on behalf of justinmchase October 14, 2025 04:30
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI requested a review from justinmchase October 14, 2025 04:39
Copilot finished work on behalf of justinmchase October 14, 2025 04:39
Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copilot AI requested a review from justinmchase October 14, 2025 04:52
Copilot finished work on behalf of justinmchase October 14, 2025 04:52
@justinmchase
Copy link
Collaborator

@copilot Now that I think about it since --desc is default we should probably remove it as an option and just have --asc. I think we should do this because having both options present doesn't make sense and I'd rather just not even let it be possible rather than throw an error.

Co-authored-by: justinmchase <10974+justinmchase@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot Now that I think about it since --desc is default we should probably remove it as an option and just have --asc. I think we should do this because having both options present doesn't make s...

Fixed in commit 5f3c8a1. Removed the --desc / -d option from the sort command. Descending is now the default behavior, and only --asc / -a is available to switch to ascending order. This simplifies the interface and prevents confusion about having both options.

Copilot finished work on behalf of justinmchase October 14, 2025 05:02
@justinmchase justinmchase merged commit 5c02e20 into main Oct 14, 2025
12 of 13 checks passed
@justinmchase justinmchase deleted the copilot/add-semver-sort-command branch October 14, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Merge the semver-sort functionality into this repo as a subcommand semver sort ...

3 participants