Skip to content

Commit f15db8b

Browse files
committed
migrate Lambda release workflow to SDK release
1 parent a197685 commit f15db8b

File tree

2 files changed

+243
-270
lines changed

2 files changed

+243
-270
lines changed

.github/workflows/release-build.yml

Lines changed: 243 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
version:
66
description: The version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1
77
required: true
8+
aws_region:
9+
description: 'Deploy lambda layer to aws regions'
10+
required: true
11+
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, ap-southeast-5, ap-southeast-7, mx-central-1, ca-west-1, cn-north-1, cn-northwest-1'
812

913
env:
1014
AWS_PUBLIC_ECR_REGION: us-east-1
@@ -13,7 +17,9 @@ env:
1317
PUBLIC_REPOSITORY: public.ecr.aws/aws-observability/adot-autoinstrumentation-java
1418
PRIVATE_REPOSITORY: 020628701572.dkr.ecr.us-west-2.amazonaws.com/adot-autoinstrumentation-java
1519
PRIVATE_REGISTRY: 020628701572.dkr.ecr.us-west-2.amazonaws.com
16-
ARTIFACT_NAME: aws-opentelemetry-agent.jar
20+
ARTIFACT_NAME: aws-opentelemetry-agent.jar
21+
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, ap-southeast-5, ap-southeast-7, mx-central-1, ca-west-1, cn-north-1, cn-northwest-1
22+
LAYER_NAME: AWSOpenTelemetryDistroJava
1723

