get-version.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. name: Parse and Validate a version string or tag
  2. on:
  3. workflow_call:
  4. inputs:
  5. version:
  6. description: "A specific version to use"
  7. required: false
  8. type: string
  9. outputs:
  10. semVerStr:
  11. description: "The full version string."
  12. value: ${{ jobs.determine-version.outputs.semVerStr}}
  13. semVerNum:
  14. description: "The numerical part of the version string"
  15. value: ${{ jobs.determine-version.outputs.semVerNum}}
  16. revNum:
  17. description: "The revision number"
  18. value: ${{ jobs.determine-version.outputs.revNum}}
  19. versionType:
  20. description: "Type of the version. Values are [stable, alpha, beta, rc, unknown]"
  21. value: ${{ jobs.determine-version.outputs.type }}
  22. env:
  23. JAVA_DIST: 'temurin'
  24. JAVA_VERSION: 23
  25. jobs:
  26. determine-version:
  27. name: 'Determines the version following semver'
  28. runs-on: ubuntu-latest
  29. outputs:
  30. semVerNum: ${{ steps.versions.outputs.semVerNum }}
  31. semVerStr: ${{ steps.versions.outputs.semVerStr }}
  32. revNum: ${{ steps.versions.outputs.revNum }}
  33. type: ${{ steps.versions.outputs.type}}
  34. steps:
  35. - uses: actions/checkout@v4
  36. with:
  37. fetch-depth: 0
  38. - name: Setup Java
  39. uses: actions/setup-java@v4
  40. with:
  41. distribution: ${{ env.JAVA_DIST }}
  42. java-version: ${{ env.JAVA_VERSION }}
  43. cache: 'maven'
  44. - id: versions
  45. name: Get version information
  46. run: |
  47. if [[ $GITHUB_REF =~ refs/tags/[0-9]+\.[0-9]+\.[0-9]+.* ]]; then
  48. SEM_VER_STR=${GITHUB_REF##*/}
  49. elif [[ "${{ inputs.version }}" =~ [0-9]+\.[0-9]+\.[0-9]+.* ]]; then
  50. SEM_VER_STR="${{ inputs.version }}"
  51. else
  52. SEM_VER_STR=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
  53. fi
  54. SEM_VER_NUM=`echo ${SEM_VER_STR} | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/'`
  55. REVCOUNT=`git rev-list --count HEAD`
  56. TYPE="unknown"
  57. if [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  58. TYPE="stable"
  59. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-alpha[1-9]+$ ]]; then
  60. TYPE="alpha"
  61. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-beta[1-9]+$ ]]; then
  62. TYPE="beta"
  63. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-rc[1-9]$ ]]; then
  64. TYPE="rc"
  65. fi
  66. echo "semVerStr=${SEM_VER_STR}" >> $GITHUB_OUTPUT
  67. echo "semVerNum=${SEM_VER_NUM}" >> $GITHUB_OUTPUT
  68. echo "revNum=${REVCOUNT}" >> $GITHUB_OUTPUT
  69. echo "type=${TYPE}" >> $GITHUB_OUTPUT
  70. - name: Validate Version
  71. uses: skymatic/semver-validation-action@v3
  72. with:
  73. version: ${{ steps.versions.outputs.semVerStr }}