name: "Create New Tag"
description: "Compute the next semantic version tag based on existing tags"

outputs:
  new_tag:
    description: "The new tag computed for this build"
    value: ${{ steps.tag.outputs.new_tag }}

runs:
  using: "composite"
  steps:
    - name: Create New Tag
      id: tag
      shell: bash
      run: |
        echo "Computing new tag..."
        latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "")
        if [ -z "$latest_tag" ]; then
          new_tag="v1.0.0"
        else
          IFS='.' read -r major minor patch <<< "${latest_tag#v}"
          minor=$((minor + 1))
          patch=0
          new_tag="v${major}.${minor}.${patch}"
        fi
        echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
        echo "Computed new tag: $new_tag"
