Skip to content

Commit cc3aef6

Browse files
cicd: Rewrite the settings.xml for maven #TASK-7783
1 parent 68138db commit cc3aef6

3 files changed

Lines changed: 196 additions & 28 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# This workflow deploys a Maven project to Sonatype Central using a reusable action.
2+
name: Reusable Sonatype Central Deployment
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
maven_opts:
8+
description: 'Additional Maven CLI options (optional)'
9+
type: string
10+
required: false
11+
secrets:
12+
MAVEN_NEXUS_USER:
13+
description: 'Sonatype Central username (token)'
14+
required: true
15+
MAVEN_NEXUS_PASSWORD:
16+
description: 'Sonatype Central password (token)'
17+
required: true
18+
MAVEN_GPG_PRIVATE_KEY:
19+
description: 'Base64-encoded GPG private key'
20+
required: true
21+
MAVEN_GPG_PASSPHRASE:
22+
description: 'Passphrase for your GPG key'
23+
required: true
24+
25+
jobs:
26+
deploy:
27+
name: Deploy to Sonatype Central
28+
runs-on: ubuntu-22.04
29+
env:
30+
# Allow GPG to access a TTY if needed
31+
GPG_TTY: ${{ runner.tool_cache }}/workspace/.gpg
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
with:
37+
# Fetch full history so tags and versions are available
38+
fetch-depth: 10
39+
40+
- name: Set up Java 8 & Maven cache
41+
uses: actions/setup-java@v4
42+
with:
43+
distribution: 'temurin' # Eclipse Temurin JDK
44+
java-version: '8' # Java 8 compatibility
45+
cache: 'maven' # Cache dependencies
46+
47+
- name: Import GPG private key
48+
# Decode and import your Base64-encoded private key
49+
env:
50+
GPG_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
51+
GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
52+
run: |
53+
echo "$GPG_KEY" | base64 -d > private.key
54+
gpg --batch --import private.key
55+
rm private.key
56+
57+
- name: Generate Maven settings.xml
58+
# Create settings.xml with Sonatype Central credentials & GPG profile
59+
run: |
60+
cat > settings.xml <<EOF
61+
<settings>
62+
<servers>
63+
<server>
64+
<id>central</id>
65+
<username>${{ secrets.MAVEN_NEXUS_USER }}</username>
66+
<password>${{ secrets.MAVEN_NEXUS_PASSWORD }}</password>
67+
</server>
68+
</servers>
69+
<profiles>
70+
<profile>
71+
<id>gpg</id>
72+
<properties>
73+
<gpg.passphrase>${{ secrets.MAVEN_GPG_PASSPHRASE }}</gpg.passphrase>
74+
</properties>
75+
</profile>
76+
</profiles>
77+
</settings>
78+
EOF
79+
80+
- name: Deploy to Central
81+
# A single Maven deploy picks SNAPSHOT vs Release by your POM’s version
82+
run: mvn clean deploy -DskipTests -s settings.xml ${{ inputs.maven_opts }} --no-transfer-progress
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Reusable workflow to deploy in Apache Maven
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
maven_opts:
7+
type: string
8+
required: false
9+
secrets:
10+
MAVEN_NEXUS_USER:
11+
required: true
12+
MAVEN_NEXUS_PASSWORD:
13+
required: true
14+
MAVEN_GPG_PASSPHRASE:
15+
required: true
16+
MAVEN_GPG_PRIVATE_KEY:
17+
required: true
18+
19+
jobs:
20+
deploy-workflow:
21+
name: Deploy to Maven and GitHub Packages
22+
runs-on: ubuntu-22.04
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: '10'
27+
- name: Set up JDK 8
28+
uses: actions/setup-java@v4
29+
with:
30+
distribution: 'temurin'
31+
java-version: '8'
32+
cache: 'maven'
33+
## Future Nacho and Juanfe, please read this very carefully: DO NOT TOUCH!!!
34+
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
35+
server-username: MAVEN_NEXUS_USER # env variable for username in deploy
36+
server-password: MAVEN_NEXUS_PASSWORD # env variable for token in deploy
37+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
38+
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
39+
- name: Deploy to Maven Central repository
40+
run: mvn clean deploy -DskipTests -P deploy-maven ${{ inputs.maven_opts }} --no-transfer-progress
41+
env:
42+
MAVEN_NEXUS_USER: ${{ secrets.MAVEN_USER_TOKEN }}
43+
MAVEN_NEXUS_PASSWORD: ${{ secrets.MAVEN_PASSWORD_TOKEN }}
44+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
45+
- name: Set up Java for publishing to GitHub Packages
46+
uses: actions/setup-java@v4
47+
with:
48+
distribution: 'temurin'
49+
java-version: '8'
50+
- name: Deploy to GitHub Packages repository
51+
run: mvn clean deploy -DskipTests -P deploy-github ${{ inputs.maven_opts }} --no-transfer-progress
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,86 @@
1-
name: Reusable workflow to deploy in Apache Maven
1+
# This workflow deploys a Maven project to Sonatype Central using a reusable action.
2+
name: Reusable Sonatype Central Deployment
23

