|
| 1 | +name: "Resolve and validate release version" |
| 2 | +description: > |
| 3 | + Reads the module POM version (the source of truth), verifies it is a |
| 4 | + -SNAPSHOT, and derives the effective release version (the optional override, |
| 5 | + or the POM version with -SNAPSHOT stripped). Exports CURRENT_VERSION and |
| 6 | + EFFECTIVE_RELEASE_VERSION to the job environment for subsequent steps. |
| 7 | +
|
| 8 | +inputs: |
| 9 | + module: |
| 10 | + description: "Module directory containing the pom.xml to release." |
| 11 | + required: true |
| 12 | + release-version-override: |
| 13 | + description: "Optional release version; defaults to the POM version without -SNAPSHOT." |
| 14 | + required: false |
| 15 | + default: "" |
| 16 | + validate-module-dir: |
| 17 | + description: "Fail if the module directory or its pom.xml is missing (use for the choice-driven workflow)." |
| 18 | + required: false |
| 19 | + default: "false" |
| 20 | + |
| 21 | +runs: |
| 22 | + using: composite |
| 23 | + steps: |
| 24 | + - name: Resolve and validate release version |
| 25 | + shell: bash |
| 26 | + env: |
| 27 | + MODULE: ${{ inputs.module }} |
| 28 | + RELEASE_VERSION_OVERRIDE: ${{ inputs.release-version-override }} |
| 29 | + VALIDATE_MODULE_DIR: ${{ inputs.validate-module-dir }} |
| 30 | + run: | |
| 31 | + if [[ "$VALIDATE_MODULE_DIR" == "true" ]]; then |
| 32 | + if [[ ! -d "$MODULE" ]]; then |
| 33 | + echo "::error::Module directory '$MODULE' does not exist" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + if [[ ! -f "$MODULE/pom.xml" ]]; then |
| 37 | + echo "::error::No pom.xml found in '$MODULE'" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + fi |
| 41 | +
|
| 42 | + # The POM version is the source of truth and must be a SNAPSHOT. |
| 43 | + CURRENT_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version --file "$MODULE/pom.xml") |
| 44 | + CURRENT_VERSION="${CURRENT_VERSION//[$'\r\n']/}" |
| 45 | + if [[ "$CURRENT_VERSION" != *-SNAPSHOT ]]; then |
| 46 | + echo "::error::POM version '$CURRENT_VERSION' is not a SNAPSHOT" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + # Optional override; default strips -SNAPSHOT. |
| 51 | + EFFECTIVE_RELEASE_VERSION="${RELEASE_VERSION_OVERRIDE:-${CURRENT_VERSION%-SNAPSHOT}}" |
| 52 | +
|
| 53 | + echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV" |
| 54 | + echo "EFFECTIVE_RELEASE_VERSION=$EFFECTIVE_RELEASE_VERSION" >> "$GITHUB_ENV" |
0 commit comments