get-version.yml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_VERSION: 19
  24. JAVA_DIST: 'temurin'
  25. JAVA_CACHE: 'maven'
  26. jobs:
  27. determine-version:
  28. name: 'Determines the version following semver'
  29. runs-on: ubuntu-latest
  30. outputs:
  31. semVerNum: ${{ steps.versions.outputs.semVerNum }}
  32. semVerStr: ${{ steps.versions.outputs.semVerStr }}
  33. revNum: ${{ steps.versions.outputs.revNum }}
  34. type: ${{ steps.versions.outputs.type}}
  35. steps:
  36. - uses: actions/checkout@v3
  37. with:
  38. fetch-depth: 0
  39. - name: Setup Java
  40. uses: actions/setup-java@v3
  41. with:
  42. distribution: ${{ env.JAVA_DIST }}
  43. java-version: ${{ env.JAVA_VERSION }}
  44. cache: ${{ env.JAVA_CACHE }}
  45. - id: versions
  46. name: Get version information
  47. run: |
  48. if [[ $GITHUB_REF =~ refs/tags/[0-9]+\.[0-9]+\.[0-9]+.* ]]; then
  49. SEM_VER_STR=${GITHUB_REF##*/}
  50. elif [[ "${{ inputs.version }}" =~ [0-9]+\.[0-9]+\.[0-9]+.* ]]; then
  51. SEM_VER_STR="${{ github.event.inputs.version }}"
  52. else
  53. SEM_VER_STR=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
  54. fi
  55. SEM_VER_NUM=`echo ${SEM_VER_STR} | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/'`
  56. REVCOUNT=`git rev-list --count HEAD`
  57. TYPE="unknown"
  58. if [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  59. TYPE="stable"
  60. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-alpha[1-9]+$ ]]; then
  61. TYPE="alpha"
  62. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-beta[1-9]+$ ]]; then
  63. TYPE="beta"
  64. elif [[ $SEM_VER_STR =~ [0-9]+\.[0-9]+\.[0-9]+-rc[1-9]$ ]]; then
  65. TYPE="rc"
  66. fi
  67. echo "semVerStr=${SEM_VER_STR}" >> $GITHUB_OUTPUT
  68. echo "semVerNum=${SEM_VER_NUM}" >> $GITHUB_OUTPUT
  69. echo "revNum=${REVCOUNT}" >> $GITHUB_OUTPUT
  70. echo "type=${TYPE}" >> $GITHUB_OUTPUT
  71. - name: Validate Version
  72. uses: skymatic/semver-validation-action@v2
  73. with:
  74. version: ${{ steps.versions.outputs.semVerStr }}