55 branches : [ main ]
66 push :
77 branches : [ main ]
8+ release :
9+ types : [ published ]
810 workflow_dispatch :
911
1012jobs :
1113 build :
1214 runs-on : ubuntu-latest
13- strategy :
14- matrix :
15- java : [11, 17]
1615 steps :
17- - uses : actions/checkout@v3
16+ - name : Check out repository
17+ uses : actions/checkout@v4
1818 - name : Set up JDK
19- uses : actions/setup-java@v3
19+ uses : actions/setup-java@v4
2020 with :
2121 check-latest : true
22- distribution : adopt
22+ distribution : temurin
2323 java-version : ${{ matrix.java }}
24- - uses : actions/cache@v3
24+ - name : Set up cache
25+ uses : actions/cache@v4
2526 env :
2627 cache-name : cache-maven-artifacts
2728 with :
28- path : ~/.m2/repository
29- key : ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
29+ key : xml-toolbox-cache-java-${{ matrix.java }}-${{ github.run_id }}
30+ path : |
31+ ~/.m2/repository
32+ **/target
3033 - name : Build with Maven
31- run : mvn -B verify
34+ run : mvn -B -U clean verify
35+ strategy :
36+ matrix :
37+ java : [11, 17]
38+ publish :
39+ if : (github.event_name == 'push' && contains(github.ref, 'main')) || github.event_name == 'release'
40+ needs : build
41+ runs-on : ubuntu-latest
42+ steps :
43+ - name : Check out repository
44+ uses : actions/checkout@v4
45+ - name : Set up cache
46+ uses : actions/cache@v4
47+ env :
48+ cache-name : cache-maven-artifacts
49+ with :
50+ key : xml-toolbox-cache-java-${{ matrix.java }}-${{ github.run_id }}
51+ path : |
52+ ~/.m2/repository
53+ **/target
54+ - name : Install XML utils
55+ run : sudo apt update && sudo apt install libxml2-utils
56+ - name : Extract project version
57+ run : echo "PROJECT_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)" >> $GITHUB_ENV
58+ # Publish snapshot
59+ - name : Set up JDK 11 for publishing a snapshot
60+ if : github.event_name == 'push' && endswith(env.PROJECT_VERSION, 'SNAPSHOT')
61+ uses : actions/setup-java@v4
62+ with :
63+ check-latest : true
64+ distribution : temurin
65+ java-version : 11
66+ server-id : central
67+ server-password : MAVEN_PASSWORD
68+ server-username : MAVEN_USERNAME
69+ - name : Publish snapshot to the Maven Central Repository
70+ if : github.event_name == 'push' && endswith(env.PROJECT_VERSION, 'SNAPSHOT')
71+ run : mvn -B deploy -DskipTests
72+ env :
73+ MAVEN_PASSWORD : ${{ secrets.CENTRAL_PASSWORD }}
74+ MAVEN_USERNAME : ${{ secrets.CENTRAL_USERNAME }}
75+ # Publish release
76+ - name : Set up JDK 11 for publishing a release
77+ if : github.event_name == 'release' && !endswith(env.PROJECT_VERSION, 'SNAPSHOT')
78+ uses : actions/setup-java@v4
79+ with :
80+ check-latest : true
81+ distribution : temurin
82+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
83+ gpg-private-key : ${{ secrets.GPG_PRIVATE_KEY }}
84+ java-version : 11
85+ server-id : central
86+ server-password : MAVEN_PASSWORD
87+ server-username : MAVEN_USERNAME
88+ - name : Publish release to the Maven Central Repository
89+ if : github.event_name == 'release' && !endswith(env.PROJECT_VERSION, 'SNAPSHOT')
90+ run : mvn -B deploy -DskipTests -Pdeploy
91+ env :
92+ MAVEN_GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
93+ MAVEN_PASSWORD : ${{ secrets.CENTRAL_PASSWORD }}
94+ MAVEN_USERNAME : ${{ secrets.CENTRAL_USERNAME }}
0 commit comments