Skip to content

Commit 3cfd945

Browse files
authored
Add model building and generate maven publications (#3)
1 parent 56c8953 commit 3cfd945

17 files changed

+1103
-0
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up JDK
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '17'
21+
distribution: 'corretto'
22+
23+
- name: Setup Gradle
24+
uses: gradle/gradle-build-action@v2
25+
26+
- name: Execute Gradle build
27+
run: ./gradlew clean build publish

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Eclipse
2+
.classpath
3+
.project
4+
.settings/
5+
6+
# Intellij
7+
.idea/
8+
*.iml
9+
*.iws
10+
11+
# Fleet
12+
.fleet/
13+
14+
# VSCode
15+
bin/
16+
17+
# Mac
18+
.DS_Store
19+
20+
# Maven
21+
target/
22+
**/dependency-reduced-pom.xml
23+
24+
# Gradle
25+
**/.gradle
26+
build/
27+
*/out/
28+
*/*/out/
29+
/wrapper
30+
31+
# Smithy
32+
.smithy.lsp.log

.scripts/list_services

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
4+
# a script for listing out all services within a directory, and assumes a service will contain a `service/` directory.
5+
# Was used to generate the initial version properties for all services by piping the output into update_versions:
6+
# > .scripts/list_services . | xargs .scripts/update_versions -p gradle.properties -s
7+
8+
# Check if directory is provided
9+
if [ $# -ne 1 ]; then
10+
echo "usage: $0 <directory>" >&2
11+
exit 1
12+
fi
13+
14+
SCAN_DIR="$1"
15+
16+
# Check if the directory exists
17+
if [ ! -d "$SCAN_DIR" ]; then
18+
echo "$0: $SCAN_DIR: No such directory" >&2
19+
exit 1
20+
fi
21+
22+
# Change to the target directory
23+
cd "$SCAN_DIR" || exit 1
24+
25+
# Iterate through all directories, find those with service subdirectory,
26+
# and sort the output
27+
for dir in */; do
28+
if [ -d "${dir}service" ]; then
29+
echo "${dir%/}"
30+
fi
31+
done | sort

.scripts/update_versions

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import logging
5+
from pathlib import Path
6+
from typing import Set
7+
8+
DEFAULT_VERSION = "1.0.0"
9+
10+
logger = logging.getLogger(__name__)
11+
logging.basicConfig(
12+
level=logging.INFO,
13+
format="%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s",
14+
datefmt="%Y-%m-%dT%H:%M:%S",
15+
)
16+
17+
18+
def main(properties_file: Path, projects: Set[str]):
19+
if not properties_file.is_file():
20+
raise ValueError(f"Properties file {properties_file} does not exist")
21+
22+
properties = read_properties(properties_file)
23+
24+
for project in sorted(projects):
25+
project_key = f"model.{project}.version"
26+
if project_key not in properties:
27+
logger.info(
28+
f"Project ({project_key}) not found in properties file, setting to ({DEFAULT_VERSION})"
29+
)
30+
properties[project_key] = DEFAULT_VERSION
31+
else:
32+
version = properties[project_key]
33+
major, minor, patch = version.split(".")
34+
patch = int(patch) + 1
35+
properties[project_key] = f"{major}.{minor}.{patch}"
36+
logger.info(
37+
f"Updated version for ({project_key}) to ({properties[project_key]})"
38+
)
39+
properties[project_key] = properties[project_key]
40+
write_properties(properties_file, properties)
41+
42+
43+
def read_properties(properties_file: Path) -> dict:
44+
lines = properties_file.read_text().split()
45+
# read each line, if it is empty, skip it
46+
properties = {}
47+
for line in lines:
48+
if line.isspace():
49+
continue
50+
# split the line on the first '='
51+
key, value = line.split("=", 1)
52+
properties[key.strip()] = value.strip()
53+
return properties
54+
55+
56+
def write_properties(properties_file: Path, properties: dict):
57+
properties_text = "\n".join([f"{key}={value}" for key, value in properties.items()])
58+
properties_file.write_text(properties_text)
59+
60+
61+
if __name__ == "__main__":
62+
parser = argparse.ArgumentParser(
63+
description="Update versions of service model packages controlled via gradle.properties"
64+
)
65+
66+
parser.add_argument(
67+
"--properties",
68+
"-p",
69+
dest="properties",
70+
type=Path,
71+
required=True,
72+
help="The gradle.properties file that contains the versions.",
73+
)
74+
75+
parser.add_argument(
76+
"--services",
77+
"-s",
78+
dest="services",
79+
type=str,
80+
nargs="+",
81+
required=True,
82+
help="A list of projects to update the versions of.",
83+
)
84+
85+
args = parser.parse_args()
86+
87+
main(args.properties, set(args.services))

build.gradle.kts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
`java-platform`
3+
`maven-publish`
4+
alias(libs.plugins.jreleaser)
5+
id("api-models-aws.publishing-conventions")
6+
}
7+
8+
subprojects {
9+
afterEvaluate {
10+
apply {
11+
plugin("api-models-aws.model-conventions")
12+
}
13+
}
14+
}
15+
16+
// Configuration for the "all" package (which depends on all the subprojects)
17+
dependencies {
18+
constraints {
19+
subprojects.forEach {
20+
api(it)
21+
}
22+
}
23+
}
24+
25+
tasks {
26+
build {
27+
mustRunAfter(clean)
28+
}
29+
}

