Comments (7)
Thanks for your suggestion! Interest--and especially feedback on usage--is appreciated.
While I understand the request, it is a little terse. Do you have specific use cases in mind?
I have a few reservations about adding this new functionality:
- semver-tool "is a little tool to manipulate version bumping in a project". It does go a bit beyond that, but not much. I look at it as a small helper for CI pipelines. Back to the use case: How would sorting be used in this context?
- It is very convenient (except on Windows!) to have small tools written in bash: you get the source, nothing to compile or link, etc. However, bash is far from the best choice for data set handling (e.g. sorting files of structures). If you look around the web for tools to sort semantic versions, you find a couple bash scripts. But they are mostly wrappers to invoke other programs (e.g. GNU sort): what bash scripts are designed for. semver-tool has probably already pushed bash too far.
- If sorting semantic version numbers is needed, I'd check out the various solutions available. One example might be Masterminds/semver. There is a command line wrapper: Masterminds/vert.
from semver-tool.
Use case: auto-increment patch version on merge to master or release/ branches
# get current branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# get all tags visible from current branch, sort them and pick the last (highest)
LATEST_TAG=$(git tags --merged ${BRANCH} | semver sort | tail -1)
# bump the highest visible version
NEW_TAG=$(semver bump patch ${LATEST_TAG})
# add tag
git tag -a "${NEW_TAG}" -m "<meaningful comment>"
# push tag
git push --tags origin
Here the sort
option could also be a highest
option, used to find the version to bump
from semver-tool.
Thanks for the use case. I agree that this is a typical situation in a CI pipeline. And you have run into the problem that "bumping" a given version is easier than determining the given version. (see, for example, storing the semver value)
You note--and I tend to agree--that "highest" is really what you want. This code "almost" does it:
function newest {
if [ $(semver compare "$1" "$2") -lt 0 ]
then echo "$2"
else echo "$1"
fi
}
max="0.0.0"
for i in "$@"
do
max=$(newest "$max" "$i")
done
echo "$max"
It seems to me that semver has the needed functionality (via compare) that one needs to write wrappers/code to get the job done. So, one question is whether or not it makes sense to incorporate some sort of "highest" function, adding to the API?
Currently, no commands read from stdin. So, returning the "highest" from stdin would be a funny direction to take. The above code returns the highest from the given arguments.
I mentioned that the code "almost" works. It fails when a tag like "0.0.0-rc1" exists. It fails when other tags (not semantic versions) exist. Your example code fails when there are no tags. I think the underlying problem is basing the "find-current-version-scheme" on git tags (and git itself).
This is not really a semver-tool issue. However, adding features to semver-tool to support a git scheme (or, in general, use of a list of versions to determine the current version) is less than convincing. And since a few lines of code to make the scheme work and enable this particular use case is quite reasonable, it seems best to keep semver-tool simple.
On the other hand, maybe "compare" is broken? Do people really use the returned value (-1,0,1) for logic other than selecting the newer value? It would be unfortunate if everyone was writing bash if-then-else's just to get the newest version when a function like semver newest <version> <other-version>
would do the job. And, of course, "newest" could be generalised to zero or more arguments. Any ideas out there?
from semver-tool.
git-tag
supports sorting by version with the git tag --sort=v:refname
invocation. That won't work for all of semver specifications, but will likely work for the standard major.minor.patch
pattern.
from semver-tool.
I'm not seeing a lot of feedback on this issue. I'll mark it "won't fix" and see if this sparks something. Otherwise, after a while, it needs to go to the graveyard ...
from semver-tool.
hi
we to need this functionality
add it please
from semver-tool.
hi we to need this functionality add it please
It would be helpful if you could explain your specific use-case (see, for example, the use-case described above and the subsequent conversation). Also, the above discussion mentions issues with tag sorting and @fsaintjacques offered the git gist for the common case of semantic version string sorting. Do these tag sorting schemes not work for you? It would be interesting to know exactly why not if the feature is to be pursued.
from semver-tool.
Related Issues (20)
- Portability: Function names containing hyphens HOT 2
- Inconsistent re-naming of "is-nat" HOT 1
- "bump prerel" should support numerical increments HOT 3
- travis-ci badge in README.md should be changed to a GitHub Action badge HOT 1
- "tag" badge in README.md file is inconsistent and confusing HOT 2
- atom/keyword returned by "diff" should match the atoms/keywords used by "bump" HOT 2
- "bats" test files are fragmented and inconsistent HOT 4
- prerel compare issue HOT 4
- Create docs for installing on a travis agent HOT 3
- asdf plugin
- Feature request: command to validate if something is a semver HOT 2
- Request regarding "semver bump prerel" HOT 2
- README should factor out package manager installation notes HOT 5
- Is it expected, that prerel bump removes "v" prefix? HOT 2
- semver validate exit codes HOT 5
- Feature request: get '$major.$minor.*`
- Test dependencies obscure/confusing and not DRY HOT 5
- Dots are not allowed in prerelease identifiers HOT 2
- Support docker version with build number HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from semver-tool.