提问人:Chris Paschen 提问时间:7/30/2021 更新时间:8/23/2021 访问量:78
XML 清单中的 Phing 更新版本号
Phing update version number in XML manifest
问:
我需要将功能添加到phing构建中,以便:
- 解析项目区域中的现有 xml 文件以获取现有内部版本号(格式为 1.2.3)
- 询问用户这是什么类型的“更改”(即主要、次要、修复)
- 根据用户在运行时的响应,从内部版本号升级相应的数字(如果主要增加 1 乘以 1;如果次要增加 2 乘以 1;如果修复将 3 增加 1)
- 将内部版本号存储回原始 xml 文件中
- 在命名 zip 文件时可以使用新的内部版本号(稍后在内部版本中)。
想知道是否有人已经有一个 phing 构建文件来执行类似操作,或者您是否碰巧知道哪些 phing 任务可能有助于完成这些步骤?
答:
0赞
Siad Ardroumli
8/23/2021
#1
作为起点,您可以使用版本任务(它使用属性文件来存储版本信息)或从 xml 文件进行更多工作,而不会产生开销。
以下示例生成脚本(可在描述属性中找到文档链接)包含这两种方式。
<?xml version="1.0" encoding="UTF-8" ?>
<project name="version test"
default="help"
phingVersion="3.0"
description="https://stackoverflow.com/questions/68584221/phing-update-version-number-in-xml-manifest"
>
<target name="help" description="usage help">
<echo>Usage:</echo>
<echo>bin/phing xml-file-based-workflow</echo>
<echo>bin/phing property-file-based-workflow</echo>
</target>
<target name="xml-file-based-workflow"
description="version handling with xml file"
depends="user-input,handle-xml-version,use-version"
/>
<target name="property-file-based-workflow"
description="version handling with property file"
depends="user-input,handle-property-version,use-version"
/>
<target name="user-input"
description="https://www.phing.info/guide/hlhtml/#InputTask"
hidden="true"
>
<input message="what is your release type?" propertyName="release.type" defaultValue="Bugfix"/>
</target>
<target name="handle-property-version"
description="https://www.phing.info/guide/hlhtml/#VersionTask"
hidden="true"
>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
</target>
<target name="handle-xml-version"
description="
https://www.phing.info/guide/hlhtml/#XmlPropertyTask
https://www.phing.info/guide/hlhtml/#EchoPropertiesTask
https://www.phing.info/guide/hlhtml/#VersionTask
https://www.phing.info/guide/hlhtml/#DeleteTask
https://www.phing.info/guide/hlhtml/#EchoXMLTask
"
hidden="true"
>
<xmlproperty file="VERSION.xml" />
<echoproperties destfile="VERSION.txt" regex="/version\.number/"/>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
<delete file="VERSION.txt"/>
<echoxml file="VERSION.xml">
<version>
<number>${version.number}</number>
</version>
</echoxml>
</target>
<target name="use-version"
description="https://www.phing.info/guide/hlhtml/#EchoTask"
hidden="true"
>
<echo message="${version.number}" />
</target>
</project>
评论