Added set version action

This commit is contained in:
2026-02-14 15:01:56 +01:00
parent 56c1771dbb
commit e161c2dcf0

62
set-version/action.yaml Normal file
View File

@@ -0,0 +1,62 @@
name: "Set Version"
description: "Generates a date-based build version, creates a git tag and uploads version artifact"
inputs:
version_suffix:
description: "Suffix for version (e.g. dev, alpha, beta)"
required: false
default: ""
runs:
using: "composite"
steps:
- name: Checkout Repository
uses: https://github.com/actions/checkout@v3
with:
token: ${{ env.CI_ACCESS_TOKEN }}
- name: Fetch Tags
shell: bash
run: |
git fetch --tags
- name: Calculate Version
shell: bash
run: |
DATE=$(date +'%Y.%m.%d')
TAG_COUNT=$(git tag -l "${DATE}.*" | wc -l)
if [ "$TAG_COUNT" -eq 0 ]; then
BUILD_NUMBER=0
else
BUILD_NUMBER=$(($TAG_COUNT + 1))
fi
VERSION_SUFFIX="${{ inputs.version_suffix }}"
if [ -n "$VERSION_SUFFIX" ] && [ "$VERSION_SUFFIX" = "dev" ]; then
BUILD_VERSION="${DATE}.dev${BUILD_NUMBER}"
elif [ -n "$VERSION_SUFFIX" ]; then
BUILD_VERSION="${DATE}.${BUILD_NUMBER}${VERSION_SUFFIX}"
else
BUILD_VERSION="${DATE}.${BUILD_NUMBER}"
fi
echo "$BUILD_VERSION" > version.txt
echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV
echo "Generated version: $BUILD_VERSION"
- name: Create Git Tag
shell: bash
run: |
git config user.name "ci"
git config user.email "dev@sh-edraft.de"
git tag "$VERSION"
git push origin "$VERSION"
- name: Upload Version Artifact
uses: https://github.com/actions/upload-artifact@v3
with:
name: version
path: version.txt