Skip to content

Commit 7d3df08

Browse files
cicd: Update distributionManagement #TASK-7783
1 parent f96de9c commit 7d3df08

3 files changed

Lines changed: 118 additions & 118 deletions

File tree

.github/workflows/deploy-maven-repository-workflow.bkp

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
# Fetch full history so tags and versions are available
34+
fetch-depth: 10
35+
36+
- name: Set up Java 8 & Maven cache
37+
uses: actions/setup-java@v4
38+
with:
39+
distribution: 'temurin' # Eclipse Temurin JDK
40+
java-version: '8' # Java 8 compatibility
41+
cache: 'maven' # Cache dependencies
42+
43+
44+
- name: Configure GPG for loopback pinentry
45+
run: |
46+
mkdir -p ~/.gnupg
47+
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg.conf
48+
chmod 600 ~/.gnupg/gpg.conf
49+
50+
- name: Import GPG private key
51+
env:
52+
GPG_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
53+
run: |
54+
export GPG_TTY=$(tty || echo /dev/console)
55+
echo "$GPG_KEY" > private.key
56+
gpg --batch --pinentry-mode loopback --import private.key
57+
rm private.key
58+
59+
- name: Generate Maven settings.xml
60+
run: |
61+
cat > settings.xml <<EOF
62+
<settings>
63+
<servers>
64+
<server>
65+
<id>ossrh</id>
66+
<username>${{ secrets.MAVEN_NEXUS_USER }}</username>
67+
<password>${{ secrets.MAVEN_NEXUS_PASSWORD }}</password>
68+
</server>
69+
</servers>
70+
<profiles>
71+
<profile>
72+
<id>gpg</id>
73+
<properties>
74+
<gpg.passphrase>${{ secrets.MAVEN_GPG_PASSPHRASE }}</gpg.passphrase>
75+
</properties>
76+
</profile>
77+
</profiles>
78+
<activeProfiles>
79+
<activeProfile>gpg</activeProfile>
80+
</activeProfiles>
81+
</settings>
82+
EOF
83+
84+
- name: Deploy to Central
85+
# A single Maven deploy picks SNAPSHOT vs Release by your POM’s version
86+
run: mvn clean deploy -DskipTests -P deploy-maven -s settings.xml ${{ inputs.maven_opts }} --no-transfer-progress
87+
- name: Deploy to GitHub Packages repository
88+
run: mvn clean deploy -DskipTests -P deploy-github ${{ inputs.maven_opts }} --no-transfer-progress
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,53 @@
1-
# This workflow deploys a Maven project to Sonatype Central using a reusable action.
2-
name: Reusable Sonatype Central Deployment
1+
name: Reusable workflow to deploy in Apache Maven
32

43
on:
54
workflow_call:
65
inputs:
76
maven_opts:
8-
description: 'Additional Maven CLI options (optional)'
97
type: string
108
required: false
119
secrets:
1210
MAVEN_NEXUS_USER:
13-
description: 'Sonatype Central username (token)'
1411
required: true
1512
MAVEN_NEXUS_PASSWORD:
16-
description: 'Sonatype Central password (token)'
17-
required: true
18-
MAVEN_GPG_PRIVATE_KEY:
19-
description: 'Base64-encoded GPG private key'
2013
required: true
2114
MAVEN_GPG_PASSPHRASE:
22-
description: 'Passphrase for your GPG key'
15+
required: true
16+
MAVEN_GPG_PRIVATE_KEY:
2317
required: true
2418

2519
jobs:
26-
deploy:
27-
name: Deploy to Sonatype Central
20+
deploy-workflow:
21+
name: Deploy to Maven and GitHub Packages
2822
runs-on: ubuntu-22.04
2923
steps:
30-
- name: Checkout repository
31-
uses: actions/checkout@v4
24+
- uses: actions/checkout@v4
3225
with:
33-
# Fetch full history so tags and versions are available
34-
fetch-depth: 10
35-
36-
- name: Set up Java 8 & Maven cache
26+
fetch-depth: '10'
27+
- name: Set up JDK 8
3728
uses: actions/setup-java@v4
3829
with:
39-
distribution: 'temurin' # Eclipse Temurin JDK
40-
java-version: '8' # Java 8 compatibility
41-
cache: 'maven' # Cache dependencies
42-
43-
44-
- name: Configure GPG for loopback pinentry
45-
run: |
46-
mkdir -p ~/.gnupg
47-
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg.conf
48-
chmod 600 ~/.gnupg/gpg.conf
49-
50-
- name: Import GPG private key
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
5141
env:
52-
GPG_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
53-
run: |
54-
export GPG_TTY=$(tty || echo /dev/console)
55-
echo "$GPG_KEY" > private.key
56-
gpg --batch --pinentry-mode loopback --import private.key
57-
rm private.key
58-
59-
- name: Generate Maven settings.xml
60-
run: |
61-
cat > settings.xml <<EOF
62-
<settings>
63-
<servers>
64-
<server>
65-
<id>ossrh</id>
66-
<username>${{ secrets.MAVEN_NEXUS_USER }}</username>
67-
<password>${{ secrets.MAVEN_NEXUS_PASSWORD }}</password>
68-
</server>
69-
</servers>
70-
<profiles>
71-
<profile>
72-
<id>gpg</id>
73-
<properties>
74-
<gpg.passphrase>${{ secrets.MAVEN_GPG_PASSPHRASE }}</gpg.passphrase>
75-
</properties>
76-
</profile>
77-
</profiles>
78-
<activeProfiles>
79-
<activeProfile>gpg</activeProfile>
80-
</activeProfiles>
81-
</settings>
82-
EOF
83-
84-
- name: Deploy to Central
85-
# A single Maven deploy picks SNAPSHOT vs Release by your POM’s version
86-
run: mvn clean deploy -DskipTests -P deploy-maven -s settings.xml ${{ inputs.maven_opts }} --no-transfer-progress
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'
8750
- name: Deploy to GitHub Packages repository
8851
run: mvn clean deploy -DskipTests -P deploy-github ${{ inputs.maven_opts }} --no-transfer-progress
8952
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)