简体   繁体   中英

Increment the patch in a version number

I have a YAML file with semantic versioning number like this:

version: 1.0.1

I need to increment PATCH part of the version. Is it possible to do it with yq?

UPDATE: The question is about mikefarah/yq implementation which is installed with brew install yq .

Please clarify which implementation of yq you are using. Apart from that, the general approach would be to split the string at the dots, convert the last item to a number and increment it, and then rejoin the array with dots.

Here's one way of doing it using the kislyuk/yq implementation:

.version |= (./"." | last |= tonumber + 1 | join("."))

And here's the same using the mikefarah/yq implementation:

.version |= (split(".") | .[-1] |= ((. tag = "!!int") + 1) | join("."))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM