blob: 19468150c0669b4919eb8d805b5017eaeb06eb1b [file] [log] [blame]
Eric Ballb31722a2026-06-09 18:07:26 -07001---
2# SPDX-FileCopyrightText: 2026 The Linux Foundation
3# SPDX-License-Identifier: Apache-2.0
4
5name: Maven Publish
6description: "Build and publish Maven (Java) artifacts to a remote repository"
7
8inputs:
9 java-version:
10 description: "Java version to use"
11 required: false
12 default: "11"
13 java-distribution:
14 description: "Java distribution"
15 required: false
16 default: "temurin"
17 maven-goals:
18 description: "Maven goals to execute"
19 required: false
20 default: "-Prelease clean deploy"
21 maven-settings-file:
22 description: "Path to custom Maven settings.xml"
23 required: false
24 default: ""
25 gpg-private-key:
26 description: "GPG private key for signing"
27 required: false
28 default: ""
29 gpg-passphrase:
30 description: "GPG passphrase"
31 required: false
32 default: ""
33 server-id:
34 description: "Maven server ID for deployment"
35 required: false
36 default: "ossrh"
37 server-username:
38 description: "Maven server username"
39 required: true
40 server-password:
41 description: "Maven server password"
42 required: true
43
44runs:
45 using: "composite"
46 steps:
47 - name: Set up JDK
48 uses: actions/setup-java@v4
49 with:
50 distribution: ${{ inputs.java-distribution }}
51 java-version: ${{ inputs.java-version }}
52 server-id: ${{ inputs.server-id }}
53 server-username: MAVEN_USERNAME
54 server-password: MAVEN_PASSWORD
55 settings-path: ${{ github.workspace }}
56
57 - name: Import GPG key
58 if: inputs.gpg-private-key != ''
59 shell: bash
60 env:
61 GPG_PRIVATE_KEY: ${{ inputs.gpg-private-key }}
62 GPG_PASSPHRASE: ${{ inputs.gpg-passphrase }}
63 run: |
64 set -eu -o pipefail
65 echo "Importing GPG private key..."
66 echo "$GPG_PRIVATE_KEY" | gpg --batch --import
67 echo "GPG key imported successfully"
68 if [ -n "$GPG_PASSPHRASE" ]; then
69 echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf
70 gpgconf --kill gpg-agent
71 gpgconf --launch gpg-agent
72 fi
73
74 - name: Apply custom Maven settings
75 if: inputs.maven-settings-file != ''
76 shell: bash
77 run: |
78 set -eu -o pipefail
79 echo "Using custom Maven settings: ${{ inputs.maven-settings-file }}"
80 cp "${{ inputs.maven-settings-file }}" "${{ github.workspace }}/settings.xml"
81
82 - name: Run Maven
83 shell: bash
84 env:
85 MAVEN_USERNAME: ${{ inputs.server-username }}
86 MAVEN_PASSWORD: ${{ inputs.server-password }}
87 GPG_PASSPHRASE: ${{ inputs.gpg-passphrase }}
88 run: |
89 set -eu -o pipefail
90 MAVEN_ARGS=(-s "${{ github.workspace }}/settings.xml")
91 if [ -n "$GPG_PASSPHRASE" ]; then
92 MAVEN_ARGS+=(-Dgpg.passphrase="$GPG_PASSPHRASE")
93 fi
94 read -r -a MAVEN_GOALS <<< "${{ inputs.maven-goals }}"
95 echo "Running: mvn ${MAVEN_ARGS[*]} ${MAVEN_GOALS[*]}"
96 mvn "${MAVEN_ARGS[@]}" "${MAVEN_GOALS[@]}"