Skip to content

Commit 2016a67

Browse files
authored
publish codegen artifacts to maven central (#4218)
## Motivation and Context Publish codegen artifacts to Maven Central so users can generate Rust clients + servers without cloning smithy-rs and patching our build files. ## Description * Move dependency management to version catalogs * Move common kotlin and publishing configuration to conventional gradle plugins removing duplication and making a single place to modify this config * Add jreleaser and configure it for releasing to maven central (this seems to be where everyone is landing, smithy team uses it already and Kotlin SDK is migrating) * Introduce tasks for checking if a codegen version exists and if `gradle.properties` has been updated if any codegen project has changed * On release it checks if we need to do a publish * On PR it checks if we modified codegen projects that we have also bumped the version * Rename several modules * `codegen-server/python` -> `codegen-server/codegen-server-python` * `codegen-server/typescript` -> `codegen-server/codegen-server-typescript` * `aws/sdk-codegen` -> `aws/codegen-aws-sdk` ## TODO * ~Need to decide on artifact names. We can probably live with most of them but the python/typescript artifacts don't indicate anything server specific and the `sdk-codegen` one doesn't indicate "AWS SDK" specific. Generally we don't publish the AWS SDK specific codegen but we tied up a lot of the "AWS specific" stuff like sigv in that module so seems like we might need to publish it as well for it to be of use. Open to discussion though.~ * Need to work with @drganjoo on internal testing, in particular need to figure out internal patch file updates needed to land this and versioning scheme * ~Need to finish configuring secrets~ * ~Publish GPG keys, for some reason this is still not working I may need to switch machines to try it on~ * ~Complete additional dry run release testing~ * Test artifacts and document how to use them in a build script to generate code for generic smithy models ## Testing * Basic testing of gradle tasks done against already published artifacts for other codegenerators, seems to be working but may still need refined * Test dry run release * https://github.com/smithy-lang/smithy-rs/actions/runs/16445373815/job/46479485851 ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 13f00bd commit 2016a67

File tree

182 files changed

+910
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+910
-848
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ jobs:
127127
runner: smithy_ubuntu-latest_8-core
128128
- action: check-deterministic-codegen
129129
runner: smithy_ubuntu-latest_8-core
130+
- action: check-codegen-version
131+
runner: ubuntu-latest
130132
steps:
131133
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
132134
- uses: actions/checkout@v4

.github/workflows/dry-run-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ jobs:
4343
CANARY_GITHUB_ACTIONS_ROLE_ARN: ${{ secrets.CANARY_GITHUB_ACTIONS_ROLE_ARN }}
4444
CANARY_STACK_CDK_OUTPUTS_BUCKET_NAME: ${{ secrets.CANARY_STACK_CDK_OUTPUTS_BUCKET_NAME }}
4545
SMITHY_RS_ECR_PUSH_ROLE_ARN: ${{ secrets.SMITHY_RS_ECR_PUSH_ROLE_ARN }}
46+
MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN }}
47+
MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN }}
48+
MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN }}
49+
MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN }}

.github/workflows/prod-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ jobs:
3737
CANARY_GITHUB_ACTIONS_ROLE_ARN: ${{ secrets.CANARY_GITHUB_ACTIONS_ROLE_ARN }}
3838
CANARY_STACK_CDK_OUTPUTS_BUCKET_NAME: ${{ secrets.CANARY_STACK_CDK_OUTPUTS_BUCKET_NAME }}
3939
SMITHY_RS_ECR_PUSH_ROLE_ARN: ${{ secrets.SMITHY_RS_ECR_PUSH_ROLE_ARN }}
40+
MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN }}
41+
MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN }}
42+
MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN }}
43+
MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN }}

.github/workflows/release.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ on:
3939
required: true
4040
SMITHY_RS_ECR_PUSH_ROLE_ARN:
4141
required: true
42+
MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN:
43+
required: true
44+
MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN:
45+
required: true
46+
MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN:
47+
required: true
48+
MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN:
49+
required: true
4250

