Skip to content

Commit 23eab49

Browse files
committed
Implement dual publishing to GitHub packages
1 parent c6e807f commit 23eab49

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ jobs:
104104
runs-on: ubuntu-latest
105105
needs: [prepare-release]
106106
timeout-minutes: 60
107+
permissions:
108+
contents: read
109+
packages: write
107110
steps:
108111
- uses: actions/checkout@v4
109112

@@ -112,20 +115,34 @@ jobs:
112115
git config --global user.email "[email protected]"
113116
git config --global user.name "GitHub Actions"
114117
git pull
118+
119+
- name: Set up JDK
120+
uses: actions/setup-java@v4
121+
with: # running setup-java overwrites the settings.xml
122+
distribution: 'temurin'
123+
java-version: '17'
124+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
125+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Only import once
115126

127+
- name: Publish to Central Portal
128+
run: ../mvnw -B deploy -P publish -DskipTests -DaltDeploymentRepository=github::https://maven.pkg.github.com/${{ github.repository }}
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
132+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
133+
116134
- name: Set up JDK
117135
uses: actions/setup-java@v4
118136
with: # running setup-java again overwrites the settings.xml
119-
java-version: '17'
120137
distribution: 'temurin'
138+
java-version: '17'
121139
server-id: sonatype-central-portal
122140
server-username: MAVEN_CENTRAL_USERNAME
123141
server-password: MAVEN_CENTRAL_TOKEN
124142
gpg-passphrase: MAVEN_GPG_PASSPHRASE
125-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
126143

127144
- name: Publish to Central Portal
128-
run: ../mvnw -B deploy -P publish-sonatype-central-portal -DskipTests
145+
run: ../mvnw -B deploy -P publish,publish-sonatype-central-portal -DskipTests
129146
env:
130147
MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_USERNAME }}
131148
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_TOKEN }}

.github/workflows/test-deploy.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ jobs:
1010
publish-maven:
1111
runs-on: ubuntu-latest
1212
timeout-minutes: 60
13+
permissions:
14+
contents: read
15+
packages: write
1316
steps:
1417
- uses: actions/checkout@v4
18+
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with: # running setup-java overwrites the settings.xml
22+
distribution: 'temurin'
23+
java-version: '17'
24+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
25+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Only import once
26+
27+
- name: Publish to GitHub Packages
28+
run: ../mvnw -B deploy -P publish -DskipTests -DaltDeploymentRepository=github::https://maven.pkg.github.com/${{ github.repository }}
29+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
1533

1634
- name: Set up JDK
1735
uses: actions/setup-java@v4
@@ -22,10 +40,9 @@ jobs:
2240
server-username: MAVEN_CENTRAL_USERNAME
2341
server-password: MAVEN_CENTRAL_TOKEN
2442
gpg-passphrase: MAVEN_GPG_PASSPHRASE
25-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
2643

2744
- name: Publish to Central Portal
28-
run: ../mvnw -B deploy -P publish-sonatype-central-portal -DskipTests
45+
run: ../mvnw -B deploy -P publish,publish-sonatype-central-portal -DskipTests
2946
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
3047
env:
3148
MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_USERNAME }}

template-placeholder/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
</build>
142142
<profiles>
143143
<profile>
144-
<id>publish-sonatype-central-portal</id>
144+
<id>publish</id>
145145
<build>
146146
<plugins>
147147
<plugin>
@@ -183,7 +183,13 @@
183183
</execution>
184184
</executions>
185185
</plugin>
186-
186+
</plugins>
187+
</build>
188+
</profile>
189+
<profile>
190+
<id>publish-sonatype-central-portal</id>
191+
<build>
192+
<plugins>
187193
<plugin>
188194
<groupId>org.sonatype.central</groupId>
189195
<artifactId>central-publishing-maven-plugin</artifactId>

0 commit comments

Comments
 (0)