Skip to content

Commit eaa110e

Browse files
wangyb-AAlex Wang
andauthored
chore: add maven publish workflow (#158)
* Add maven publish workflow * Include jar in the github release --------- Co-authored-by: Alex Wang <wangyb@amazon.com>
1 parent 429dc03 commit eaa110e

4 files changed

Lines changed: 151 additions & 0 deletions

File tree

.github/scripts/maven_publish.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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: Deploy to Maven Central ==="
44+
45+
mvn clean deploy -s "${SETTINGS_FILE}" -pl sdk -P publishing -DskipTests --no-transfer-progress
46+
mvn clean deploy -s "${SETTINGS_FILE}" -pl sdk-testing -P publishing -DskipTests --no-transfer-progress
47+
48+
echo "=== Release ${RELEASE_VERSION} published successfully! ==="
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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: Build artifacts
63+
run: mvn clean install -q -Dlog4j2.level=WARN -Dlog4j.configurationFile=log4j2-quiet.xml --no-transfer-progress
64+
65+
- name: Create GitHub Release
66+
uses: softprops/action-gh-release@v2
67+
with:
68+
tag_name: v${{ github.event.inputs.release_version }}
69+
name: Release v${{ github.event.inputs.release_version }}
70+
generate_release_notes: true
71+
files: |
72+
sdk/target/aws-durable-execution-sdk-java-${{ github.event.inputs.release_version }}.jar
73+
sdk-testing/target/aws-durable-execution-sdk-java-testing-${{ github.event.inputs.release_version }}.jar
74+
75+
- name: Get Env variables
76+
uses: aws-actions/aws-secretsmanager-get-secrets@v2
77+
with:
78+
secret-ids: |
79+
mvn_gpg_keys
80+
mvn_account_keys
81+
parse-json-secrets: true
82+
83+
- name: Sign and publish
84+
run: bash .github/scripts/maven_publish.sh
85+
env:
86+
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
87+
88+
- name: Set next development version
89+
run: mvn -q versions:set -DnewVersion=${{ github.event.inputs.next_version }} -DgenerateBackupPoms=false
90+
91+
- name: Commit release version
92+
run: |
93+
git add .
94+
git commit -m "chore: bump version to ${{ github.event.inputs.next_version }}"
95+
96+
- name: Push changes
97+
uses: ad-m/github-push-action@master
98+
with:
99+
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)