diff --git a/.github/scripts/poll_build_status.sh b/.github/scripts/poll_build_status.sh new file mode 100755 index 000000000..e1c097681 --- /dev/null +++ b/.github/scripts/poll_build_status.sh @@ -0,0 +1,33 @@ +# Polls the provided CodeBuild batch ID until the build terminates +# Script terminates when the build status is not "IN_PROGRESS". +# +# Usage: ./poll_build_status.sh [batch-build-id] + +BUILD_TIMEOUT_MINUTES=120 +POLL_COUNTER=0 + +while [ $POLL_COUNTER -lt $BUILD_TIMEOUT_MINUTES ]; do + BUILD_STATUS=$(aws codebuild batch-get-build-batches \ + --ids "$1" \ + | jq -r --arg BATCH_ID "$1" '.buildBatches[] + | select(.id == $BATCH_ID) + | .buildBatchStatus' ) + + echo "Build status is $BUILD_STATUS after $POLL_COUNTER minutes" + # If build succeeds, exit 0; Github will interpret 'exit 0' as successful job run + if [ "$BUILD_STATUS" == "SUCCEEDED" ]; then + exit 0 + fi + + # If build is not successful nor in-progress, it has either failed, timed-out, faulted, or been stopped. + # Github will interpret 'exit 1' as job failure + if [ "$BUILD_STATUS" != "IN_PROGRESS" ]; then + exit 1 + fi + + ((POLL_COUNTER++)) + sleep 60 +done + +# If job does not report success within BUILD_TIMEOUT_MINUTES, fail Github job +exit 1; \ No newline at end of file diff --git a/.github/scripts/start_codebuild_batch.sh b/.github/scripts/start_codebuild_batch.sh new file mode 100755 index 000000000..9700f822b --- /dev/null +++ b/.github/scripts/start_codebuild_batch.sh @@ -0,0 +1,9 @@ +# Starts a CodeBuild batch with provided source version +# Returns build batch ID for build +# +# Usage: ./start_codebuild_batch.sh [source_version] +aws codebuild start-build-batch \ + --region us-west-2 \ + --project-name AWS-ESDK-Java-CI \ + --source-version "$1" \ + | jq -r '.buildBatch.id' \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43112040b..d0de7c903 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,9 @@ permissions: contents: read jobs: - staticAnalysis: - name: Static Analysis + runCodeBuildCI: + name: Run CodeBuild CI + environment: ci runs-on: ubuntu-latest steps: - name: Configure AWS Credentials @@ -20,93 +21,14 @@ jobs: role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} aws-region: us-west-2 role-duration-seconds: 3600 - - name: Run Static Analysis - uses: aws-actions/aws-codebuild-run-build@v1 - timeout-minutes: 60 - with: - project-name: AWS-ESDK-Java-CI - buildspec-override: codebuild/ci/static-analysis.yml - compute-type-override: BUILD_GENERAL1_MEDIUM - image-override: aws/codebuild/amazonlinux2-x86_64-standard:3.0 - vectorTests: - name: Vector Tests - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - platform: - - distribution: openjdk - image: "aws/codebuild/standard:3.0" - - distribution: corretto - image: "aws/codebuild/amazonlinux2-x86_64-standard:3.0" # Corretto only runs on AL2 - version: [ 8, 11 ] - steps: - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} - aws-region: us-west-2 - role-duration-seconds: 3600 - - name: Vector Tests ${{ matrix.platform.distribution }}${{ matrix.version }} - uses: aws-actions/aws-codebuild-run-build@v1 - timeout-minutes: 60 - with: - project-name: AWS-ESDK-Java-CI - buildspec-override: codebuild/ci/vectors-ci.yml - compute-type-override: BUILD_GENERAL1_LARGE - image-override: ${{ matrix.platform.image }} - env-vars-for-codebuild: JAVA_ENV_VERSION - env: - JAVA_ENV_VERSION: ${{ matrix.platform.distribution }}${{ matrix.version }} - releaseCI: - name: Release CI - runs-on: ubuntu-latest - steps: - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} - aws-region: us-west-2 - role-duration-seconds: 3600 - - name: Release CI - uses: aws-actions/aws-codebuild-run-build@v1 - timeout-minutes: 60 - with: - project-name: AWS-ESDK-Java-CI - buildspec-override: codebuild/ci/release-ci.yml - compute-type-override: BUILD_GENERAL1_LARGE - image-override: aws/codebuild/standard:3.0 - validateCI: - name: Validate CI - runs-on: ubuntu-latest - needs: releaseCI - strategy: - fail-fast: true - matrix: - platform: - - distribution: openjdk - image: "aws/codebuild/standard:3.0" - - distribution: corretto - image: "aws/codebuild/amazonlinux2-x86_64-standard:3.0" # Corretto only runs on AL2 - version: [ 8, 11 ] - steps: - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} - aws-region: us-west-2 - role-duration-seconds: 3600 - - name: Validate CI ${{ matrix.platform.distribution }}${{ matrix.version }} - uses: aws-actions/aws-codebuild-run-build@v1 - timeout-minutes: 60 - with: - project-name: AWS-ESDK-Java-CI - buildspec-override: codebuild/ci/validate-ci.yml - compute-type-override: BUILD_GENERAL1_MEDIUM - image-override: ${{ matrix.platform.image }} - env-vars-for-codebuild: | - JAVA_ENV_VERSION, - JAVA_NUMERIC_VERSION - env: - JAVA_ENV_VERSION: ${{ matrix.platform.distribution }}${{ matrix.version }} - JAVA_NUMERIC_VERSION: ${{ matrix.version }} + - name: Checkout + uses: actions/checkout@v3 + - name: Start CodeBuild Batch Build + run: | + echo "BATCH_ID<> $GITHUB_ENV + ./.github/scripts/start_codebuild_batch.sh ${{ github.sha }} >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + shell: bash + - name: Wait for CodeBuild completion + run: ./.github/scripts/poll_build_status.sh ${{ env.BATCH_ID }} + shell: bash \ No newline at end of file diff --git a/codebuild/ci/ci.yml b/codebuild/ci/ci.yml new file mode 100644 index 000000000..3b74de5a9 --- /dev/null +++ b/codebuild/ci/ci.yml @@ -0,0 +1,89 @@ +version: 0.2 + +# TODO: Replace/Augment build-graph with build-matrix +# Note: It's possible that 9 builds will be running concurrently with the current arrangement + +batch: + fast-fail: false + build-graph: + - identifier: static_analysis + buildspec: codebuild/ci/static-analysis.yml + env: + compute-type: BUILD_GENERAL1_MEDIUM + image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 + ######### Start Vector tests ######### + - identifier: vectors_ci_openjdk8 + buildspec: codebuild/ci/vectors-ci.yml + env: + compute-type: BUILD_GENERAL1_LARGE + variables: + JAVA_ENV_VERSION: openjdk8 + image: aws/codebuild/standard:3.0 + - identifier: vectors_ci_openjdk11 + buildspec: codebuild/ci/vectors-ci.yml + env: + compute-type: BUILD_GENERAL1_LARGE + variables: + JAVA_ENV_VERSION: openjdk11 + image: aws/codebuild/standard:3.0 + - identifier: vectors_ci_corretto8 + buildspec: codebuild/ci/vectors-ci.yml + env: + compute-type: BUILD_GENERAL1_LARGE + variables: + JAVA_ENV_VERSION: corretto8 + image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 + - identifier: vectors_ci_corretto11 + buildspec: codebuild/ci/vectors-ci.yml + env: + compute-type: BUILD_GENERAL1_LARGE + variables: + JAVA_ENV_VERSION: corretto11 + image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 + ######### End Vector tests ######### + - identifier: release_ci + buildspec: codebuild/ci/release-ci.yml + env: + compute-type: BUILD_GENERAL1_LARGE + image: aws/codebuild/standard:3.0 + ######### Start JAR Smoke tests ######### + - identifier: validate_ci_openjdk8 + depend-on: + - release_ci + buildspec: codebuild/ci/validate-ci.yml + env: + variables: + JAVA_ENV_VERSION: openjdk8 + JAVA_NUMERIC_VERSION: 8 + image: aws/codebuild/standard:3.0 + - identifier: validate_ci_openjdk11 + depend-on: + - release_ci + buildspec: codebuild/ci/validate-ci.yml + env: + compute-type: BUILD_GENERAL1_MEDIUM + variables: + JAVA_ENV_VERSION: openjdk11 + JAVA_NUMERIC_VERSION: 11 + image: aws/codebuild/standard:3.0 + - identifier: validate_ci_corretto8 + depend-on: + - release_ci + buildspec: codebuild/ci/validate-ci.yml + env: + compute-type: BUILD_GENERAL1_MEDIUM + variables: + JAVA_ENV_VERSION: corretto8 + JAVA_NUMERIC_VERSION: 8 + image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 + - identifier: validate_ci_corretto11 + depend-on: + - release_ci + buildspec: codebuild/ci/validate-ci.yml + env: + compute-type: BUILD_GENERAL1_MEDIUM + variables: + JAVA_ENV_VERSION: corretto11 + JAVA_NUMERIC_VERSION: 11 + image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 + ######### End JAR Smoke tests ######### \ No newline at end of file