156 lines
5.1 KiB
YAML
156 lines
5.1 KiB
YAML
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: "-"
|
|
target:
|
|
description: "Project type (e.g. dotnet, npm)"
|
|
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: Prepare variables
|
|
id: prepare
|
|
shell: bash
|
|
run: |
|
|
YEAR=$(date +'%Y')
|
|
MONTH=$(date +%-m)
|
|
DAY=$(date +%-d)
|
|
VERSION_SUFFIX="${{ inputs.version_suffix }}"
|
|
SUFFIX_SEPARATOR="${{ inputs.suffix_separator }}"
|
|
|
|
# Count tags for day and month prefixes to support different targets
|
|
TAG_COUNT_DAY=$(git tag -l "${YEAR}.${MONTH}.${DAY}.*" | wc -l)
|
|
TAG_COUNT_MONTH=$(git tag -l "${YEAR}.${MONTH}.*" | wc -l)
|
|
|
|
echo "year=$YEAR" >> $GITHUB_OUTPUT
|
|
echo "month=$MONTH" >> $GITHUB_OUTPUT
|
|
echo "day=$DAY" >> $GITHUB_OUTPUT
|
|
echo "version_suffix=$VERSION_SUFFIX" >> $GITHUB_OUTPUT
|
|
echo "suffix_separator=$SUFFIX_SEPARATOR" >> $GITHUB_OUTPUT
|
|
echo "tag_count_day=$TAG_COUNT_DAY" >> $GITHUB_OUTPUT
|
|
echo "tag_count_month=$TAG_COUNT_MONTH" >> $GITHUB_OUTPUT
|
|
|
|
- name: Calculate Version (dotnet)
|
|
id: calc_dotnet
|
|
if: ${{ inputs.target == 'dotnet' }}
|
|
shell: bash
|
|
run: |
|
|
YEAR=${{ steps.prepare.outputs.year }}
|
|
MONTH=${{ steps.prepare.outputs.month }}
|
|
DAY=${{ steps.prepare.outputs.day }}
|
|
VERSION_SUFFIX=${{ steps.prepare.outputs.version_suffix }}
|
|
SUFFIX_SEPARATOR=${{ steps.prepare.outputs.suffix_separator }}
|
|
TAG_COUNT=${{ steps.prepare.outputs.tag_count_day }}
|
|
|
|
if [ "$TAG_COUNT" -eq 0 ]; then
|
|
BUILD_NUMBER=0
|
|
else
|
|
BUILD_NUMBER=$(($TAG_COUNT + 1))
|
|
fi
|
|
|
|
if [ -n "$VERSION_SUFFIX" ]; then
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${DAY}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
|
|
else
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${DAY}.${BUILD_NUMBER}"
|
|
fi
|
|
|
|
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Calculate Version (angular)
|
|
id: calc_angular
|
|
if: ${{ inputs.target == 'angular' }}
|
|
shell: bash
|
|
run: |
|
|
YEAR=${{ steps.prepare.outputs.year }}
|
|
MONTH=${{ steps.prepare.outputs.month }}
|
|
DAY=${{ steps.prepare.outputs.day }}
|
|
VERSION_SUFFIX=${{ steps.prepare.outputs.version_suffix }}
|
|
SUFFIX_SEPARATOR=${{ steps.prepare.outputs.suffix_separator }}
|
|
TAG_COUNT=${{ steps.prepare.outputs.tag_count_month }}
|
|
|
|
if [ "$TAG_COUNT" -eq 0 ]; then
|
|
BUILD_NUMBER=0
|
|
else
|
|
BUILD_NUMBER=$(($TAG_COUNT + 1))
|
|
fi
|
|
|
|
LAST_PART="${DAY}${BUILD_NUMBER}"
|
|
if [ -n "$VERSION_SUFFIX" ]; then
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${LAST_PART}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
|
|
else
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${LAST_PART}"
|
|
fi
|
|
|
|
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Calculate Version (default)
|
|
id: calc_default
|
|
if: ${{ inputs.target != 'dotnet' && inputs.target != 'angular' }}
|
|
shell: bash
|
|
run: |
|
|
YEAR=${{ steps.prepare.outputs.year }}
|
|
MONTH=${{ steps.prepare.outputs.month }}
|
|
DAY=${{ steps.prepare.outputs.day }}
|
|
VERSION_SUFFIX=${{ steps.prepare.outputs.version_suffix }}
|
|
SUFFIX_SEPARATOR=${{ steps.prepare.outputs.suffix_separator }}
|
|
TAG_COUNT=${{ steps.prepare.outputs.tag_count_day }}
|
|
|
|
if [ "$TAG_COUNT" -eq 0 ]; then
|
|
BUILD_NUMBER=0
|
|
else
|
|
BUILD_NUMBER=$(($TAG_COUNT + 1))
|
|
fi
|
|
|
|
if [ -n "$VERSION_SUFFIX" ]; then
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${DAY}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
|
|
else
|
|
BUILD_VERSION="${YEAR}.${MONTH}.${DAY}.${BUILD_NUMBER}"
|
|
fi
|
|
|
|
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Publish Version
|
|
shell: bash
|
|
run: |
|
|
BUILD_VERSION="${{ steps.calc_dotnet.outputs.build_version }}"
|
|
if [ -z "$BUILD_VERSION" ]; then BUILD_VERSION="${{ steps.calc_angular.outputs.build_version }}"; fi
|
|
if [ -z "$BUILD_VERSION" ]; then BUILD_VERSION="${{ steps.calc_default.outputs.build_version }}"; 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
|