diff --git a/.github/workflows/build-images-on-commit.yml b/.github/workflows/build-images-on-commit.yml index a7105a2..cf8c606 100644 --- a/.github/workflows/build-images-on-commit.yml +++ b/.github/workflows/build-images-on-commit.yml @@ -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: diff --git a/.github/workflows/build-images-on-pr.yml b/.github/workflows/build-images-on-pr.yml index 1dc62ba..48078e2 100644 --- a/.github/workflows/build-images-on-pr.yml +++ b/.github/workflows/build-images-on-pr.yml @@ -7,7 +7,6 @@ on: - "src/loaders/**" - "src/services/**" - "src/databases/**" - - ".version" - ".github/workflows/reusable-build-container-images.yml" - ".github/workflows/check.yml" jobs: diff --git a/.github/workflows/reusable-build-container-images.yml b/.github/workflows/reusable-build-container-images.yml index 8462d5d..a3fc7b5 100644 --- a/.github/workflows/reusable-build-container-images.yml +++ b/.github/workflows/reusable-build-container-images.yml @@ -29,10 +29,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4.2.2 - - 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 diff --git a/.github/workflows/tag-from-version.yml b/.github/workflows/tag-from-version.yml deleted file mode 100644 index 444be2d..0000000 --- a/.github/workflows/tag-from-version.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Create Tag from .version File -permissions: read-all - -on: - workflow_dispatch: - push: - paths: - - ".version" # Trigger only when the .version file changes - branches: - - main - -jobs: - create_tag: - runs-on: ubuntu-24.04 - permissions: - contents: write - steps: - # Checkout the repository - - name: Checkout repository - uses: actions/checkout@v4.2.2 - - # Read the content of the .version file - - name: Read version from .version file - id: read_version - run: | - if [ ! -f .version ]; then - echo "The .version file does not exist." - exit 1 - fi - version=$(cat .version | tr -d '[:space:]') - echo "version=$version" >> $GITHUB_ENV - - - name: Configure git - run: | - # Set up Git with an identifiable user - git config --global user.name cisco-service - git config --global user.email 111539563+cisco-service@users.noreply.github.com - - # Create a tag with the version - - name: Create and push tag - env: - GH_TOKEN: ${{ secrets.CISCO_SERVICE_GITHUB_AUTOMATION_TOKEN }} - run: | - # Add a custom tag message - tag_message="Tag created by ${{ github.actor }} via GitHub Actions." - git tag -a "$version" -m "$tag_message" - git push origin $version diff --git a/.version b/.version deleted file mode 100644 index a3dce6c..0000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -v0.0.2 diff --git a/scripts/bumpversion.sh b/scripts/bumpversion.sh index 5df9e2c..5908e6d 100755 --- a/scripts/bumpversion.sh +++ b/scripts/bumpversion.sh @@ -1,40 +1,70 @@ #!/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 @@ -42,12 +72,12 @@ if [[ $current_version =~ $version_pattern ]]; then 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++)) ;; @@ -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 ;; @@ -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"