Skip to content

Commit 47613f5

Browse files
chore: settings.xml from actions/setup-java (#182)
Refactored the Maven setup process to avoid redundant creation of `settings.xml`. This uses the configuration options provided directly within the `setup-java` action. This change reduces duplication and simplifies the workflow for both GitHub Packages and Maven Central publishing.
1 parent 89904a7 commit 47613f5

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

.github/workflows/release.yaml

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,44 @@ jobs:
3535
uses: bufbuild/buf-setup-action@382440cdb8ec7bc25a68d7b4711163d95f7cc3aa
3636
with:
3737
github_token: ${{ secrets.GITHUB_TOKEN }}
38-
- name: Set up JDK
38+
# stage maven profile
39+
- name: Set up JDK to publish to GitHub Packages
40+
if: github.ref == 'refs/heads/main'
3941
uses: actions/setup-java@5896cecc08fd8a1fbdfaf517e29b571164b031f7
4042
with:
4143
java-version: "11"
4244
distribution: "adopt"
43-
server-id: github
44-
server-username: MAVEN_USERNAME
45-
server-password: MAVEN_PASSWORD
45+
# write settings.xml
46+
server-id: github-pkg
47+
server-username: GITHUB_ACTOR
48+
server-password: GITHUB_TOKEN
4649
gpg-private-key: ${{ secrets.GPG_KEY }}
4750
gpg-passphrase: MAVEN_GPG_PASSPHRASE
4851
- name: Publish to GitHub Packages
4952
if: github.ref == 'refs/heads/main'
50-
run: |
51-
mkdir -p $HOME/.m2
52-
cat > $HOME/.m2/settings.xml <<EOF
53-
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54-
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
55-
<servers><server>
56-
<id>github-pkg</id>
57-
<username>${{ env.GITHUB_ACTOR }}</username>
58-
<password>${{ env.GITHUB_TOKEN }}</password>
59-
</server></servers>
60-
</settings>
61-
EOF
62-
mvn --batch-mode deploy -DskipTests -P stage
53+
run: mvn --batch-mode deploy -DskipTests -P stage
6354
env:
55+
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
6456
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6557
BUF_INPUT_HTTPS_USERNAME: opentdf-bot
6658
BUF_INPUT_HTTPS_PASSWORD: ${{ secrets.PERSONAL_ACCESS_TOKEN_OPENTDF }}
6759
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
60+
# release maven profile
61+
- name: Set up JDK to publish to Maven Central
62+
if: startsWith(github.ref, 'refs/tags/')
63+
uses: actions/setup-java@5896cecc08fd8a1fbdfaf517e29b571164b031f7
64+
with:
65+
java-version: "11"
66+
distribution: "adopt"
67+
# write settings.xml
68+
server-id: central
69+
server-username: MAVEN_USERNAME
70+
server-password: MAVEN_PASSWORD
71+
gpg-private-key: ${{ secrets.GPG_KEY }}
72+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
6873
- name: Publish to Maven Central
6974
if: startsWith(github.ref, 'refs/tags/')
70-
run: |
71-
mkdir -p $HOME/.m2
72-
cat > $HOME/.m2/settings.xml <<EOF
73-
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74-
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
75-
<servers><server>
76-
<id>central</id>
77-
<username>${{ secrets.MAVEN_USERNAME }}</username>
78-
<password>${{ secrets.MAVEN_PASSWORD }}</password>
79-
</server></servers>
80-
</settings>
81-
EOF
82-
mvn --batch-mode deploy -DskipTests -P release
75+
run: mvn --batch-mode deploy -DskipTests -P release
8376
env:
8477
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8578
BUF_INPUT_HTTPS_USERNAME: opentdf-bot

0 commit comments

Comments
 (0)