4351
jobs:
4452
check-actor-for-prod-run:
@@ -273,6 +281,81 @@ jobs:
273281
releaseCommitish: "${{ steps.push-changelog.outputs.commit_sha }}"
274282
});
275283
284+
publish-to-maven-central:
285+
name: Publish Codegen artifacts to Maven Central
286+
needs:
287+
- release
288+
if: always() && needs.release.result == 'success'
289+
runs-on: ubuntu-latest
290+
steps:
291+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
292+
- uses: actions/checkout@v4
293+
with:
294+
path: smithy-rs
295+
ref: ${{ inputs.commit_sha }}
296+
fetch-depth: 0
297+
- name: Set up JDK
298+
uses: actions/setup-java@v4
299+
with:
300+
distribution: temurin
301+
java-version: '17'
302+
- name: Check if publishing is needed
303+
id: check-publish
304+
shell: bash
305+
working-directory: smithy-rs
306+
run: |
307+
# Run the Gradle task to check if publishing is needed
308+
./gradlew checkMavenCentralPublishingNeeded
309+
310+
# Read the result from the build
311+
if grep -q "mavenCentralPublishingNeeded=true" build/maven-central/publishing.properties; then
312+
echo "publish=true" >> $GITHUB_OUTPUT
313+
else
314+
echo "publish=false" >> $GITHUB_OUTPUT
315+
fi
316+
- name: Acquire credentials
317+
if: steps.check-publish.outputs.publish == 'true'
318+
uses: aws-actions/configure-aws-credentials@v4
319+
with:
320+
role-to-assume: ${{ secrets.SMITHY_RS_ECR_PUSH_ROLE_ARN }}
321+
role-session-name: GitHubActions
322+
aws-region: us-west-2
323+
- name: Publish to Maven Central
324+
if: steps.check-publish.outputs.publish == 'true'
325+
shell: bash
326+
working-directory: smithy-rs
327+
env:
328+
GPG_PUBLIC_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY_SECRET_ARN }}
329+
GPG_PRIVATE_KEY_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY_SECRET_ARN }}
330+
GPG_PASSPHRASE_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE_SECRET_ARN }}
331+
SONATYPE_CREDENTIALS_SECRET_ARN: ${{ secrets.MAVEN_CENTRAL_SONATYPE_CREDENTIALS_SECRET_ARN }}
332+
JRELEASER_DRY_RUN: ${{ inputs.dry_run }}
333+
run: |
334+
pwd
335+
# Get secrets from AWS Secrets Manager
336+
GPG_PUBLIC_KEY=$(aws secretsmanager get-secret-value --secret-id $GPG_PUBLIC_KEY_SECRET_ARN --query SecretString --output text)
337+
GPG_PRIVATE_KEY=$(aws secretsmanager get-secret-value --secret-id $GPG_PRIVATE_KEY_SECRET_ARN --query SecretString --output text)
338+
GPG_PASSPHRASE=$(aws secretsmanager get-secret-value --secret-id $GPG_PASSPHRASE_SECRET_ARN --query SecretString --output text)
339+
340+
# Get Sonatype credentials from JSON secret
341+
SONATYPE_CREDS=$(aws secretsmanager get-secret-value --secret-id $SONATYPE_CREDENTIALS_SECRET_ARN --query SecretString --output text)
342+
MAVEN_CENTRAL_USERNAME=$(echo $SONATYPE_CREDS | jq -r '.["sonatype-portal-token-username"]')
343+
MAVEN_CENTRAL_TOKEN=$(echo $SONATYPE_CREDS | jq -r '.["sonatype-portal-token"]')
344+
345+
# Set up JReleaser environment variables
346+
export JRELEASER_GPG_PUBLIC_KEY="$GPG_PUBLIC_KEY"
347+
export JRELEASER_GPG_SECRET_KEY="$GPG_PRIVATE_KEY"
348+
export JRELEASER_GPG_PASSPHRASE="$GPG_PASSPHRASE"
349+
export JRELEASER_MAVENCENTRAL_USERNAME="$MAVEN_CENTRAL_USERNAME"
350+
export JRELEASER_MAVENCENTRAL_TOKEN="$MAVEN_CENTRAL_TOKEN"
351+
export JRELEASER_GENERIC_TOKEN=not-used-but-must-be-set
352+
353+
# Run Gradle publish task to stage outputs to build/m2 directory
354+
./gradlew publish
355+
ls -lsa build/m2/software/amazon/smithy/rust
356+
./gradlew jreleaserConfig
357+
./gradlew jreleaserFullRelease
358+
276359
# If this step fails for any reason, there's no need to retry the release workflow, as this step is auxiliary
277360
# and the release itself was successful. Instead, manually trigger `backport-pull-request.yml`.
278361
open-backport-pull-request:

README.md

Lines changed: 4 additions & 4 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
plugins {
7+
id("smithy-rs.kotlin-conventions")
8+
id("smithy-rs.publishing-conventions")
9+
}
10+
11+
description = "AWS Specific Customizations for Smithy code generation"
12+
extra["displayName"] = "Smithy :: Rust :: AWS Codegen"
13+
extra["moduleName"] = "software.amazon.smithy.rustsdk"
14+
15+
dependencies {
16+
implementation(project(":codegen-core"))
17+
implementation(project(":codegen-client"))
18+
implementation(libs.jsoup)
19+
implementation(libs.smithy.aws.traits)
20+
implementation(libs.smithy.protocol.test.traits)
21+
implementation(libs.smithy.rules.engine)
22+
implementation(libs.smithy.aws.endpoints)
23+
implementation(libs.smithy.smoke.test.traits)
24+
implementation(libs.smithy.aws.smoke.test.model)
25+
26+
27+
implementation(project(":aws:aws-rust-runtime"))
28+
testImplementation(libs.junit.jupiter)
29+
testImplementation(libs.kotest.assertions.core.jvm)
30+
}

0 commit comments

Comments
 (0)