Before I do a release of my package and tag it, I would like to update the manifest.json file version Patch value to reflect the new version of the package every time I trigger it.
Json file:
{
"version": "0.0.0",
"timeStamp": "2022-02-14T09:41:34 00:00",
"packages": [
{
"name": "data-service",
"type": "docker-image",
"version": "REL-1.0.5"
},
{
"name": "application-service",
"type": "docker-image",
"version": "REL-1.0.6"
},
]
}
So here I am trying to increment by reading the content of the Json file from Powershell:
version = (Get-Content manifest.json | ConvertFrom-Json).version
Value for the variable "version" in the Json file is 0.0.0 But My question is - how to increase the only patch value? E.g. I need to have 0.0.1 output values after transform automatically in the manifest.json file.
CodePudding user response:
Use the [version]
type to parse the existing version, then increment the build number:
$data = Get-Content manifest.json | ConvertFrom-Json
# extract and increment version build number
$existingVersion = $data.version -as [version]
$nextVersion = [version]::new($existingVersion.Major, $existingVersion.Minor, $existingVersion.Build 1)
# update original data
$data.version = "$nextVersion"
# write back to disk
$data |ConvertTo-Json |Set-Content updated-manifest.json