|
| 1 | +name: Release Java Lambda layer |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: The version to tag the lambda release with, e.g., 1.2.0 |
| 8 | + required: true |
| 9 | + aws_region: |
| 10 | + description: 'Deploy to aws regions' |
| 11 | + required: true |
| 12 | + default: 'us-east-1, us-east-2, us-west-1, us-west-2, ap-south-1, ap-northeast-3, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-northeast-1, ca-central-1, eu-central-1, eu-west-1, eu-west-2, eu-west-3, eu-north-1, sa-east-1, af-south-1, ap-east-1, ap-south-2, ap-southeast-3, ap-southeast-4, eu-central-2, eu-south-1, eu-south-2, il-central-1, me-central-1, me-south-1' |
| 13 | + |
| 14 | +env: |
| 15 | + COMMERCIAL_REGIONS: us-east-1, us-east-2, us-west-1, us-west-2, ap-south-1, ap-northeast-3, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-northeast-1, ca-central-1, eu-central-1, eu-west-1, eu-west-2, eu-west-3, eu-north-1, sa-east-1 |
| 16 | + LAYER_NAME: AWSOpenTelemetryDistroJava |
| 17 | + |
| 18 | +permissions: |
| 19 | + id-token: write |
| 20 | + contents: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-layer: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + aws_regions_json: ${{ steps.set-matrix.outputs.aws_regions_json }} |
| 27 | + steps: |
| 28 | + - name: Set up regions matrix |
| 29 | + id: set-matrix |
| 30 | + run: | |
| 31 | + IFS=',' read -ra REGIONS <<< "${{ github.event.inputs.aws_region }}" |
| 32 | + MATRIX="[" |
| 33 | + for region in "${REGIONS[@]}"; do |
| 34 | + trimmed_region=$(echo "$region" | xargs) |
| 35 | + MATRIX+="\"$trimmed_region\"," |
| 36 | + done |
| 37 | + MATRIX="${MATRIX%,}]" |
| 38 | + echo ${MATRIX} |
| 39 | + echo "aws_regions_json=${MATRIX}" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Checkout Repo @ SHA - ${{ github.sha }} |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - uses: actions/setup-java@v4 |
| 45 | + with: |
| 46 | + java-version: 17 |
| 47 | + distribution: 'temurin' |
| 48 | + |
| 49 | + - name: Build layers |
| 50 | + working-directory: lambda-layer |
| 51 | + run: | |
| 52 | + ./build-layer.sh |
| 53 | +
|
| 54 | + - name: Upload layer |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: aws-opentelemetry-java-layer.zip |
| 58 | + path: lambda-layer/build/distributions/aws-opentelemetry-java-layer.zip |
| 59 | + |
| 60 | + publish-prod: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: build-layer |
| 63 | + strategy: |
| 64 | + matrix: |
| 65 | + aws_region: ${{ fromJson(needs.build-layer.outputs.aws_regions_json) }} |
| 66 | + steps: |
| 67 | + - name: role arn |
| 68 | + env: |
| 69 | + COMMERCIAL_REGIONS: ${{ env.COMMERCIAL_REGIONS }} |
| 70 | + run: | |
| 71 | + COMMERCIAL_REGIONS_ARRAY=(${COMMERCIAL_REGIONS//,/ }) |
| 72 | + FOUND=false |
| 73 | + for REGION in "${COMMERCIAL_REGIONS_ARRAY[@]}"; do |
| 74 | + if [[ "$REGION" == "${{ matrix.aws_region }}" ]]; then |
| 75 | + FOUND=true |
| 76 | + break |
| 77 | + fi |
| 78 | + done |
| 79 | + if [ "$FOUND" = true ]; then |
| 80 | + echo "Found ${{ matrix.aws_region }} in COMMERCIAL_REGIONS" |
| 81 | + SECRET_KEY="LAMBDA_LAYER_RELEASE" |
| 82 | + else |
| 83 | + echo "Not found ${{ matrix.aws_region }} in COMMERCIAL_REGIONS" |
| 84 | + SECRET_KEY="${{ matrix.aws_region }}_LAMBDA_LAYER_RELEASE" |
| 85 | + fi |
| 86 | + SECRET_KEY=${SECRET_KEY//-/_} |
| 87 | + echo "SECRET_KEY=${SECRET_KEY}" >> $GITHUB_ENV |
| 88 | +
|
| 89 | + - uses: aws-actions/[email protected] |
| 90 | + with: |
| 91 | + role-to-assume: ${{ secrets[env.SECRET_KEY] }} |
| 92 | + role-duration-seconds: 1200 |
| 93 | + aws-region: ${{ matrix.aws_region }} |
| 94 | + |
| 95 | + - name: Get s3 bucket name for release |
| 96 | + run: | |
| 97 | + echo BUCKET_NAME=java-lambda-layer-${{ github.run_id }}-${{ matrix.aws_region }} | tee --append $GITHUB_ENV |
| 98 | +
|
| 99 | + - name: download layer.zip |
| 100 | + uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + name: aws-opentelemetry-java-layer.zip |
| 103 | + |
| 104 | + - name: publish |
| 105 | + run: | |
| 106 | + aws s3 mb s3://${{ env.BUCKET_NAME }} |
| 107 | + aws s3 cp aws-opentelemetry-java-layer.zip s3://${{ env.BUCKET_NAME }} |
| 108 | + layerARN=$( |
| 109 | + aws lambda publish-layer-version \ |
| 110 | + --layer-name ${{ env.LAYER_NAME }} \ |
| 111 | + --content S3Bucket=${{ env.BUCKET_NAME }},S3Key=aws-opentelemetry-java-layer.zip \ |
| 112 | + --compatible-runtimes java17 java21 \ |
| 113 | + --compatible-architectures "arm64" "x86_64" \ |
| 114 | + --license-info "Apache-2.0" \ |
| 115 | + --description "AWS Distro of OpenTelemetry Lambda Layer for Java Runtime" \ |
| 116 | + --query 'LayerVersionArn' \ |
| 117 | + --output text |
| 118 | + ) |
| 119 | + echo $layerARN |
| 120 | + echo "LAYER_ARN=${layerARN}" >> $GITHUB_ENV |
| 121 | + mkdir ${{ env.LAYER_NAME }} |
| 122 | + echo $layerARN > ${{ env.LAYER_NAME }}/${{ matrix.aws_region }} |
| 123 | + cat ${{ env.LAYER_NAME }}/${{ matrix.aws_region }} |
| 124 | +
|
| 125 | + - name: public layer |
| 126 | + run: | |
| 127 | + layerVersion=$( |
| 128 | + aws lambda list-layer-versions \ |
| 129 | + --layer-name ${{ env.LAYER_NAME }} \ |
| 130 | + --query 'max_by(LayerVersions, &Version).Version' |
| 131 | + ) |
| 132 | + aws lambda add-layer-version-permission \ |
| 133 | + --layer-name ${{ env.LAYER_NAME }} \ |
| 134 | + --version-number $layerVersion \ |
| 135 | + --principal "*" \ |
| 136 | + --statement-id publish \ |
| 137 | + --action lambda:GetLayerVersion |
| 138 | +
|
| 139 | + - name: upload layer arn artifact |
| 140 | + if: ${{ success() }} |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: ${{ env.LAYER_NAME }} |
| 144 | + path: ${{ env.LAYER_NAME }}/${{ matrix.aws_region }} |
| 145 | + |
| 146 | + - name: clean s3 |
| 147 | + if: always() |
| 148 | + run: | |
| 149 | + aws s3 rb --force s3://${{ env.BUCKET_NAME }} |
| 150 | +
|
| 151 | + generate-release-note: |
| 152 | + runs-on: ubuntu-latest |
| 153 | + needs: publish-prod |
| 154 | + steps: |
| 155 | + - name: Checkout Repo @ SHA - ${{ github.sha }} |
| 156 | + uses: actions/checkout@v4 |
| 157 | + - uses: hashicorp/setup-terraform@v2 |
| 158 | + - name: download layerARNs |
| 159 | + uses: actions/download-artifact@v4 |
| 160 | + with: |
| 161 | + pattern: ${{ env.LAYER_NAME }}-* |
| 162 | + path: ${{ env.LAYER_NAME }} |
| 163 | + merge-multiple: true |
| 164 | + - name: show layerARNs |
| 165 | + run: | |
| 166 | + for file in ${{ env.LAYER_NAME }}/* |
| 167 | + do |
| 168 | + echo $file |
| 169 | + cat $file |
| 170 | + done |
| 171 | + - name: generate layer-note |
| 172 | + working-directory: ${{ env.LAYER_NAME }} |
| 173 | + run: | |
| 174 | + echo "| Region | Layer ARN |" >> ../layer-note |
| 175 | + echo "| ---- | ---- |" >> ../layer-note |
| 176 | + for file in * |
| 177 | + do |
| 178 | + read arn < $file |
| 179 | + echo "| " $file " | " $arn " |" >> ../layer-note |
| 180 | + done |
| 181 | + cat ../layer-note |
| 182 | + - name: generate tf layer |
| 183 | + working-directory: ${{ env.LAYER_NAME }} |
| 184 | + run: | |
| 185 | + echo "locals {" >> ../layer_arns.tf |
| 186 | + echo " sdk_layer_arns = {" >> ../layer_arns.tf |
| 187 | + for file in * |
| 188 | + do |
| 189 | + read arn < $file |
| 190 | + echo " \""$file"\" = \""$arn"\"" >> ../layer_arns.tf |
| 191 | + done |
| 192 | + cd .. |
| 193 | + echo " }" >> layer_arns.tf |
| 194 | + echo "}" >> layer_arns.tf |
| 195 | + terraform fmt layer_arns.tf |
| 196 | + cat layer_arns.tf |
| 197 | + - name: download layer.zip |
| 198 | + uses: actions/download-artifact@v4 |
| 199 | + with: |
| 200 | + name: layer.zip |
| 201 | + - name: Get commit hash |
| 202 | + id: commit |
| 203 | + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 204 | + - name: Create Release Notes |
| 205 | + run: | |
| 206 | + echo "AWS OpenTelemetry Lambda Layer for Java version ${{ github.event.inputs.version }}-${{ steps.commit.outputs.sha_short }}" > release_notes.md |
| 207 | + echo "" >> release_notes.md |
| 208 | + echo "" >> release_notes.md |
| 209 | + echo "See new Lambda Layer ARNs:" >> release_notes.md |
| 210 | + echo "" >> release_notes.md |
| 211 | + cat layer-note >> release_notes.md |
| 212 | + echo "" >> release_notes.md |
| 213 | + echo "Notes:" >> release_notes.md |
| 214 | + - name: Create GH release |
| 215 | + id: create_release |
| 216 | + env: |
| 217 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 218 | + run: | |
| 219 | + gh release create --target "$GITHUB_REF_NAME" \ |
| 220 | + --title "Release lambda-v${{ github.event.inputs.version }}-${{ steps.commit.outputs.sha_short }}" \ |
| 221 | + --notes-file release_notes.md \ |
| 222 | + --draft \ |
| 223 | + "lambda-v${{ github.event.inputs.version }}-${{ steps.commit.outputs.sha_short }}" \ |
| 224 | + layer_arns.tf layer.zip |
| 225 | + echo Removing release_notes.md ... |
| 226 | + rm -f release_notes.md |
| 227 | + - name: Upload layer.zip and SHA-256 checksum to SDK Release Notes (tagged with latest) |
| 228 | + env: |
| 229 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 230 | + run: | |
| 231 | + LATEST_SDK_VERSION=$(gh release list --repo "aws-observability/aws-otel-java-instrumentation" --json tagName,isLatest -q 'map(select(.isLatest==true)) | .[0].tagName') |
| 232 | + # Generate SHA-256 checksum for layer.zip |
| 233 | + shasum -a 256 layer.zip > layer.zip.sha256 |
| 234 | + # Upload layer.zip and its checksum to the latest SDK release note |
| 235 | + gh release upload "$LATEST_SDK_VERSION" layer.zip layer.zip.sha256 --repo "aws-observability/aws-otel-java-instrumentation" --clobber |
| 236 | + echo "✅ layer.zip successfully uploaded to $LATEST_SDK_VERSION in the upstream repo!" |
0 commit comments