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: "" suffix_separator: description: "Separator between version and suffix (either '.' or '-')" 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 id: calculate shell: bash run: | # Regular date with leading zeros DATE_LEADING=$(date +'%Y.%m.%d') # Year, month and day without leading zeros for alternate formats YEAR=$(date +'%Y') MONTH_NL=$(date +%-m) DAY_NL=$(date +%-d) TAG_COUNT=$(git tag -l "${DATE_LEADING}.*" | wc -l) if [ "${TAG_COUNT}" -eq 0 ]; then BUILD_NUMBER=0 else BUILD_NUMBER=$((${TAG_COUNT} + 1)) fi VERSION_SUFFIX="${{ inputs.version_suffix }}" SUFFIX_SEPARATOR="${{ inputs.suffix_separator }}" # Regular (keeps leading zeros in date) if [ -n "$VERSION_SUFFIX" ]; then BUILD_VERSION="${DATE_LEADING}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}" else BUILD_VERSION="${DATE_LEADING}.${BUILD_NUMBER}" fi # Dotnet variant: year.month.day.build (no leading zeros for month/day) DOTNET_DATE="${YEAR}.${MONTH_NL}.${DAY_NL}" if [ -n "$VERSION_SUFFIX" ]; then DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}" else DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}" fi # NPM variant: year.month.(day concatenated with build) e.g. 2026.2.221 for day=22 build=1 NPM_DAY_BUILD="${DAY_NL}${BUILD_NUMBER}" if [ -n "$VERSION_SUFFIX" ]; then NPM_VERSION="${YEAR}.${MONTH_NL}.${NPM_DAY_BUILD}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}" else NPM_VERSION="${YEAR}.${MONTH_NL}.${NPM_DAY_BUILD}" fi # Write the versions as artifacts for backward compatibility and accessibility echo "$BUILD_VERSION" > version.txt echo "$DOTNET_VERSION" > dotnet-version.txt echo "$NPM_VERSION" > npm-version.txt # Export regular version to environment (backwards-compatible) echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV - 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 - name: Upload Dotnet Version Artifact uses: https://github.com/actions/upload-artifact@v3 with: name: dotnet-version path: dotnet-version.txt - name: Upload NPM Version Artifact uses: https://github.com/actions/upload-artifact@v3 with: name: npm-version path: npm-version.txt