|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +jobs: |
| 9 | + test: |
| 10 | + if: "!contains(github.event.head_commit.message, '[version bump]')" |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout project |
| 14 | + uses: actions/checkout@v2 |
| 15 | + - name: Setup Build Cache |
| 16 | + uses: actions/cache@v1 |
| 17 | + with: |
| 18 | + path: ~/.m2/repository |
| 19 | + key: ${{ runner.os }}-m2 |
| 20 | + restore-keys: | |
| 21 | + ${{ runner.os }}-m2 |
| 22 | + - name: Set up JDK 11 |
| 23 | + uses: actions/setup-java@v1 |
| 24 | + with: |
| 25 | + java-version: 11 |
| 26 | + - name: Build & Test |
| 27 | + run: mvn -B test |
| 28 | + |
| 29 | + sonar: |
| 30 | + if: "!contains(github.event.head_commit.message, '[version bump]')" |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Checkout project |
| 34 | + uses: actions/checkout@v2 |
| 35 | + - name: Setup Build Cache |
| 36 | + uses: actions/cache@v1 |
| 37 | + with: |
| 38 | + path: ~/.m2/repository |
| 39 | + key: ${{ runner.os }}-m2 |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-m2 |
| 42 | + - name: Set up JDK 11 |
| 43 | + uses: actions/setup-java@v1 |
| 44 | + with: |
| 45 | + java-version: 11 |
| 46 | + - name: Build and Analyze |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 50 | + run: mvn -B verify sonar:sonar |
| 51 | + |
| 52 | + publish: |
| 53 | + if: "!contains(github.event.head_commit.message, '[version bump]') && contains(github.ref, 'release')" |
| 54 | + runs-on: ubuntu-latest |
| 55 | + needs: [ test, sonar ] |
| 56 | + steps: |
| 57 | + - name: Checkout project |
| 58 | + uses: actions/checkout@v2 |
| 59 | + |
| 60 | + - name: Setup Build Cache |
| 61 | + uses: actions/cache@v1 |
| 62 | + with: |
| 63 | + path: ~/.m2/repository |
| 64 | + key: ${{ runner.os }}-m2 |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-m2 |
| 67 | +
|
| 68 | + - name: Set up JDK 11 |
| 69 | + uses: actions/setup-java@v1 |
| 70 | + with: |
| 71 | + java-version: 11 |
| 72 | + |
| 73 | + - name: Configure Git user |
| 74 | + run: | |
| 75 | + git config user.email "actions@github.com" |
| 76 | + git config user.name "GitHub Actions" |
| 77 | +
|
| 78 | + - name: Get version from POM without SNAPSHOT |
| 79 | + run: | |
| 80 | + VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n")) |
| 81 | + echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV |
| 82 | + echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV |
| 83 | + echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV |
| 84 | +
|
| 85 | + - name: Setup release version |
| 86 | + run: | |
| 87 | + NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH))" |
| 88 | + echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV |
| 89 | +
|
| 90 | + - name: Update POM Version |
| 91 | + run: | |
| 92 | + echo "New version is: $NEW_VERSION" |
| 93 | + mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false -B |
| 94 | +
|
| 95 | + - name: Build and Publish |
| 96 | + uses: samuelmeuli/action-maven-publish@v1 |
| 97 | + with: |
| 98 | + maven_args: "-DskipTests=true" |
| 99 | + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 100 | + gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} |
| 101 | + nexus_username: ${{ secrets.NEXUS_USERNAME }} |
| 102 | + nexus_password: ${{ secrets.NEXUS_PASSWORD }} |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + |
| 106 | + - name: Commit files |
| 107 | + run: | |
| 108 | + git commit -m "[version bump]" -a |
| 109 | + git tag -a release-$NEW_VERSION -m "[version bump]" |
| 110 | +
|
| 111 | + - name: Push changes |
| 112 | + uses: ad-m/github-push-action@master |
| 113 | + with: |
| 114 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + branch: ${{ github.ref }} |
| 116 | + |
| 117 | + bump: |
| 118 | + if: "!contains(github.event.head_commit.message, '[version bump]') && contains(github.ref, 'release')" |
| 119 | + runs-on: ubuntu-latest |
| 120 | + needs: [ publish ] |
| 121 | + steps: |
| 122 | + |
| 123 | + - name: Checkout Main Branch |
| 124 | + uses: actions/checkout@v2 |
| 125 | + with: |
| 126 | + ref: main |
| 127 | + - name: Setup Build Cache |
| 128 | + uses: actions/cache@v1 |
| 129 | + with: |
| 130 | + path: ~/.m2/repository |
| 131 | + key: ${{ runner.os }}-m2 |
| 132 | + restore-keys: | |
| 133 | + ${{ runner.os }}-m2 |
| 134 | + - name: Set up JDK 11 |
| 135 | + uses: actions/setup-java@v1 |
| 136 | + with: |
| 137 | + java-version: 11 |
| 138 | + - name: Configure Git user |
| 139 | + run: | |
| 140 | + git config user.email "actions@github.com" |
| 141 | + git config user.name "GitHub Actions" |
| 142 | + - name: Get version from POM without SNAPSHOT |
| 143 | + run: | |
| 144 | + VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n")) |
| 145 | + echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV |
| 146 | + echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV |
| 147 | + echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV |
| 148 | + - name: Bump And Update POM Version to new Development version |
| 149 | + run: | |
| 150 | + NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH+1))-SNAPSHOT" |
| 151 | + echo "New development version is: $NEW_VERSION" |
| 152 | + mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false |
| 153 | + - name: Commit files |
| 154 | + run: | |
| 155 | + git commit -m "[version bump] new dev version" -a |
| 156 | +
|
| 157 | + - name: Push Development Version to Main Branch |
| 158 | + uses: ad-m/github-push-action@master |
| 159 | + with: |
| 160 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + branch: main |
0 commit comments