# Assumes are running using the Ubuntu Codebuild standard image # Makes a test deployment to the SNAPSHOT repository in the package manager # This job is responsible for artifacting the JAR which will have all of the other shared libs stuffed # into it once all platforms are built and artifacted # # NOTE: This script assumes that the AWS CLI-V2 is pre-installed! # - AWS CLI-V2 is a requirement to run this script. version: 0.2 phases: install: commands: - sudo add-apt-repository ppa:openjdk-r/ppa - sudo apt-get update -y - sudo apt-get install openjdk-8-jdk-headless maven -y -f - echo "\nBuild version data:" - echo "\nJava Version:"; java -version - echo "\nMaven Version:"; mvn --version - echo "\n" pre_build: commands: - cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java-v2 - export PKG_VERSION=$(cat $CODEBUILD_SRC_DIR/VERSION) # install settings.xml to ~/.m2/settings.xml - mkdir -p $HOME/.m2 - export CD_SETTINGS=$(aws secretsmanager get-secret-value --secret-id cd/aws-crt-java-settings --query "SecretString" | cut -f2 -d\") - echo $CD_SETTINGS > $HOME/.m2/settings.xml - export ST_PASSWORD=$(aws --query "SecretString" secretsmanager get-secret-value --secret-id cd/Sonatype/JIRA/Password | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') # Use the password from secret manager to update the settings - sed -i 's/password-to-replace/'"$ST_PASSWORD"'/g' $HOME/.m2/settings.xml # import gpg key - export CD_KEY=$(aws secretsmanager get-secret-value --secret-id cd/aws-crt-java-key --query "SecretString" | cut -f2 -d\") - echo $CD_KEY > /tmp/aws-sdk-common-runtime.key.asc - gpg --batch --import /tmp/aws-sdk-common-runtime.key.asc - export GPG_PASSPHRASE=$(aws --query "SecretString" secretsmanager get-secret-value --secret-id cd/aws-crt-java-key/password | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') # Java 17 needs special JDK options apparently. It is a known Sonatype issue. # Issue link: https://issues.sonatype.org/browse/NEXUS-27902 - export JDK_JAVA_OPTIONS='--add-opens java.base/java.util=ALL-UNNAMED' build: commands: - cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java-v2/sdk # update the CRT dependency to the latest released version - mvn -B versions:use-latest-versions -Dincludes=software.amazon.awssdk.crt* # update the version to match the git tag, make a snapshot version we can test - mvn -B versions:set -DnewVersion=${PKG_VERSION}-SNAPSHOT # do a full build/deploy, but skip tests, since the shared libs were artifacts above - mvn -B deploy -Prelease -Dmaven.test.skip=true -Dgpg.passphrase=$GPG_PASSPHRASE # update the version to match the git tag, make a staging release which we will release once snapshot testing passes - mvn -B versions:set -DnewVersion=${PKG_VERSION} - mvn -B deploy -Prelease -Dmaven.test.skip=true -Dgpg.passphrase=$GPG_PASSPHRASE | tee /tmp/deploy.log - cat /tmp/deploy.log | grep "Created staging repository with ID" | cut -d\" -f2 | tee /tmp/repositoryId.txt # Store the repository ID in a secret for use later - aws secretsmanager update-secret --secret-id cd/aws-iot-device-sdk-java-v2/repository-id --secret-string "$(cat /tmp/repositoryId.txt)" --region us-east-1 artifacts: discard-paths: yes files: - $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java-v2/target/aws-crt-*.jar - $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java-v2/target/aws-crt-*.asc - /tmp/repositoryId.txt cache: paths: - "/root/.m2/**/*"