1824
permissions:
1925
id-token: write
@@ -130,13 +136,17 @@ jobs:
130136
env:
131137
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
132138
run: |
133-
# Create release notes template
134-
cat > release_notes.md << 'EOF'
139+
# Extract versions from dependency files
140+
OTEL_INSTRUMENTATION_VERSION=$(grep "val otelVersion" dependencyManagement/build.gradle.kts | sed 's/.*= "\([^"]*\)".*/\1/')
141+
OTEL_CONTRIB_VERSION=$(grep "io.opentelemetry.contrib:opentelemetry-aws-xray" dependencyManagement/build.gradle.kts | sed 's/.*:\([^"]*\)".*/\1/')
142+
143+
# Create release notes
144+
cat > release_notes.md << EOF
135145
This release contains updates of the following upstream components:
136146
137147
OpenTelemetry Java - <opentelemetry-java version number - e.g. 1.45.0>
138-
OpenTelemetry Java Contrib - <opentelemetry-java-contrib version number - e.g. 1.39.0>
139-
Opentelemetry Instrumentation for Java - <opentelemetry-java-instrumentation version number - e.g. 2.11.0>
148+
OpenTelemetry Java Contrib - $OTEL_CONTRIB_VERSION
149+
Opentelemetry Instrumentation for Java - $OTEL_INSTRUMENTATION_VERSION
140150
141151
This release also publishes to public ECR and Maven Central.
142152
* See ADOT Java auto-instrumentation Docker image v${{ github.event.inputs.version }} in our public ECR repository:
@@ -147,7 +157,235 @@ jobs:
147157
148158
gh release create --target "$GITHUB_REF_NAME" \
149159
--title "Release v${{ github.event.inputs.version }}" \
160+
--notes-file release_notes.md \
150161
--draft \
151162
"v${{ github.event.inputs.version }}" \
152163
${{ env.ARTIFACT_NAME }} \
153164
${{ env.ARTIFACT_NAME }}.sha256
165+
build-layer:
166+
environment: Release
167+
needs: build
168+
runs-on: ubuntu-latest
169+
outputs:
170+
aws_regions_json: ${{ steps.set-matrix.outputs.aws_regions_json }}
171+
steps:
172+
- name: Set up regions matrix
173+
id: set-matrix
174+
run: |
175+
IFS=',' read -ra REGIONS <<< "${{ github.event.inputs.aws_region }}"
176+
MATRIX="["
177+
for region in "${REGIONS[@]}"; do
178+
trimmed_region=$(echo "$region" | xargs)
179+
MATRIX+="\"$trimmed_region\","
180+
done
181+
MATRIX="${MATRIX%,}]"
182+
echo ${MATRIX}
183+
echo "aws_regions_json=${MATRIX}" >> $GITHUB_OUTPUT
184+
185+
- name: Checkout Repo @ SHA - ${{ github.sha }}
186+
uses: actions/checkout@v5
187+
188+
- uses: actions/setup-java@v4
189+
with:
190+
java-version: 17
191+
distribution: 'temurin'
192+
193+
- name: Build layers
194+
working-directory: lambda-layer
195+
run: |
196+
./build-layer.sh
197+
198+
- name: Upload layer
199+
uses: actions/upload-artifact@v4
200+
with:
201+
name: aws-opentelemetry-java-layer.zip
202+
path: lambda-layer/build/distributions/aws-opentelemetry-java-layer.zip
203+
publish-layer-prod:
204+
runs-on: ubuntu-latest
205+
needs: build-layer
206+
strategy:
207+
matrix:
208+
aws_region: ${{ fromJson(needs.build-layer.outputs.aws_regions_json) }}
209+
steps:
210+
- name: role arn
211+
env:
212+
COMMERCIAL_REGIONS: ${{ env.COMMERCIAL_REGIONS }}
213+
run: |
214+
COMMERCIAL_REGIONS_ARRAY=(${COMMERCIAL_REGIONS//,/ })
215+
FOUND=false
216+
for REGION in "${COMMERCIAL_REGIONS_ARRAY[@]}"; do
217+
if [[ "$REGION" == "${{ matrix.aws_region }}" ]]; then
218+
FOUND=true
219+
break
220+
fi
221+
done
222+
if [ "$FOUND" = true ]; then
223+
echo "Found ${{ matrix.aws_region }} in COMMERCIAL_REGIONS"
224+
SECRET_KEY="LAMBDA_LAYER_RELEASE"
225+
else
226+
echo "Not found ${{ matrix.aws_region }} in COMMERCIAL_REGIONS"
227+
SECRET_KEY="${{ matrix.aws_region }}_LAMBDA_LAYER_RELEASE"
228+
fi
229+
SECRET_KEY=${SECRET_KEY//-/_}
230+
echo "SECRET_KEY=${SECRET_KEY}" >> $GITHUB_ENV
231+
232+
- uses: aws-actions/[email protected]
233+
with:
234+
role-to-assume: ${{ secrets[env.SECRET_KEY] }}
235+
role-duration-seconds: 1200
236+
aws-region: ${{ matrix.aws_region }}
237+
238+
- name: Get s3 bucket name for release
239+
run: |
240+
echo BUCKET_NAME=java-lambda-layer-${{ github.run_id }}-${{ matrix.aws_region }} | tee --append $GITHUB_ENV
241+
242+
- name: download layer.zip
243+
uses: actions/download-artifact@v4
244+
with:
245+
name: aws-opentelemetry-java-layer.zip
246+
247+
- name: publish
248+
run: |
249+
aws s3 mb s3://${{ env.BUCKET_NAME }}
250+
aws s3 cp aws-opentelemetry-java-layer.zip s3://${{ env.BUCKET_NAME }}
251+
layerARN=$(
252+
aws lambda publish-layer-version \
253+
--layer-name ${{ env.LAYER_NAME }} \
254+
--content S3Bucket=${{ env.BUCKET_NAME }},S3Key=aws-opentelemetry-java-layer.zip \
255+
--compatible-runtimes java17 java21 \
256+
--compatible-architectures "arm64" "x86_64" \
257+
--license-info "Apache-2.0" \
258+
--description "AWS Distro of OpenTelemetry Lambda Layer for Java Runtime" \
259+
--query 'LayerVersionArn' \
260+
--output text
261+
)
262+
echo $layerARN
263+
echo "LAYER_ARN=${layerARN}" >> $GITHUB_ENV
264+
mkdir ${{ env.LAYER_NAME }}
265+
echo $layerARN > ${{ env.LAYER_NAME }}/${{ matrix.aws_region }}
266+
cat ${{ env.LAYER_NAME }}/${{ matrix.aws_region }}
267+
268+
- name: public layer
269+
run: |
270+
layerVersion=$(
271+
aws lambda list-layer-versions \
272+
--layer-name ${{ env.LAYER_NAME }} \
273+
--query 'max_by(LayerVersions, &Version).Version'
274+
)
275+
aws lambda add-layer-version-permission \
276+
--layer-name ${{ env.LAYER_NAME }} \
277+
--version-number $layerVersion \
278+
--principal "*" \
279+
--statement-id publish \
280+
--action lambda:GetLayerVersion
281+
282+
- name: upload layer arn artifact
283+
if: ${{ success() }}
284+
uses: actions/upload-artifact@v4
285+
with:
286+
name: ${{ env.LAYER_NAME }}-${{ matrix.aws_region }}
287+
path: ${{ env.LAYER_NAME }}/${{ matrix.aws_region }}
288+
289+
- name: clean s3
290+
if: always()
291+
run: |
292+
aws s3 rb --force s3://${{ env.BUCKET_NAME }}
293+
generate-lambda-release-note:
294+
runs-on: ubuntu-latest
295+
needs: publish-layer-prod
296+
steps:
297+
- name: Checkout Repo @ SHA - ${{ github.sha }}
298+
uses: actions/checkout@v5
299+
- uses: hashicorp/setup-terraform@v2
300+
- name: download layerARNs
301+
uses: actions/download-artifact@v4
302+
with:
303+
pattern: ${{ env.LAYER_NAME }}-*
304+
path: ${{ env.LAYER_NAME }}
305+
merge-multiple: true
306+
- name: show layerARNs
307+
run: |
308+
for file in ${{ env.LAYER_NAME }}/*
309+
do
310+
echo $file
311+
cat $file
312+
done
313+
- name: generate layer-note
314+
working-directory: ${{ env.LAYER_NAME }}
315+
run: |
316+
echo "| Region | Layer ARN |" >> ../layer-note
317+
echo "| ---- | ---- |" >> ../layer-note
318+
for file in *
319+
do
320+
read arn < $file
321+
echo "| " $file " | " $arn " |" >> ../layer-note
322+
done
323+
cat ../layer-note
324+
- name: generate tf layer
325+
working-directory: ${{ env.LAYER_NAME }}
326+
run: |
327+
echo "locals {" >> ../layer_arns.tf
328+
echo " sdk_layer_arns = {" >> ../layer_arns.tf
329+
for file in *
330+
do
331+
read arn < $file
332+
echo " \""$file"\" = \""$arn"\"" >> ../layer_arns.tf
333+
done
334+
cd ..
335+
echo " }" >> layer_arns.tf
336+
echo "}" >> layer_arns.tf
337+
terraform fmt layer_arns.tf
338+
cat layer_arns.tf
339+
- name: generate layer ARN constants for CDK
340+
working-directory: ${{ env.LAYER_NAME }}
341+
run: |
342+
echo "{" > ../layer_cdk
343+
for file in *; do
344+
read arn < "$file"
345+
echo " \"$file\": \"$arn\"," >> ../layer_cdk
346+
done
347+
echo "}" >> ../layer_cdk
348+
cat ../layer_cdk
349+
- name: download layer.zip
350+
uses: actions/download-artifact@v4
351+
with:
352+
name: aws-opentelemetry-java-layer.zip
353+
- name: Rename layer file
354+
run: |
355+
cp aws-opentelemetry-java-layer.zip layer.zip
356+
- name: Get commit hash
357+
id: commit
358+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
359+
- name: Update GH release
360+
env:
361+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
362+
run: |
363+
TAG="v${{ github.event.inputs.version }}"
364+
# Generate SHA-256 checksum for layer.zip
365+
shasum -a 256 layer.zip > layer.zip.sha256
366+
gh release upload $TAG \
367+
layer.zip \
368+
layer.zip.sha256 \
369+
layer_arns.tf \
370+
--clobber
371+
- name: Update Release Notes
372+
env:
373+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
374+
run: |
375+
TAG="v${{ github.event.inputs.version }}"
376+
# Get current release notes
377+
current_notes=$(gh release view $TAG --json body -q .body)
378+
echo "This release also includes the AWS OpenTelemetry Lambda Layer for Java version ${{ github.event.inputs.version }}-${{ steps.commit.outputs.sha_short }}." >> lambda_notes.md
379+
echo "" >> lambda_notes.md
380+
echo "Lambda Layer ARNs:" >> lambda_notes.md
381+
echo "" >> lambda_notes.md
382+
cat layer-note >> lambda_notes.md
383+
echo "" >> lambda_notes.md
384+
echo "Notes:" >> lambda_notes.md
385+
{
386+
echo "$current_notes"
387+
echo ""
388+
cat lambda_notes.md
389+
} > updated_notes.md
390+
# Update release notes
391+
gh release edit $TAG --notes-file updated_notes.md

0 commit comments

Comments
 (0)