Skip to content

Commit

Permalink
fix: publishing action
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuslenke committed Jan 12, 2025
1 parent ffc887f commit 99d9e63
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
63 changes: 23 additions & 40 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,26 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- name: Import GPG Key
run: |
echo "${{ secrets.GPG_SIGNING_KEY }}" | base64 --decode | gpg --batch --passphrase "${{ secrets.GPG_PASSWORD }}" --import
gpg --list-secret-keys --keyid-format LONG
- name: Verify Secret Key Import
run: gpg --list-secret-keys --keyid-format LONG

- name: Check GPG Version
run: gpg --version

- name: Configure Maven settings.xml
run: |
cat << EOF > ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${{ secrets.MAVEN_USERNAME }}</username>
<password>${{ secrets.MAVEN_PASSWORD }}</password>
</server>
</servers>
</settings>
EOF
- name: Publish package
run: mvn --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
# https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-maven
# https://github.com/actions/setup-java
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
cache: maven
# https://central.sonatype.org/publish/generate-portal-token/
server-id: central
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Publish to Maven Central Portal
# if autoPublish is false (see pom.xml), we need to publish manually via https://central.sonatype.com/publishing/deployments
run: mvn --batch-mode deploy
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ''
37 changes: 23 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.publishing.version>0.6.0</plugin.publishing.version>
<plugin.gpg.version>3.2.7</plugin.gpg.version>
</properties>

<licenses>
Expand Down Expand Up @@ -122,30 +124,37 @@
</execution>
</executions>
</plugin>
<!-- the following plugins are required for publishing to maven central -->
<!-- https://central.sonatype.org/publish/publish-portal-maven/ -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${plugin.publishing.version}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<!-- visit https://central.sonatype.com/publishing/deployments to publish manually -->
<!-- also visit that site to debug validation issues -->
<autoPublish>false</autoPublish>
</configuration>
</plugin>
<!-- https://central.sonatype.org/publish/publish-maven/#gpg-signed-components -->
<!-- https://maven.apache.org/plugins/maven-gpg-plugin/usage.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<version>${plugin.gpg.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<bestPractices>true</bestPractices>
<!-- set gpg.keyname via command line if necessary (default: first found) -->
</configuration>
</execution>
</executions>
</plugin>
Expand Down

0 comments on commit 99d9e63

Please sign in to comment.