|
1 | 1 | name: Publish package to the Maven Central Repository
|
2 | 2 |
|
3 | 3 | on:
|
| 4 | + push: |
| 5 | + branches: [ main, master ] |
4 | 6 | pull_request:
|
5 |
| - branches: [ "master" ] |
| 7 | + branches: [ main, master ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: 'Version to deploy (optional, will use pom.xml version if not specified)' |
| 14 | + required: false |
| 15 | + type: string |
6 | 16 |
|
7 | 17 | jobs:
|
8 |
| - release: |
9 |
| - name: Release on Sonatype OSS |
| 18 | + build-and-test: |
| 19 | + name: Build and Test |
10 | 20 | runs-on: ubuntu-latest
|
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Set up JDK 17 |
| 28 | + uses: actions/setup-java@v4 |
| 29 | + with: |
| 30 | + java-version: 17 |
| 31 | + distribution: 'temurin' |
| 32 | + |
| 33 | + - name: Cache Maven packages |
| 34 | + uses: actions/cache@v3 |
| 35 | + with: |
| 36 | + path: ~/.m2 |
| 37 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 38 | + restore-keys: ${{ runner.os }}-m2 |
11 | 39 |
|
| 40 | + - name: Build and test |
| 41 | + run: mvn -B clean verify |
| 42 | + |
| 43 | + - name: Upload test results |
| 44 | + uses: actions/upload-artifact@v3 |
| 45 | + if: always() |
| 46 | + with: |
| 47 | + name: test-results |
| 48 | + path: target/surefire-reports/ |
| 49 | + retention-days: 30 |
| 50 | + |
| 51 | + - name: Upload coverage reports |
| 52 | + uses: actions/upload-artifact@v3 |
| 53 | + if: always() |
| 54 | + with: |
| 55 | + name: coverage-reports |
| 56 | + path: target/site/jacoco/ |
| 57 | + retention-days: 30 |
| 58 | + |
| 59 | + publish: |
| 60 | + name: Publish to Maven Central |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: build-and-test |
| 63 | + if: needs.build-and-test.result == 'success' && (github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch') |
12 | 64 | steps:
|
13 |
| - - uses: actions/checkout@v2 |
| 65 | + - name: Checkout code |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 |
14 | 69 |
|
15 | 70 | - name: Set up JDK 17
|
16 |
| - uses: actions/setup-java@v2 |
| 71 | + uses: actions/setup-java@v4 |
17 | 72 | with:
|
18 | 73 | java-version: 17
|
19 |
| - distribution: 'adopt' |
| 74 | + distribution: 'temurin' |
20 | 75 |
|
21 |
| - - name: Build with Maven |
22 |
| - run: mvn -B package --file pom.xml |
| 76 | + - name: Cache Maven packages |
| 77 | + uses: actions/cache@v3 |
| 78 | + with: |
| 79 | + path: ~/.m2 |
| 80 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 81 | + restore-keys: ${{ runner.os }}-m2 |
23 | 82 |
|
24 | 83 | - name: Set up Apache Maven Central
|
25 |
| - uses: actions/setup-java@v2 |
| 84 | + uses: actions/setup-java@v4 |
26 | 85 | with: # running setup-java again overwrites the settings.xml
|
27 | 86 | java-version: 17
|
28 |
| - distribution: 'adopt' |
29 |
| - server-id: central |
| 87 | + distribution: 'temurin' |
| 88 | + server-id: ossrh |
30 | 89 | server-username: OSSRH_USERNAME
|
31 | 90 | server-password: OSSRH_PASSWORD
|
32 | 91 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
33 | 92 | gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
34 | 93 |
|
35 | 94 | - name: Publish to Apache Maven Central
|
36 |
| - run: mvn -Prelease deploy |
| 95 | + run: mvn -B -Prelease deploy |
37 | 96 | env:
|
38 | 97 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
39 | 98 | OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
40 | 99 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
| 100 | + |
| 101 | + - name: Create Release Tag |
| 102 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' |
| 103 | + run: | |
| 104 | + git config --local user.email "[email protected]" |
| 105 | + git config --local user.name "GitHub Action" |
| 106 | + git tag -a v${{ github.event.inputs.version }} -m "Release version ${{ github.event.inputs.version }}" |
| 107 | + git push origin v${{ github.event.inputs.version }} |
0 commit comments