版本管理器
vm的Python项目详细描述
跨多个文件更新版本。
安装
pip install vm
用法
你需要一个versions.json,或者一个versions.yml,只要你可以 指定要跟踪的版本以及要跟踪的文件 使用全局模式更新:
germanium:version:1.10.3files:README.*:"^(germanium)(.*?)$"setup.py:"version='**VERSION**',"doc/usage/index.adoc:"^(=Germaniumv)(.*?)$"germanium/version.py:"current=\"**VERSION**\""
帮助:
usage: version-manager [-h] [--display NAME] [--all] [--set NAME=VAL [NAME=VAL ...]] [--load FILE] [-t] [--ignore-missing-parents] [--version] Versions processor optional arguments: -h, --help show this help message and exit --display NAME, -d NAME Display the version of a single tracked version. --all, -a, --list Display all the tracked versions and their values. --set NAME=VAL [NAME=VAL ...], -s NAME=VAL [NAME=VAL ...] Set values overriding what's in the yml files. --load FILE, -l FILE Override versions from the given yml file. -t, --tag-name, --tag Get the current name to use in general tags. If the branch name can't be detected from the git repo, the $BRANCH_NAME environment variable will be used. --ignore-missing-parents Ignore missing parents, and simply don't patch the values. Upstream values are still being patched if existing. --version Show the currently installed program version (2.4.2)
指定版本
如果版本值包含“$”则将使用shell展开 或者一个'`',这样您就可以得到这样的版本:
"description":{"version":"Built at $(date) on $(uname -n)"}
或山药:
description:version:Built at $(date) on $(uname -n)
版本还可以引用其他版本文件,并提取属性 从这里开始,在版本中使用parent:符号:
"germaniumdrivers":{"version":"parent:../germanium/@germaniumdrivers"}
germaniumdrivers:version:"parent:../germanium/@germaniumdrivers"
路径将指向versions.json/yml文件或文件夹 它包含versions.json/yml文件,之后fill将 请阅读并解释将使用germaniumdrivers版本。
也可以使用 --set或-s标志,例如:
version-manager -s germanium=2.0.8
这将忽略versions.yml文件中指定的值,并使用 指定的那个。
功能分支
版本的前缀也可以是upstream:。在这种情况下,如果 当前签出的分支名称包含-x-,或导出的 branch_name环境变量具有该名称,返回的版本是 version-manager--tag将被替代。
germaniumdrivers:version:"upstream:1.1.0"
只要分支未标记为包含交叉特征分支 与-x-的依赖项将返回1.1.0。
这也适用于父分支,因此您可以拥有:
germaniumdrivers:version:"parent:upstream:../germanium/@germaniumdrivers"
如果分支名称是例如:feature/UI-123-x-test-new-drivers 不会读取parent:值,并且 0.1-feature_UI-123-x-test-new-drivers将作为值返回。
文件匹配器
目前只有三个文件匹配器:
regexp文件匹配器
它是一个包含两个或三个组的regexp,它将包含第二个组 组替换为匹配的版本。
version文件匹配器
这将构造一个与给定文本完全匹配的regexp, 第二组是**VERSION**。
所以有一个匹配器,比如:
"files":{"README":"This installs version **VERSION** of the product."}
或山药
files:README:This installs version **VERSION** of the product.
相当于:
"files":{"README":"(This installs version )(.+?)( of the product\\.)"}
或山药
files:README:(This installs version )(.+?)( of the product\\.)
如果**s在开头替换为^^,或者$$at 最后,它们将充当regexp锚,相当于^和$。 如果表达式中在^^之前或之后有内容 $$,内容被忽略。
maven:文件匹配器
这将构造一个匹配的regexp:
`(<groupId>${m[1]}</groupId>\\s*` + `<artifactId>${m[2]}</artifactId>\\s*` + `<version>)(.*?)(</version>)`;
要指定匹配器,只需使用:
{"germanium":{"version":"2.0.0","files":{"pom.xml":"maven:com.germaniumhq:germanium"}}
或山药
germanium:version:2.0.0files:pom.xml:maven:com.germaniumhq:germanium
匹配器约束
为了确保表达式不会替换太多 可以添加位置、约束来限制或扩展匹配。
匹配器约束始终处于活动状态,如果没有约束 然后指定最大替换计数设置为1。
匹配计数
{"product":{"version":"1.0","files":{"README.md":{"match":"^(= Germanium v)(.*?)$","count":2}}}}
或山药
product:version:"1.0"files:README.md:match:^(= Germanium v)(.*?)$count:2
计数也可以是0表示没有匹配项,也可以是负数表示任何匹配项 允许匹配的数目。
多个匹配器
在一个文件中,我们还可以有多个匹配器,例如:
{"product":{"version":"1.0","files":{"README.md":["^(= Germanium v)(.*?)$","(Germanium )(\\d+\\.\\d+)()"]}}}
对于添加的每个匹配器,如果未指定匹配计数, 假设它在文件中只匹配一次。
当然,约束可以同时应用于全套匹配器:
{"product":{"version":"1.0","files":{"README.md":{"match":["^(= Germanium v)(.*?)$","(Germanium )(\\d+\\.\\d+)()"],"count":3}}}}
甚至个别表达式:
{"product":{"version":"1.0","files":{"README.md":{"match":["^(= Germanium v)(.*?)$",{"match":"(Germanium )(\\d+\\.\\d+)()","count":2}],"count":3}}}}
注释
- 文件实际上是glob模式,因此可以匹配**/*.js 例如。
- 配置文件可以是yml。
- vm将输出以下错误代码:没有文件时为0 已更改,f时为0已成功更改文件,或出现非零错误 出错时的代码。