diff --git a/.github/workflows/get-version-info.yml b/.github/workflows/get-version-info.yml new file mode 100644 index 000000000..1aa97b60a --- /dev/null +++ b/.github/workflows/get-version-info.yml @@ -0,0 +1,62 @@ +name: Parse and Validate a version string or tag + +on: + workflow_call: + inputs: + version: + description: "A specific version to use" + required: false + type: string + outputs: + semVerStr: + description: "The full version string." + value: ${{ jobs.determine-version.outputs.semVerStr}} + semVerNum: + description: "The numerical part of the version string" + value: ${{ jobs.determine-version.outputs.semVerNum}} + revNum: + description: "The revision number" + value: ${{ jobs.determine-version.outputs.revNum}} + +env: + JAVA_VERSION: 19 + JAVA_DIST: 'temurin' + JAVA_CACHE: 'maven' + +jobs: + determine-version: + name: 'Determines the version following semver' + runs-on: ubuntu-latest + outputs: + semVerNum: ${{ steps.versions.outputs.semVerNum }} + semVerStr: ${{ steps.versions.outputs.semVerStr }} + revNum: ${{ steps.versions.outputs.revNum }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: ${{ env.JAVA_DIST }} + java-version: ${{ env.JAVA_VERSION }} + cache: ${{ env.JAVA_CACHE }} + - id: versions + name: Get version information # TODO: is Github ref inherited when called from super workflow? + run: | + if [[ $GITHUB_REF =~ refs/tags/[0-9]+\.[0-9]+\.[0-9]+.* ]]; then + SEM_VER_STR=${GITHUB_REF##*/} + elif [[ "${{ inputs.version }}" =~ [0-9]+\.[0-9]+\.[0-9]+.* ]]; then + SEM_VER_STR="${{ github.event.inputs.version }}" + else + SEM_VER_STR=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` + fi + SEM_VER_NUM=`echo ${SEM_VER_STR} | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/'` + REVCOUNT=`git rev-list --count HEAD` + echo "::set-output name=semVerStr::${SEM_VER_STR}" + echo "::set-output name=semVerNum::${SEM_VER_NUM}" + echo "::set-output name=revNum::${REVCOUNT}" + - name: Validate Version + uses: skymatic/semver-validation-action@v1 + with: + version: ${{ steps.versions.outputs.semVerStr }} \ No newline at end of file