|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +name: Publish Java Package |
| 18 | +# |
| 19 | +# Requirements for this workflow: |
| 20 | +# |
| 21 | +# 1. Secrets must be configured in the repository settings: |
| 22 | +# - OSSRH_USERNAME: The username for Sonatype OSSRH (Maven Central). |
| 23 | +# - OSSRH_TOKEN: The password or token for Sonatype OSSRH. |
| 24 | +# - MAVEN_GPG_PRIVATE_KEY: The ASCII-armored GPG private key for signing artifacts. |
| 25 | +# - MAVEN_GPG_PASSPHRASE: The passphrase for the GPG private key. |
| 26 | +# |
| 27 | +# 2. GPG Key Formatting: |
| 28 | +# - The private key should be exported using: `gpg --armor --export-secret-keys <ID>` |
| 29 | +# - Ensure the key has no empty lines or formatting issues when pasted into GitHub Secrets. |
| 30 | +# |
| 31 | + |
| 32 | +on: |
| 33 | + release: |
| 34 | + types: [created] |
| 35 | + |
| 36 | +jobs: |
| 37 | + publish-java: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: read |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Set up JDK 21 |
| 45 | + uses: actions/setup-java@v4 |
| 46 | + with: |
| 47 | + java-version: '21' |
| 48 | + distribution: 'temurin' |
| 49 | + |
| 50 | + - name: Setup Bazel |
| 51 | + uses: bazelbuild/setup-bazelisk@v3 |
| 52 | + |
| 53 | + - name: Import GPG key |
| 54 | + id: import_gpg |
| 55 | + uses: crazy-max/ghaction-import-gpg@v6 |
| 56 | + with: |
| 57 | + gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 58 | + passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 59 | + |
| 60 | + - name: Publish to Maven Central |
| 61 | + env: |
| 62 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 63 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 64 | + run: | |
| 65 | + ./scripts/publish-java.sh \ |
| 66 | + "${{ steps.import_gpg.outputs.keyring }}" \ |
| 67 | + "${{ secrets.MAVEN_GPG_PASSPHRASE }}" \ |
| 68 | + "$MAVEN_USERNAME" \ |
| 69 | + "$MAVEN_PASSWORD" |
0 commit comments