Skip to content

Commit

Permalink
Remove .version and use git tags instead (#45)
Browse files Browse the repository at this point in the history
* Remove .version and use git tags instead

Signed-off-by: Severin Neumann <[email protected]>

* remove references to .version file

Signed-off-by: Severin Neumann <[email protected]>

* Update tag-from-version.yml (#44)

* initial commit mysql service (#33)

* initial commit mysql service

* moved mysql service to it's own section in /src

* moved mysql folder to src/databases/mysql

* updated reusable workflow

* initial commit cleand up nodejs service (#36)

---------

Signed-off-by: Severin Neumann <[email protected]>
Co-authored-by: Alexander Stoklasa <[email protected]>
  • Loading branch information
svrnm and noMoreCLI authored Dec 17, 2024
1 parent e0d162c commit 773429d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 77 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-images-on-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- "src/loaders/**"
- "src/services/**"
- "src/databases/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/build-images-on-commit.yml"
workflow_dispatch:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-images-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- "src/loaders/**"
- "src/services/**"
- "src/databases/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/check.yml"
jobs:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/reusable-build-container-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ jobs:
steps:
- name: Checkout
uses: actions/[email protected]
- name: Read version from .version file
id: version
run: |
echo "version=$(cat .version)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
47 changes: 0 additions & 47 deletions .github/workflows/tag-from-version.yml

This file was deleted.

1 change: 0 additions & 1 deletion .version

This file was deleted.

80 changes: 57 additions & 23 deletions scripts/bumpversion.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,83 @@
#!/bin/bash

# File that stores the version string
REPO_DIR=$(dirname "$0")/..
VERSION_FILE="$REPO_DIR/.version"

# Function to display help
show_help() {
echo "Usage: bumpversion.sh [OPTION]"
echo "Modify or display the version string in the form of 'v{major}.{minor}.{patch}'."
echo "Stores the version in the file '$VERSION_FILE', defaults to v0.0.0 if it does not exist"
echo "Version information is managed using Git tags."
echo
echo "Options:"
echo " --patch Increase the patch number by 1."
echo " --minor Increase the minor number by 1 and reset patch to 0."
echo " --major Increase the major number by 1, reset minor to 0, reset patch to 0."
echo " --push Push the latest or newly created tag to the remote repository."
echo " --help Display this help message."
echo " (no option) Display the current version."
}

# Function to read the current version from the file
# Function to get the latest version from Git tags
get_version() {
if [ -f "$VERSION_FILE" ]; then
cat "$VERSION_FILE"
else
echo "v0.0.0" # Default version if the file does not exist
fi
# Get the latest tag matching the version pattern, fallback to v0.0.0
git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1 || echo "v0.0.0"
}

# Function to update the version in the file
# Function to set a new Git tag with the updated version
set_version() {
echo "$1" >"$VERSION_FILE"
git tag "$1"
}

# Function to push a tag to the remote repository
push_version() {
git push origin "$1"
}

# Parse command-line arguments
push_to_remote=false
operation=""

for arg in "$@"; do
case "$arg" in
--patch|--minor|--major)
operation="$arg"
;;
--push)
push_to_remote=true
;;
--help)
show_help
exit 0
;;
*)
echo "Unknown option: $arg"
show_help
exit 1
;;
esac
done

# Get the current version
current_version=$(get_version)

# If --push is used without --patch, --minor, or --major
if $push_to_remote && [ -z "$operation" ]; then
push_version "$current_version"
echo "Pushed existing tag $current_version to the remote repository."
exit 0
fi

# Extract major, minor, and patch numbers
version_pattern='^v([0-9]+)\.([0-9]+)\.([0-9]+)$'
if [[ $current_version =~ $version_pattern ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
else
echo "Invalid version format"
echo "Invalid version format: $current_version"
exit 1
fi

# Handle command-line arguments
case "$1" in
# Handle version increment based on the operation
case "$operation" in
--patch)
((patch++))
;;
Expand All @@ -60,12 +90,8 @@ case "$1" in
minor=0
patch=0
;;
--help)
show_help
exit 0
;;
*)
# No argument, just return the current version
"")
# No operation provided, just display the current version
echo "$current_version"
exit 0
;;
Expand All @@ -74,8 +100,16 @@ esac
# Construct the new version string
new_version="v${major}.${minor}.${patch}"

# Update the version file
# Update the Git tag
set_version "$new_version"

# Push the tag if the --push flag is provided
if $push_to_remote; then
push_version "$new_version"
echo "Pushed tag $new_version to the remote repository."
else
echo "Created tag $new_version locally. Use '--push' to push it to the remote repository."
fi

# Output the new version
echo "$new_version"

0 comments on commit 773429d

Please sign in to comment.