sed to Bump Version Numbers in CI
sed can rewrite a version string in a manifest as part of a release pipeline, matching the exact line to avoid collateral edits.
Release jobs often need to stamp a new version into a file. sed does it in one line, but a loose pattern can rewrite the wrong field, so anchor the match.
What it does
sed matches the line holding the current version and substitutes the new value. The key is anchoring the pattern to the specific key so an unrelated version-like string elsewhere in the file is left alone.
Common usage
# package.json "version": "1.2.3"
sed -i 's/"version": "[0-9.]*"/"version": "1.3.0"/' package.json
# pom.xml first <version> under the project
sed -i '0,/<version>.*<\/version>/s//<version>1.3.0<\/version>/' pom.xml
# a plain VERSION file
echo "1.3.0" > VERSIONOptions
| Technique | Why it helps |
|---|---|
| Anchor the key | Match "version": not just the number, to avoid stray hits |
| [0-9.]* class | Match any semver-like value being replaced |
| 0,/re/s// (GNU) | Replace only the first match in the file |
| -i for in place | Write back to the manifest (mind GNU vs BSD) |
| Different delimiter | Use s|...| when the value contains slashes |
In CI
On ubuntu-latest, sed -i works without a backup argument; on macos-latest you need sed -i ''. The 0,/regex/ first-match address is a GNU extension, so on macOS replace only the first match another way or accept that all matches change. For structured files like package.json, a real JSON tool such as jq is safer than sed.
Common errors in CI
A greedy pattern like s/[0-9.]*// can wipe the value entirely if it matches an empty string; keep the surrounding key in the pattern. The XML example needs the slash in </version> escaped or a different delimiter, otherwise sed: -e expression #1, char N: unknown option to `s' appears.