|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + |
| 7 | +env: |
| 8 | + PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-code: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 30 |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up JDK |
| 22 | + uses: actions/setup-java@v4 |
| 23 | + with: |
| 24 | + java-version: '17' |
| 25 | + distribution: 'temurin' |
| 26 | + cache: 'maven' |
| 27 | + |
| 28 | + - name: Build with Maven |
| 29 | + run: ./mvnw -B clean package -T2C |
| 30 | + |
| 31 | + - name: Check for uncommited changes |
| 32 | + run: | |
| 33 | + if [[ "$(git status --porcelain)" != "" ]]; then |
| 34 | + echo ---------------------------------------- |
| 35 | + echo git status |
| 36 | + echo ---------------------------------------- |
| 37 | + git status |
| 38 | + echo ---------------------------------------- |
| 39 | + echo git diff |
| 40 | + echo ---------------------------------------- |
| 41 | + git diff |
| 42 | + echo ---------------------------------------- |
| 43 | + echo Troubleshooting |
| 44 | + echo ---------------------------------------- |
| 45 | + echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && ./mvnw -B clean package" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + prepare-release: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + needs: [check-code] |
| 52 | + timeout-minutes: 10 |
| 53 | + outputs: |
| 54 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Configure Git |
| 59 | + run: | |
| 60 | + git config --global user.email "[email protected]" |
| 61 | + git config --global user.name "GitHub Actions" |
| 62 | + |
| 63 | + - name: Un-SNAP |
| 64 | + run: | |
| 65 | + mvnwPath=$(readlink -f ./mvnw) |
| 66 | + modules=("") # root |
| 67 | + modules+=($(grep -oP '(?<=<module>)[^<]+' 'pom.xml')) |
| 68 | + for i in "${modules[@]}" |
| 69 | + do |
| 70 | + echo "Processing $i/pom.xml" |
| 71 | + (cd "$i" && $mvnwPath -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false) |
| 72 | + done |
| 73 | + |
| 74 | + - name: Get version |
| 75 | + id: version |
| 76 | + run: | |
| 77 | + version=$(../mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 78 | + echo "release=$version" >> $GITHUB_OUTPUT |
| 79 | + echo "releasenumber=${version//[!0-9]/}" >> $GITHUB_OUTPUT |
| 80 | + working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} |
| 81 | + |
| 82 | + - name: Commit and Push |
| 83 | + run: | |
| 84 | + git add -A |
| 85 | + git commit -m "Release ${{ steps.version.outputs.release }}" |
| 86 | + git push origin |
| 87 | + git tag v${{ steps.version.outputs.release }} |
| 88 | + git push origin --tags |
| 89 | + |
| 90 | + - name: Create Release |
| 91 | + id: create_release |
| 92 | + uses: shogo82148/actions-create-release@v1 |
| 93 | + with: |
| 94 | + tag_name: v${{ steps.version.outputs.release }} |
| 95 | + release_name: v${{ steps.version.outputs.release }} |
| 96 | + commitish: master |
| 97 | + body: | |
| 98 | + ## [Changelog](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) |
| 99 | + See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information. |
| 100 | +
|
| 101 | + ## Installation |
| 102 | + Add the following lines to your pom: |
| 103 | + ```XML |
| 104 | + <dependency> |
| 105 | + <groupId>software.xdev</groupId> |
| 106 | + <artifactId>${{ env.PRIMARY_MAVEN_MODULE }}</artifactId> |
| 107 | + <version>${{ steps.version.outputs.release }}</version> |
| 108 | + </dependency> |
| 109 | + ``` |
| 110 | +
|
| 111 | + publish-maven: |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: [prepare-release] |
| 114 | + timeout-minutes: 60 |
| 115 | + steps: |
| 116 | + - uses: actions/checkout@v4 |
| 117 | + |
| 118 | + - name: Init Git and pull |
| 119 | + run: | |
| 120 | + git config --global user.email "[email protected]" |
| 121 | + git config --global user.name "GitHub Actions" |
| 122 | + git pull |
| 123 | + |
| 124 | + - name: Set up JDK OSSRH |
| 125 | + uses: actions/setup-java@v4 |
| 126 | + with: # running setup-java again overwrites the settings.xml |
| 127 | + java-version: '17' |
| 128 | + distribution: 'temurin' |
| 129 | + server-id: ossrh |
| 130 | + server-username: MAVEN_CENTRAL_USERNAME |
| 131 | + server-password: MAVEN_CENTRAL_TOKEN |
| 132 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 133 | + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 134 | + |
| 135 | + - name: Publish to OSSRH |
| 136 | + run: ../mvnw -B deploy -Possrh -DskipTests |
| 137 | + env: |
| 138 | + MAVEN_CENTRAL_USERNAME: ${{ secrets.S01_OSS_SONATYPE_MAVEN_USERNAME }} |
| 139 | + MAVEN_CENTRAL_TOKEN: ${{ secrets.S01_OSS_SONATYPE_MAVEN_TOKEN }} |
| 140 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 141 | + working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} |
| 142 | + |
| 143 | + publish-pages: |
| 144 | + runs-on: ubuntu-latest |
| 145 | + needs: [prepare-release] |
| 146 | + timeout-minutes: 15 |
| 147 | + steps: |
| 148 | + - uses: actions/checkout@v4 |
| 149 | + |
| 150 | + - name: Init Git and pull |
| 151 | + run: | |
| 152 | + git config --global user.email "[email protected]" |
| 153 | + git config --global user.name "GitHub Actions" |
| 154 | + git pull |
| 155 | +
|
| 156 | + - name: Setup - Java |
| 157 | + uses: actions/setup-java@v4 |
| 158 | + with: |
| 159 | + java-version: '17' |
| 160 | + distribution: 'temurin' |
| 161 | + cache: 'maven' |
| 162 | + |
| 163 | + - name: Build site |
| 164 | + run: ../mvnw -B compile site -DskipTests -T2C |
| 165 | + working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} |
| 166 | + |
| 167 | + - name: Deploy to Github pages |
| 168 | + uses: peaceiris/actions-gh-pages@v4 |
| 169 | + with: |
| 170 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + publish_dir: ./${{ env.PRIMARY_MAVEN_MODULE }}/target/site |
| 172 | + force_orphan: true |
| 173 | + |
| 174 | + after-release: |
| 175 | + runs-on: ubuntu-latest |
| 176 | + needs: [publish-maven] |
| 177 | + timeout-minutes: 10 |
| 178 | + steps: |
| 179 | + - uses: actions/checkout@v4 |
| 180 | + |
| 181 | + - name: Init Git and pull |
| 182 | + run: | |
| 183 | + git config --global user.email "[email protected]" |
| 184 | + git config --global user.name "GitHub Actions" |
| 185 | + git pull |
| 186 | +
|
| 187 | + - name: Inc Version and SNAP |
| 188 | + run: | |
| 189 | + mvnwPath=$(readlink -f ./mvnw) |
| 190 | + modules=("") # root |
| 191 | + modules+=($(grep -oP '(?<=<module>)[^<]+' 'pom.xml')) |
| 192 | + for i in "${modules[@]}" |
| 193 | + do |
| 194 | + echo "Processing $i/pom.xml" |
| 195 | + (cd "$i" && $mvnwPath -B build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false -DnextSnapshot=true -DupdateMatchingVersions=false) |
| 196 | + done |
| 197 | +
|
| 198 | + - name: Git Commit and Push |
| 199 | + run: | |
| 200 | + git add -A |
| 201 | + git commit -m "Preparing for next development iteration" |
| 202 | + git push origin |
| 203 | + |
| 204 | + - name: pull-request |
| 205 | + env: |
| 206 | + GH_TOKEN: ${{ github.token }} |
| 207 | + run: | |
| 208 | + gh_pr_up() { |
| 209 | + gh pr create "$@" || gh pr edit "$@" |
| 210 | + } |
| 211 | + gh_pr_up -B "develop" \ |
| 212 | + --title "Sync back" \ |
| 213 | + --body "An automated PR to sync changes back" |
0 commit comments