Skip to content

Commit

Permalink
Add a manually triggered Maven deploy workflow (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkwarren authored Aug 19, 2024
1 parent 3412985 commit 6753535
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
echo $GPG_KEY | base64 --decode > signing-key
gpg --passphrase $GPG_PASSPHRASE --batch --import signing-key
shred signing-key
- name: Configure GIT
run: |
git config --global user.email "[email protected]"
git config --global user.email "[email protected]"
git config --global user.name "envoy-bot"
- name: Set up JDK
Expand All @@ -55,7 +55,7 @@ jobs:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: sonatype-nexus-snapshots
server-id: ossrh
server-username: ${ env.SONATYPE_USER }
server-password: ${ env.SONATYPE_PASSWORD }
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/maven-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
## For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path

name: Maven Manual Deploy

on:
workflow_dispatch:
inputs:
ref:
description: "Git ref to release"
required: true
version:
description: "Maven version to release (without 'v' prefix)"
required: true
deployArgs:
description: "Additional Maven deploy arguments (e.g. '--debug -DautoReleaseAfterClose=false')"
required: false

jobs:
build:
runs-on: ubuntu-latest
env:
SONATYPE_USER: ${{secrets.BUF_SONATYPE_USER}}
SONATYPE_PASSWORD: ${{secrets.BUF_SONATYPE_PASSWORD}}
GPG_KEY_NAME: ${{secrets.GPG_KEY_NAME}}
GPG_PASSPHRASE: ${{secrets.GPG_PASSPHRASE}}
MAVEN_OPTS: "--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED"
REF_NAME: ${{ inputs.ref }}

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Set VERSION variable from tag
run: |
echo "VERSION=${{ inputs.VERSION }}" >> $GITHUB_ENV
- name: 'Configure GPG signing'
env:
GPG_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
# https://github.com/keybase/keybase-issues/issues/2798
export GPG_TTY=$(tty)
# Import gpg keys and warm the passphrase to avoid the gpg
# passphrase prompt when initating a deploy
# `--pinentry-mode=loopback` could be needed to ensure we
# suppress the gpg prompt
echo $GPG_KEY | base64 --decode > signing-key
gpg --passphrase $GPG_PASSPHRASE --batch --import signing-key
shred signing-key
- name: Configure GIT
run: |
git config --global user.email "[email protected]"
git config --global user.name "envoy-bot"
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: ossrh
server-username: ${ env.SONATYPE_USER }
server-password: ${ env.SONATYPE_PASSWORD }
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
gpg-passphrase: ${ env.GPG_PASSPHRASE }

- name: Update version in pom
working-directory: ${{ github.workspace }}/java
run: mvn -B versions:set -DnewVersion=${{ env.VERSION }} -DgenerateBackupPoms=false

- name: Publish to Maven Packages Apache Maven
working-directory: ${{ github.workspace }}/java
run: |
mvn -B -s settings.xml ${{ inputs.deployArgs }} clean deploy \
-Darguments="-s settings.xml" \
-DreleaseVersion=${{ env.VERSION }} \
-DdevelopmentVersion=${{ env.VERSION }}-SNAPSHOT \
-DscmCommentPrefix="java release: "
env:
MAVEN_USERNAME: ${{ env.SONATYPE_USER }}
MAVEN_CENTRAL_TOKEN: ${{ env.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
10 changes: 7 additions & 3 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
Expand Down Expand Up @@ -206,8 +206,12 @@
</scm>

<distributionManagement>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Expand Down
7 changes: 1 addition & 6 deletions java/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${env.SONATYPE_USER}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<id>ossrh</id>
<username>${env.SONATYPE_USER}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
Expand Down

0 comments on commit 6753535

Please sign in to comment.