buildSrc/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
dependencies {
11+
implementation(libs.smithy.gradle.base)
12+
implementation(libs.smithy.gradle.jar)
13+
14+
// https://github.com/gradle/gradle/issues/15383
15+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
16+
}

buildSrc/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.gradle.parallel=true
2+
org.gradle.jvmargs='-Dfile.encoding=UTF-8'

buildSrc/settings.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Ensure version library is available to buildSrc plugins
2+
dependencyResolutionManagement {
3+
versionCatalogs {
4+
create("libs") {
5+
from(files("../gradle/libs.versions.toml"))
6+
}
7+
}
8+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
`java-library`
3+
id("software.amazon.smithy.gradle.smithy-jar")
4+
id("api-models-aws.publishing-conventions")
5+
}
6+
7+
repositories {
8+
mavenLocal()
9+
mavenCentral()
10+
}
11+
12+
//// Workaround per: https://github.com/gradle/gradle/issues/15383
13+
val Project.libs get() = the<org.gradle.accessors.dm.LibrariesForLibs>()
14+
15+
dependencies {
16+
implementation(libs.smithy.aws.cloudformation.traits)
17+
implementation(libs.smithy.aws.endpoints)
18+
implementation(libs.smithy.aws.iam.traits)
19+
implementation(libs.smithy.aws.smoke.test.model)
20+
implementation(libs.smithy.aws.traits)
21+
implementation(libs.smithy.protocol.traits)
22+
implementation(libs.smithy.model)
23+
implementation(libs.smithy.rules.engine)
24+
implementation(libs.smithy.smoke.test.traits)
25+
implementation(libs.smithy.waiters)
26+
}
27+
28+
smithy {
29+
format = false
30+
smithyBuildConfigs.set(project.objects.fileCollection())
31+
}
32+
33+
sourceSets {
34+
main {
35+
smithy {
36+
srcDir(project.projectDir.path + "/service")
37+
}
38+
}
39+
}
40+
41+
tasks {
42+
build {
43+
mustRunAfter(clean)
44+
}
45+
}
46+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
`maven-publish`
3+
}
4+
5+
group = "software.amazon.api.models"
6+
version = project.property("model.${project.name}.version")!!
7+
8+
publishing {
9+
repositories {
10+
// JReleaser's `publish` task publishes to all repositories, so only configure one.
11+
maven {
12+
name = "localStaging"
13+
url = rootProject.layout.buildDirectory.dir("staging").get().asFile.toURI()
14+
}
15+
}
16+
17+
publications {
18+
create<MavenPublication>("maven") {
19+
if (project != rootProject) {
20+
from(components["java"])
21+
} else {
22+
from(components["javaPlatform"])
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)