From 46b1317c9880ed6f68a62b49208815b5e6c24051 Mon Sep 17 00:00:00 2001 From: Alexander Gornak Date: Mon, 21 Oct 2024 01:47:42 +0300 Subject: [PATCH] ci: add working semver autotag (#12) --- .github/workflows/semver.yml | 25 +++++++++++++++++++++++++ scripts/semver.sh | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .github/workflows/semver.yml create mode 100755 scripts/semver.sh diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml new file mode 100644 index 0000000..cf75dc2 --- /dev/null +++ b/.github/workflows/semver.yml @@ -0,0 +1,25 @@ +name: Semver + +on: + push: + branches: + - master + +jobs: + set_tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Run version bump script + run: | + VERSION=$(./scripts/semver.sh) + echo "Project version: $VERSION" + + git config --global user.name "Gornak40[bot]" + git config --global user.email "noreply@algolymp.ru" + + MESSAGE=$(git log -1 --pretty=%B) + git tag $VERSION -m $MESSAGE + git push origin $VERSION diff --git a/scripts/semver.sh b/scripts/semver.sh new file mode 100755 index 0000000..de5ec8e --- /dev/null +++ b/scripts/semver.sh @@ -0,0 +1,22 @@ +#!/usr/bin/bash +major=0 +minor=0 +patch=0 + +commits=$(git log --reverse --pretty=format:"%s") + +while read -r commit_msg; do + if [[ $commit_msg == major* ]]; then + ((major++)) + minor=0 + patch=0 + elif [[ $commit_msg == feat* ]]; then + ((minor++)) + patch=0 + else + ((patch++)) + fi + >&2 echo "[v$major.$minor.$patch] $commit_msg" +done <<< $commits + +echo "v$major.$minor.$patch"