Skip to content

Commit 4422374

Browse files
Update publish-central.yml
1 parent 3b39450 commit 4422374

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed
Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,107 @@
11
name: Publish package to the Maven Central Repository
22

33
on:
4+
push:
5+
branches: [ main, master ]
46
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
616

717
jobs:
8-
release:
9-
name: Release on Sonatype OSS
18+
build-and-test:
19+
name: Build and Test
1020
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
1139

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')
1264
steps:
13-
- uses: actions/checkout@v2
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0
1469

1570
- name: Set up JDK 17
16-
uses: actions/setup-java@v2
71+
uses: actions/setup-java@v4
1772
with:
1873
java-version: 17
19-
distribution: 'adopt'
74+
distribution: 'temurin'
2075

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
2382

2483
- name: Set up Apache Maven Central
25-
uses: actions/setup-java@v2
84+
uses: actions/setup-java@v4
2685
with: # running setup-java again overwrites the settings.xml
2786
java-version: 17
28-
distribution: 'adopt'
29-
server-id: central
87+
distribution: 'temurin'
88+
server-id: ossrh
3089
server-username: OSSRH_USERNAME
3190
server-password: OSSRH_PASSWORD
3291
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
3392
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3493

3594
- name: Publish to Apache Maven Central
36-
run: mvn -Prelease deploy
95+
run: mvn -B -Prelease deploy
3796
env:
3897
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
3998
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
4099
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

Comments
 (0)