|
10 | 10 | jobs:
|
11 | 11 |
|
12 | 12 | # ---------------------------------------------------------------------------
|
13 |
| - build-and-publish: |
| 13 | + build-and-test: |
14 | 14 | runs-on: ubuntu-latest
|
| 15 | + permissions: |
| 16 | + id-token: write |
| 17 | + contents: write |
| 18 | + outputs: |
| 19 | + version: ${{ steps.extract-version.outputs.version }} |
15 | 20 |
|
16 | 21 | steps:
|
17 | 22 | - name: Checkout repository
|
|
31 | 36 | java-version: 11
|
32 | 37 | distribution: corretto
|
33 | 38 |
|
| 39 | + - name: Extract Version |
| 40 | + id: extract-version |
| 41 | + run: | |
| 42 | + if [[ "${{ github.event_name == 'release'}}" = "true" ]]; then |
| 43 | + VERSION=$(git describe --tags | cut -d v -f2) |
| 44 | + else |
| 45 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout); |
| 46 | + fi |
| 47 | + echo "Detected version = $VERSION" |
| 48 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Set Release Version |
| 51 | + if: ${{ github.event_name == 'release' }} |
| 52 | + run: | |
| 53 | + git config user.email "[email protected]" |
| 54 | + git config user.name "GitHub Actions" |
| 55 | + |
| 56 | + RELEASE_VERSION="${{ steps.extract-version.outputs.version }}" |
| 57 | + mvn -B versions:set "-DnewVersion=$RELEASE_VERSION" versions:commit |
| 58 | + git commit -am "[skip ci] set release version $RELEASE_VERSION" |
| 59 | + git push origin HEAD:master |
| 60 | + |
| 61 | + TAG_NAME="v$RELEASE_VERSION" |
| 62 | + git tag -f $TAG_NAME |
| 63 | + git push origin -f --tags |
| 64 | +
|
34 | 65 | - name: Maven Build
|
35 | 66 | run: mvn -B verify -Pci
|
36 | 67 |
|
|
40 | 71 | name: target
|
41 | 72 | path: target/*.jar
|
42 | 73 | retention-days: 2
|
| 74 | + |
| 75 | + |
| 76 | + prepare-next-snapshot: |
| 77 | + needs: build-and-test |
| 78 | + runs-on: ubuntu-latest |
| 79 | + if: ${{ github.event_name == 'release' }} |
| 80 | + steps: |
| 81 | + - name: Checkout Source |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Download Maven Cache |
| 85 | + uses: actions/cache@v4 |
| 86 | + with: |
| 87 | + path: ~/.m2/repository |
| 88 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 89 | + restore-keys: | |
| 90 | + ${{ runner.os }}-maven- |
| 91 | +
|
| 92 | + - name: Setup JDK 11 |
| 93 | + uses: actions/setup-java@v4 |
| 94 | + with: |
| 95 | + java-version: 11 |
| 96 | + distribution: corretto |
| 97 | + |
| 98 | + - name: Prepare next Snapshot Version |
| 99 | + run: | |
| 100 | + git config user.email "[email protected]" |
| 101 | + git config user.name "GitHub Actions" |
| 102 | + git pull origin HEAD |
| 103 | + |
| 104 | + VERSION="${{ needs.build-and-test.outputs.version }}" |
| 105 | + MAJOR_VERSION=$(echo "$VERSION" | cut -d . -f1) |
| 106 | + MINOR_VERSION=$(echo "$VERSION" | cut -d . -f2) |
| 107 | + INCREMENT_VERSION=$(echo "$VERSION" | cut -d . -f3) |
| 108 | + NEXT_INCREMENT_VERSION=$((INCREMENT_VERSION + 1)) |
| 109 | + NEXT_SNAPSHOT_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$NEXT_INCREMENT_VERSION-SNAPSHOT" |
| 110 | + mvn -B versions:set "-DnewVersion=$NEXT_SNAPSHOT_VERSION" versions:commit |
| 111 | + git commit -am "[skip ci] set development version $NEXT_SNAPSHOT_VERSION" |
| 112 | + git push origin HEAD:master |
0 commit comments