1
- name : Publish to Maven Central
1
+ # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2
+ # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3
+
4
+ name : Maven Package
2
5
3
6
on :
4
7
push :
5
- branches :
6
- - main
8
+ branches : [main]
7
9
8
10
jobs :
9
- publish :
11
+ build :
12
+
10
13
runs-on : ubuntu-latest
14
+ permissions :
15
+ contents : read
16
+ packages : write
17
+
11
18
steps :
12
- - uses : actions/checkout@v3
13
-
14
- - name : Set up JDK 17
15
- uses : actions/setup-java@v3
16
- with :
17
- java-version : ' 17'
18
- distribution : ' temurin'
19
- server-id : central # Maven settings server id
20
- server-username : ${{ secrets.OSSRH_USERNAME }}
21
- server-password : ${{ secrets.OSSRH_PASSWORD }}
22
- gpg-private-key : ${{ secrets.GPG_PRIVATE_KEY }}
23
- gpg-passphrase : ${{ secrets.GPG_PASSPHRASE }}
24
-
25
- - name : Cache Maven dependencies
26
- uses : actions/cache@v3
27
- with :
28
- path : ~/.m2/repository
29
- key : ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
30
- restore-keys : |
31
- ${{ runner.os }}-m2-
32
-
33
- - name : Setup Maven settings
34
- run : |
35
- mkdir -p ~/.m2
36
- echo "<settings>
37
- <servers>
38
- <server>
39
- <id>central</id>
40
- <username>${{ secrets.OSSRH_USERNAME }}</username>
41
- <password>${{ secrets.OSSRH_PASSWORD }}</password>
42
- </server>
43
- </servers>
44
- </settings>" > ~/.m2/settings.xml
45
-
46
- - name : Import GPG key
47
- run : |
48
- echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
49
- env :
50
- GPG_PRIVATE_KEY : ${{ secrets.GPG_PRIVATE_KEY }}
51
-
52
- - name : Set GPG_TTY
53
- run : echo "export GPG_TTY=$(tty)" >> $GITHUB_ENV
54
-
55
- - name : Reload gpg-agent
56
- run : gpg-connect-agent reloadagent /bye
57
-
58
- - name : Build and Test
59
- run : mvn clean test
60
-
61
- - name : Build and Publish
62
- run : mvn clean deploy -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}
19
+ - uses : actions/checkout@v4
20
+ - name : Set up JDK 17
21
+ uses : actions/setup-java@v4
22
+ with :
23
+ java-version : ' 17'
24
+ distribution : ' temurin'
25
+ server-id : github # Value of the distributionManagement/repository/id field of the pom.xml
26
+ settings-path : ${{ github.workspace }} # location for the settings.xml file
27
+
28
+ - name : Build and Test
29
+ run : mvn clean test
30
+
31
+ - name : Build with Maven
32
+ run : mvn -B package --file pom.xml
33
+
34
+ - name : Publish to GitHub Packages Apache Maven
35
+ run : mvn deploy -s $GITHUB_WORKSPACE/settings.xml
36
+ env :
37
+ GITHUB_TOKEN : ${{ github.token }}
0 commit comments