Skip to content

Commit 2b7f909

Browse files
author
Alex Wang
committed
Add maven publish workflow
1 parent bd511af commit 2b7f909

4 files changed

Lines changed: 148 additions & 0 deletions

File tree

.github/scripts/maven_publish.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#!/bin/bash
3+
# publish-maven.sh
4+
# Builds, signs, and publishes to Maven Central using central-publishing-maven-plugin
5+
set -euo pipefail
6+
7+
SETTINGS_FILE="./settings.xml"
8+
9+
# Auto-cleanup settings.xml on exit (success or failure)
10+
trap 'echo "Cleaning up settings.xml..."; rm -f "${SETTINGS_FILE}"' EXIT
11+
12+
echo "=== Step 1: Format GPG private key ==="
13+
14+
BEGIN_MARKER="-----BEGIN PGP PRIVATE KEY BLOCK-----"
15+
END_MARKER="-----END PGP PRIVATE KEY BLOCK-----"
16+
MIDDLE="${MVN_GPG_KEYS_GPGPRIVATEKEY#*$BEGIN_MARKER}"
17+
MIDDLE="${MIDDLE%$END_MARKER*}"
18+
19+
MIDDLE=$(echo "$MIDDLE" | tr ' ' $'
20+
')
21+
22+
export MAVEN_GPG_KEY="${BEGIN_MARKER}
23+
${MIDDLE}
24+
${END_MARKER}"
25+
26+
export MAVEN_GPG_PASSPHRASE="${MVN_GPG_KEYS_GPGPASSPHRASE}"
27+
28+
echo "=== Step 2: Write minimal settings.xml ==="
29+
cat > "${SETTINGS_FILE}" <<EOF
30+
<settings>
31+
<servers>
32+
<server>
33+
<id>central</id>
34+
<username>${MVN_ACCOUNT_KEYS_USERNAME}</username>
35+
<password>${MVN_ACCOUNT_KEYS_PASSWORD}</password>
36+
</server>
37+
</servers>
38+
</settings>
39+
EOF
40+
41+
echo "settings.xml written."
42+
43+
echo "=== Step 3: Build artifacts ==="
44+
mvn clean install -q -Dlog4j2.level=WARN -Dlog4j.configurationFile=log4j2-quiet.xml --no-transfer-progress
45+
46+
echo "=== Step 4: Deploy to Maven Central ==="
47+
48+
mvn clean deploy -s "${SETTINGS_FILE}" -pl sdk -P publishing -DskipTests --no-transfer-progress
49+
mvn clean deploy -s "${SETTINGS_FILE}" -pl sdk-testing -P publishing -DskipTests --no-transfer-progress
50+
51+
echo "=== Release ${RELEASE_VERSION} published successfully! ==="
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
name: Maven Release
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
release_version:
8+
description: 'Release version (e.g. 1.2.0)'
9+
required: true
10+
type: string
11+
next_version:
12+
description: 'Next development version (e.g. 1.3.0-SNAPSHOT)'
13+
required: true
14+
type: string
15+
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
env:
21+
AWS_REGION: us-west-2
22+
23+
jobs:
24+
release:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Setup Java
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '17'
37+
distribution: 'corretto'
38+
cache: maven
39+
40+
- name: configure aws credentials
41+
uses: aws-actions/configure-aws-credentials@v6
42+
with:
43+
role-to-assume: "${{ secrets.ACTIONS_MVN_ROLE_NAME }}"
44+
role-session-name: mavenreleasesession
45+
aws-region: ${{ env.AWS_REGION }}
46+
47+
- name: Set release version
48+
run: mvn -q versions:set -DnewVersion=${{ github.event.inputs.release_version }} -DgenerateBackupPoms=false
49+
50+
- name: Commit release version
51+
run: |
52+
git config user.email "${{ github.actor }}+github-actions[bot]@users.noreply.github.com"
53+
git config user.name "${{ github.actor }}+github-actions[bot]"
54+
git add .
55+
git commit -m "chore: release version ${{ github.event.inputs.release_version }}"
56+
57+
- name: Push changes
58+
uses: ad-m/github-push-action@master
59+
with:
60+
github_token: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Create GitHub Release
63+
uses: softprops/action-gh-release@v2
64+
with:
65+
tag_name: v${{ github.event.inputs.release_version }}
66+
name: Release v${{ github.event.inputs.release_version }}
67+
generate_release_notes: true
68+
69+
- name: Get Env variables
70+
uses: aws-actions/aws-secretsmanager-get-secrets@v2
71+
with:
72+
secret-ids: |
73+
mvn_gpg_keys
74+
mvn_account_keys
75+
parse-json-secrets: true
76+
77+
- name: Sign and publish
78+
run: bash .github/scripts/maven_publish.sh
79+
env:
80+
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
81+
82+
- name: Set next development version
83+
run: mvn -q versions:set -DnewVersion=${{ github.event.inputs.next_version }} -DgenerateBackupPoms=false
84+
85+
- name: Commit release version
86+
run: |
87+
git add .
88+
git commit -m "chore: bump version to ${{ github.event.inputs.next_version }}"
89+
90+
- name: Push changes
91+
uses: ad-m/github-push-action@master
92+
with:
93+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ buildNumber.properties
2626
# Local testing
2727

2828
.durable-executions-local
29+
.env
2930

3031
# OS
3132
.DS_Store

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@
238238
<goals>
239239
<goal>sign</goal>
240240
</goals>
241+
<configuration>
242+
<signer>bc</signer>
243+
</configuration>
241244
</execution>
242245
</executions>
243246
</plugin>

0 commit comments

Comments
 (0)