In continuous integration pipelines, deploying software updates requires updating build versions and tagging source code. Doing this manually is time-consuming and can lead to merge conflicts or missing tags. Writing automated Release Scripts ensures that versions follow Semantic Versioning (SemVer) rules, tags are applied correctly, and release logs are generated automatically.
By scripting shell utilities, we can automate patch and minor version increments on code commits.
1. Automated SemVer Tagging Script
We write a bash script that parses the current git tags, increments the patch or minor version, and pushes the new tag to the repository:
#!/bin/bash
# release.sh
set -euo pipefail
# Fetch latest tags
git fetch --tags
# Get current version tag (e.g. v1.2.3)
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Current Version: $CURRENT_VERSION"
# Strip 'v' prefix
VERSION_NUM=${CURRENT_VERSION#v}
IFS='.' read -r major minor patch <<< "$VERSION_NUM"
# Increment patch version by default
NEW_PATCH=$((patch + 1))
NEW_VERSION="v$major.$minor.$NEW_PATCH"
echo "New Version: $NEW_VERSION"
# Apply git tag and push
git tag -a "$NEW_VERSION" -m "Release version $NEW_VERSION"
git push origin "$NEW_VERSION"
2. Updating Package Configurations
Before creating the tag, the release script updates local config files (such as package.json or setup.py), committing the changes automatically to keep version files in sync.