Skip to content

Commit aff4425

Browse files
authored
Merge pull request #626 from aws/fabisev/automating-mvn-deployment
Fabisev/automating mvn deployment
2 parents 1f8f306 + 8266bb5 commit aff4425

13 files changed

Lines changed: 840 additions & 7 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Configure Maven CodeArtifact mirror
2+
description: Configure Maven to resolve dependencies through the release CodeArtifact repository.
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- shell: bash
8+
run: |
9+
CA_DOMAIN=aws-lambda
10+
CA_REPO=maven-central-store
11+
12+
# Uses the ambient region and caller account.
13+
TOKEN=$(aws codeartifact get-authorization-token \
14+
--domain "$CA_DOMAIN" --query authorizationToken --output text)
15+
echo "::add-mask::$TOKEN"
16+
17+
CA_URL=$(aws codeartifact get-repository-endpoint \
18+
--domain "$CA_DOMAIN" --repository "$CA_REPO" --format maven \
19+
--query repositoryEndpoint --output text)
20+
21+
# <mirrorOf>*</mirrorOf> routes all resolution through the mirror;
22+
# deployment uses distributionManagement and is unaffected.
23+
mkdir -p "$HOME/.m2"
24+
cat > "$HOME/.m2/settings.xml" <<EOF
25+
<settings>
26+
<servers>
27+
<server>
28+
<id>codeartifact-mirror</id>
29+
<username>aws</username>
30+
<password>${TOKEN}</password>
31+
</server>
32+
</servers>
33+
<mirrors>
34+
<mirror>
35+
<id>codeartifact-mirror</id>
36+
<name>release CodeArtifact Maven Central proxy</name>
37+
<url>${CA_URL}</url>
38+
<mirrorOf>*</mirrorOf>
39+
</mirror>
40+
</mirrors>
41+
</settings>
42+
EOF
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Configure AWS credentials for release (OIDC)"
2+
description: >
3+
Assumes the release OIDC role via aws-actions/configure-aws-credentials so the
4+
job can read the signing key and Sonatype token from Secrets Manager. Pinning
5+
of the underlying action lives here so it is updated in one place.
6+
7+
inputs:
8+
aws-region:
9+
description: "AWS region to operate in."
10+
required: true
11+
role-to-assume:
12+
description: "ARN of the OIDC role to assume."
13+
required: true
14+
role-session-name:
15+
description: "Session name for the assumed role (helps distinguish callers in CloudTrail)."
16+
required: true
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
22+
with:
23+
aws-region: ${{ inputs.aws-region }}
24+
role-to-assume: ${{ inputs.role-to-assume }}
25+
role-session-name: ${{ inputs.role-session-name }}
26+
# Short-lived: the job only needs the role briefly to read two secrets.
27+
role-duration-seconds: 300
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "Resolve and validate release version"
2+
description: >
3+
Reads the module POM version (the source of truth), verifies it is a
4+
-SNAPSHOT, and derives the effective release version (the optional override,
5+
or the POM version with -SNAPSHOT stripped). Exports CURRENT_VERSION and
6+
EFFECTIVE_RELEASE_VERSION to the job environment for subsequent steps.
7+
8+
inputs:
9+
module:
10+
description: "Module directory containing the pom.xml to release."
11+
required: true
12+
release-version-override:
13+
description: "Optional release version; defaults to the POM version without -SNAPSHOT."
14+
required: false
15+
default: ""
16+
validate-module-dir:
17+
description: "Fail if the module directory or its pom.xml is missing (use for the choice-driven workflow)."
18+
required: false
19+
default: "false"
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Resolve and validate release version
25+
shell: bash
26+
env:
27+
MODULE: ${{ inputs.module }}
28+
RELEASE_VERSION_OVERRIDE: ${{ inputs.release-version-override }}
29+
VALIDATE_MODULE_DIR: ${{ inputs.validate-module-dir }}
30+
run: |
31+
if [[ "$VALIDATE_MODULE_DIR" == "true" ]]; then
32+
if [[ ! -d "$MODULE" ]]; then
33+
echo "::error::Module directory '$MODULE' does not exist"
34+
exit 1
35+
fi
36+
if [[ ! -f "$MODULE/pom.xml" ]]; then
37+
echo "::error::No pom.xml found in '$MODULE'"
38+
exit 1
39+
fi
40+
fi
41+
42+
# The POM version is the source of truth and must be a SNAPSHOT.
43+
CURRENT_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version --file "$MODULE/pom.xml")
44+
CURRENT_VERSION="${CURRENT_VERSION//[$'\r\n']/}"
45+
if [[ "$CURRENT_VERSION" != *-SNAPSHOT ]]; then
46+
echo "::error::POM version '$CURRENT_VERSION' is not a SNAPSHOT"
47+
exit 1
48+
fi
49+
50+
# Optional override; default strips -SNAPSHOT.
51+
EFFECTIVE_RELEASE_VERSION="${RELEASE_VERSION_OVERRIDE:-${CURRENT_VERSION%-SNAPSHOT}}"
52+
53+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV"
54+
echo "EFFECTIVE_RELEASE_VERSION=$EFFECTIVE_RELEASE_VERSION" >> "$GITHUB_ENV"

0 commit comments

Comments
 (0)