#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

C_YELLOW='\033[1;33m'
C_RESET='\033[0m'

set -eux
cd smithy-rs

# Make aws-config (which depends on generated services) available to additional checks
mkdir -p aws/sdk/build
mv ../aws-sdk-smoketest aws/sdk/build/aws-sdk
SDK_PATH="$(git rev-parse --show-toplevel)"/aws/sdk/build/aws-sdk/sdk

pushd tools/ci-cdk/canary-lambda

# The canary-lambda doesn't have a Cargo.toml in a fresh checkout of smithy-rs, so generate one before checks
pushd ../canary-runner
echo "${C_YELLOW}## Generating Cargo.toml for the canary-lambda...${C_RESET}"
cargo run -- build-bundle --manifest-only --canary-path ../canary-lambda --sdk-path "${SDK_PATH}" --musl
popd

# Note: This only checks the `latest` canary, and not any previous version features
echo "${C_YELLOW}## Running 'cargo clippy' for the canary-lambda...${C_RESET}"
cargo clippy

popd