34
on:
45
workflow_call:
56
inputs:
67
maven_opts:
8+
description: 'Additional Maven CLI options (optional)'
79
type: string
810
required: false
911
secrets:
1012
MAVEN_NEXUS_USER:
13+
description: 'Sonatype Central username (token)'
1114
required: true
1215
MAVEN_NEXUS_PASSWORD:
13-
required: true
14-
MAVEN_GPG_PASSPHRASE:
16+
description: 'Sonatype Central password (token)'
1517
required: true
1618
MAVEN_GPG_PRIVATE_KEY:
19+
description: 'Base64-encoded GPG private key'
20+
required: true
21+
MAVEN_GPG_PASSPHRASE:
22+
description: 'Passphrase for your GPG key'
1723
required: true
1824

1925
jobs:
20-
deploy-workflow:
21-
name: Deploy to Maven and GitHub Packages
26+
deploy:
27+
name: Deploy to Sonatype Central
2228
runs-on: ubuntu-22.04
29+
env:
30+
# Allow GPG to access a TTY if needed
31+
GPG_TTY: ${{ runner.tool_cache }}/workspace/.gpg
32+
2333
steps:
24-
- uses: actions/checkout@v4
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
2536
with:
26-
fetch-depth: '10'
27-
- name: Set up JDK 8
37+
# Fetch full history so tags and versions are available
38+
fetch-depth: 10
39+
40+
- name: Set up Java 8 & Maven cache
2841
uses: actions/setup-java@v4
2942
with:
30-
distribution: 'temurin'
31-
java-version: '8'
32-
cache: 'maven'
33-
## Future Nacho and Juanfe, please read this very carefully: DO NOT TOUCH!!!
34-
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
35-
server-username: MAVEN_NEXUS_USER # env variable for username in deploy
36-
server-password: MAVEN_NEXUS_PASSWORD # env variable for token in deploy
37-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
38-
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
39-
- name: Deploy to Maven Central repository
40-
run: mvn clean deploy -DskipTests -P deploy-maven ${{ inputs.maven_opts }} --no-transfer-progress
43+
distribution: 'temurin' # Eclipse Temurin JDK
44+
java-version: '8' # Java 8 compatibility
45+
cache: 'maven' # Cache dependencies
46+
47+
- name: Import GPG private key
48+
# Decode and import your Base64-encoded private key
4149
env:
42-
MAVEN_NEXUS_USER: ${{ secrets.MAVEN_USER_TOKEN }}
43-
MAVEN_NEXUS_PASSWORD: ${{ secrets.MAVEN_PASSWORD_TOKEN }}
44-
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
45-
- name: Set up Java for publishing to GitHub Packages
46-
uses: actions/setup-java@v4
47-
with:
48-
distribution: 'temurin'
49-
java-version: '8'
50+
GPG_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
51+
GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
52+
run: |
53+
echo "$GPG_KEY" | base64 -d > private.key
54+
gpg --batch --import private.key
55+
rm private.key
56+
57+
- name: Generate Maven settings.xml
58+
# Create settings.xml with Sonatype Central credentials & GPG profile
59+
run: |
60+
cat > settings.xml <<EOF
61+
<settings>
62+
<servers>
63+
<server>
64+
<id>central</id>
65+
<username>${{ secrets.MAVEN_NEXUS_USER }}</username>
66+
<password>${{ secrets.MAVEN_NEXUS_PASSWORD }}</password>
67+
</server>
68+
</servers>
69+
<profiles>
70+
<profile>
71+
<id>gpg</id>
72+
<properties>
73+
<gpg.passphrase>${{ secrets.MAVEN_GPG_PASSPHRASE }}</gpg.passphrase>
74+
</properties>
75+
</profile>
76+
</profiles>
77+
</settings>
78+
EOF
79+
80+
- name: Deploy to Central
81+
# A single Maven deploy picks SNAPSHOT vs Release by your POM’s version
82+
run: mvn clean deploy -DskipTests -P deploy-maven -s settings.xml ${{ inputs.maven_opts }} --no-transfer-progress
5083
- name: Deploy to GitHub Packages repository
5184
run: mvn clean deploy -DskipTests -P deploy-github ${{ inputs.maven_opts }} --no-transfer-progress
5285
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)