Skip to content

Commit

Permalink
Merge pull request #183 from aws/pipeline
Browse files Browse the repository at this point in the history
Continuous Delivery:
Added scripts for Continuous Delivery and provide version stamping,
Used a higher version of nexus-staging-maven-plugin to fix release issue
  • Loading branch information
xiazhvera authored Apr 27, 2022
2 parents 93d4f29 + 7caf4b3 commit 028b60b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 8 deletions.
4 changes: 2 additions & 2 deletions aws-iot-device-sdk-java-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-pom</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
</parent>
<artifactId>aws-iot-device-sdk-java-samples</artifactId>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Expand Down
4 changes: 2 additions & 2 deletions aws-iot-device-sdk-java-samples/samples-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-samples</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -12,7 +12,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
2 changes: 1 addition & 1 deletion aws-iot-device-sdk-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-pom</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
</parent>
<artifactId>aws-iot-device-sdk-java</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
@Setter
public class AwsIotMqttConnection extends AwsIotConnection {

private static final String USERNAME_METRIC_STRING = "?SDK=Java&Version=1.3.9";
// Release Script will replace the version string on release. Refer to codebuild/cd/promote-release.yml
private static final String USERNAME_METRIC_STRING = "?SDK=Java&Version=0.0.1-dev";
private final SocketFactory socketFactory;

private MqttAsyncClient mqttClient;
Expand Down
58 changes: 58 additions & 0 deletions codebuild/cd/promote-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 0.2
#this buildspec assumes the ubuntu 16.04:x64 image
# 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
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
- sudo apt-get install jq -y
# need latest awscli for secretsmanager
- sudo pip3 install awscli --upgrade

pre_build:
commands:
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java
- export PKG_VERSION=$(git describe --tags | cut -f2 -dv)
- echo PKG_VERSION=$PKG_VERSION
# Set version to PKG_VERSION
- sed -i 's/0.0.1-dev/'"$PKG_VERSION"'/g' pom.xml
- sed -i 's/0.0.1-dev/'"$PKG_VERSION"'/g' aws-iot-device-sdk-java/pom.xml
- sed -i 's/0.0.1-dev/'"$PKG_VERSION"'/g' aws-iot-device-sdk-java-samples/pom.xml
- sed -i 's/0.0.1-dev/'"$PKG_VERSION"'/g' aws-iot-device-sdk-java/src/main/java/com/amazonaws/services/iot/client/mqtt/AwsIotMqttConnection.java
# Get java v1 gpg files
- aws s3 cp --recursive s3://code-sharing-aws-crt/gpg-java-v1/ maven-gpg
# manully copy the maven-gpg in subfolder, since codeBuild does not set localRepository correctly
- cp -r maven-gpg aws-iot-device-sdk-java/maven-gpg
- cp -r maven-gpg aws-iot-device-sdk-java-samples/maven-gpg
# install settings.xml to ~/.m2/settings.xml
- mkdir -p $HOME/.m2
- aws s3 cp s3://code-sharing-aws-crt/iot-sdk-java-v1.settings.xml $HOME/.m2/settings.xml
- aws --query "SecretString" secretsmanager get-secret-value --secret-id Sonatype/JIRA/Password/V1 > sonatype_secret
- jq fromjson sonatype_secret > sonatype_json
- export ST_PASSWORD=$(jq -r '.password' sonatype_json)
- export ST_USERNAME=$(jq -r '.username' sonatype_json)
- aws --query "SecretString" secretsmanager get-secret-value --secret-id gpg/IoT/JAVA/V1 > gpg_secret
- jq fromjson gpg_secret > gpg_json
- export GPG_PRINCIPAL=$(jq -r '.username' gpg_json)
- export GPG_CREDENTIAL=$(jq -r '.password' gpg_json)
# Use the password from secret manager to update the settings
- sed -i 's/sonatype_Principal/'"$ST_USERNAME"'/g' $HOME/.m2/settings.xml
- sed -i 's/sonatype_Credential/'"$ST_PASSWORD"'/g' $HOME/.m2/settings.xml
- sed -i 's/gpg_Principal/'"$GPG_PRINCIPAL"'/g' $HOME/.m2/settings.xml
- sed -i 's/gpg_Credential/'"$GPG_CREDENTIAL"'/g' $HOME/.m2/settings.xml


build:
commands:
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java
# Trigger the release of the last staged package in the staging repository
- mvn -s $HOME/.m2/settings.xml clean package -Dmaven.test.skip=true
- mvn -s $HOME/.m2/settings.xml clean deploy -P publishing -e -X
- mvn -s $HOME/.m2/settings.xml nexus-staging:release -e -X

cache:
paths:
- "/root/.m2/**/*"
23 changes: 23 additions & 0 deletions codebuild/cd/test-version-exists.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
set -x
# force a failure if there's no tag
git describe --tags
# now get the tag
CURRENT_TAG=$(git describe --tags | cut -f2 -dv)
# convert v0.2.12-2-g50254a9 to 0.2.12
CURRENT_TAG_VERSION=$(git describe --tags | cut -f1 -d'-' | cut -f2 -dv)
# if there's a hash on the tag, then this is not a release tagged commit
if [ "$CURRENT_TAG" != "$CURRENT_TAG_VERSION" ]; then
echo "Current tag version is not a release tag, cut a new release if you want to publish."
exit 1
fi

PUBLISHED_TAG_VERSION=$(curl -s "https://repo.maven.apache.org/maven2/com/amazonaws/aws-iot-device-sdk-java/maven-metadata.xml" | grep "<latest>" | cut -f2 -d ">" | cut -f1 -d "<")
if [ "$PUBLISHED_TAG_VERSION" == "$CURRENT_TAG_VERSION" ]; then
echo "$CURRENT_TAG_VERSION is already in Sonatype, cut a new tag if you want to upload another version."
exit 1
fi

echo "$CURRENT_TAG_VERSION currently does not exist in Sonatype, allowing pipeline to continue."
exit 0
10 changes: 10 additions & 0 deletions codebuild/cd/test-version-exists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 0.2
#this build spec assumes the ubuntu 16.04:x64 image
#this build run simply verifies we haven't published something at this tag yet.
#if we have we fail the build and stop the pipeline, if we haven't we allow the pipeline to run.
phases:
build:
commands:
- cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-java
- bash ./codebuild/cd/test-version-exists.sh

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-pom</artifactId>
<version>1.3.9</version>
<version>0.0.1-dev</version>
<packaging>pom</packaging>
<name>AWS IoT Device SDK for Java</name>
<description>The AWS IoT Device SDK for Java provides Java APIs for devices to connect to AWS IoT service using the MQTT protocol. The SDK also provides support for AWS IoT specific features, such as Thing Shadow and Thing Shadow abstraction.</description>
Expand Down Expand Up @@ -45,7 +45,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down

0 comments on commit 028b60b

Please sign in to comment.