mirror of https://github.com/smithy-lang/smithy-rs
89 lines
3.1 KiB
Python
Executable File
89 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# This script is a fake `./gradlew aws:sdk:assemble` stand-in for the fake smithy-rs
|
|
# repository created by `create-test-workspace`.
|
|
#
|
|
|
|
import sys
|
|
import subprocess
|
|
import shlex
|
|
import os.path
|
|
|
|
|
|
def get_cmd_output(command):
|
|
result = subprocess.run(shlex.split(command), capture_output=True, check=True)
|
|
return result.stdout.decode("utf-8").strip()
|
|
|
|
|
|
def get_property(name):
|
|
prefix = f"-P{name}="
|
|
for arg in sys.argv:
|
|
if arg.startswith(prefix):
|
|
return arg[len(prefix):]
|
|
return None
|
|
|
|
|
|
def get_examples_revision():
|
|
return get_property("aws.sdk.examples.revision")
|
|
|
|
|
|
def get_previous_release_versions():
|
|
return get_property("aws.sdk.previous.release.versions.manifest")
|
|
|
|
|
|
def get_models_path():
|
|
return get_property("aws.sdk.models.path")
|
|
|
|
|
|
# Fail on the first few attempts to test retry
|
|
if int(get_property("aws.sdk.sync.attempt")) < 3:
|
|
print("Timeout waiting to connect to the Gradle daemon")
|
|
sys.exit(1)
|
|
|
|
# Verify the models path was set correctly
|
|
models_path = get_models_path()
|
|
if models_path is None or not os.path.isfile(f"{models_path}/s3.json"):
|
|
print(f"Missing or wrong aws.sdk.models.path: {models_path}")
|
|
sys.exit(1)
|
|
|
|
# Verify the versions manifest path was set correctly
|
|
previous_release_versions = get_previous_release_versions()
|
|
if previous_release_versions is None or not os.path.exists(previous_release_versions):
|
|
print("Previous release versions file didn't exist")
|
|
sys.exit(1)
|
|
else:
|
|
# Verify its the right file by looking for our special comment
|
|
with open(previous_release_versions, 'r') as file:
|
|
contents = file.read()
|
|
if "# special test comment: this came from the previous release" not in contents:
|
|
print("Wrong previous release versions.toml given to aws:sdk:assemble")
|
|
sys.exit(1)
|
|
|
|
examples_revision = get_examples_revision()
|
|
smithy_rs_revision = get_cmd_output("git rev-parse HEAD")
|
|
smithy_rs_version_commit_hash_override = os.getenv("SMITHY_RS_VERSION_COMMIT_HASH_OVERRIDE")
|
|
if not smithy_rs_version_commit_hash_override:
|
|
print("Missing SMITHY_RS_VERSION_COMMIT_HASH_OVERRIDE env var")
|
|
sys.exit(1)
|
|
|
|
# Emulate generating the versions.toml
|
|
with open("aws/sdk/build/aws-sdk/versions.toml", "w") as versions:
|
|
print(f"smithy_rs_revision = \"{smithy_rs_revision}\"", file=versions)
|
|
print(f"aws_doc_sdk_examples_revision = \"{examples_revision}\"", file=versions)
|
|
|
|
# Emulate generating code from the models by just copying the model into the build artifacts.
|
|
# The model doesn't get copied like this in reality, but this is an easy way to fake it.
|
|
subprocess.run(shlex.split(f"cp {models_path}/s3.json aws/sdk/build/aws-sdk/sdk/s3/"), check=True)
|
|
|
|
# Emulate using the updated endpoints.json by copying it into sdk/verify-endpoints.json.
|
|
subprocess.run(
|
|
shlex.split(f"cp {models_path}/endpoints.json aws/sdk/build/aws-sdk/sdk/verify-endpoints.json"),
|
|
check=True
|
|
)
|
|
|
|
# Emulate copying the examples into the build output
|
|
subprocess.run(shlex.split("cp -r aws/sdk/examples aws/sdk/build/aws-sdk/"), check=True)
|