Features: - Parse and compare semantic versions from Docker Hub - Check if current version is outdated on startup - Only pull updates when newer version is available - GitLab CI now tags images with Cargo.toml version - Created bump-version.sh script for easy version bumping How it works: 1. Cargo.toml contains source of truth version (0.1.0) 2. GitLab CI extracts version and tags Docker images with it 3. Agent queries Docker Hub for all semver tags 4. Compares current version against latest available 5. Only pulls and restarts if newer version exists Version bumping workflow: ./scripts/bump-version.sh patch # 0.1.0 -> 0.1.1 ./scripts/bump-version.sh minor # 0.1.0 -> 0.2.0 ./scripts/bump-version.sh major # 0.1.0 -> 1.0.0 This creates git commit and tag, ready to push.
75 lines
1.6 KiB
Bash
Executable file
75 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Bump semantic version in Cargo.toml
|
|
# Usage: ./bump-version.sh [major|minor|patch]
|
|
|
|
set -e
|
|
|
|
BUMP_TYPE=${1:-patch}
|
|
|
|
if [[ ! "$BUMP_TYPE" =~ ^(major|minor|patch)$ ]]; then
|
|
echo "Error: Invalid bump type. Use: major, minor, or patch"
|
|
exit 1
|
|
fi
|
|
|
|
# Get current version from Cargo.toml
|
|
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
|
|
|
|
if [ -z "$CURRENT_VERSION" ]; then
|
|
echo "Error: Could not find version in Cargo.toml"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Current version: $CURRENT_VERSION"
|
|
|
|
# Parse version
|
|
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
|
|
|
|
# Bump version
|
|
case $BUMP_TYPE in
|
|
major)
|
|
major=$((major + 1))
|
|
minor=0
|
|
patch=0
|
|
;;
|
|
minor)
|
|
minor=$((minor + 1))
|
|
patch=0
|
|
;;
|
|
patch)
|
|
patch=$((patch + 1))
|
|
;;
|
|
esac
|
|
|
|
NEW_VERSION="$major.$minor.$patch"
|
|
|
|
echo "New version: $NEW_VERSION"
|
|
|
|
# Update Cargo.toml
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# macOS
|
|
sed -i '' "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
|
|
else
|
|
# Linux
|
|
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
|
|
fi
|
|
|
|
echo "✓ Updated Cargo.toml"
|
|
|
|
# Update Cargo.lock
|
|
cargo check --quiet
|
|
echo "✓ Updated Cargo.lock"
|
|
|
|
# Git operations
|
|
git add Cargo.toml Cargo.lock
|
|
git commit -m "Bump version to $NEW_VERSION"
|
|
git tag "v$NEW_VERSION"
|
|
|
|
echo ""
|
|
echo "✓ Version bumped to $NEW_VERSION"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " git push origin main"
|
|
echo " git push origin v$NEW_VERSION"
|
|
echo ""
|
|
echo "This will trigger a GitLab CI build that tags the Docker image with $NEW_VERSION"
|