name: Version Bump description: Bump or get semver patch version with git tags inputs: token: description: GitHub/Gitea token for pushing tags required: true mode: description: "bump (create tag) or get (read only)" required: false default: bump outputs: version: description: "e.g. 0.1.0 (no v prefix)" value: ${{ steps.calc.outputs.version }} version_with_sha: description: "e.g. 0.1.0-a1b2c3d" value: ${{ steps.calc.outputs.version_with_sha }} runs: using: composite steps: - name: Configure git shell: bash run: | git config user.name "CI Bot" git config user.email "ci@git.sebse.de" git remote set-url origin https://ci:${{ inputs.token }}@git.sebse.de/${{ github.repository }} - name: Fetch tags shell: bash run: git fetch --tags --force - name: Calculate version id: calc shell: bash run: | SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7) LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -n1) if [ -z "$LATEST_TAG" ]; then MAJOR=0 MINOR=0 PATCH=0 else V="${LATEST_TAG#v}" MAJOR=$(echo "$V" | cut -d. -f1) MINOR=$(echo "$V" | cut -d. -f2) PATCH=$(echo "$V" | cut -d. -f3) fi if [ "${{ inputs.mode }}" = "bump" ]; then NEW_PATCH=$((PATCH + 1)) else NEW_PATCH=$PATCH fi VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "version_with_sha=${VERSION}-${SHORT_SHA}" >> $GITHUB_OUTPUT echo "VERSION=${VERSION}" >> $GITHUB_ENV - name: Create and push tag if: inputs.mode == 'bump' shell: bash run: | git tag "v${VERSION}" git push origin "v${VERSION}"