Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/actions/workflow-metrics/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Workflow Metrics
description: >
Track and upload workflow metrics to CloudWatch

runs:
using: composite
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
# will change this to AWS CI role before merging
role-to-assume: arn:aws:iam::886436966712:role/Admin
aws-region: us-west-2
- name: Upload workflow metrics
shell: bash
run: |
# Determine build job name with matrix values
job_name="${{ github.job }}"
if [ ! -z "${{ matrix.java-version || '' }}" ]; then
job_name="${job_name}(${{ matrix.java-version }})"
fi
if [ ! -z "${{ matrix.os || '' }}" ]; then
job_name="${job_name}(${{ matrix.os }})"
fi

# Determine success/failure (1 for success, 0 for failure)
if [ "${{ job.status }}" == "success" ]; then
success_value=1
else
success_value=0
fi

# Determine branch (PR target branch or current branch)
if [ ! -z "${{ github.base_ref }}" ]; then
branch_name="${{ github.base_ref }}"
else
branch_name="${{ github.ref_name }}"
fi

aws cloudwatch put-metric-data \
--namespace "GitHub/Workflows" \
--metric-data '[{
"MetricName": "Success",
"Value": '$success_value',
"Unit": "Count",
"Dimensions": [
{
"Name": "WorkflowName",
"Value": "${{ github.workflow }}"
},
{
"Name": "JobName",
"Value": "'$job_name'"
},
{
"Name": "Repository",
"Value": "${{ github.repository }}"
},
{
"Name": "Branch",
"Value": "'$branch_name'"
}
]
}]'

if [ -z "$WORKFLOW_START_TIME" ]; then
echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
exit 0
fi

duration=$(($(date +%s) - $WORKFLOW_START_TIME))

# Only track duration for successful workflows
if [ "$success_value" -eq 1 ]; then
aws cloudwatch put-metric-data \
--namespace "GitHub/Workflows" \
--metric-data '[{
"MetricName": "Duration",
"Value": '$duration',
"Unit": "Seconds",
"Dimensions": [
{
"Name": "WorkflowName",
"Value": "${{ github.workflow }}"
},
{
"Name": "JobName",
"Value": "'$job_name'"
},
{
"Name": "Repository",
"Value": "${{ github.repository }}"
},
{
"Name": "Branch",
"Value": "'$branch_name'"
}
]
}]'
fi
29 changes: 27 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
pull_request:
workflow_dispatch:

permissions: { }
permissions:
id-token: write
contents: read

# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
concurrency:
Expand All @@ -33,6 +35,8 @@ jobs:
- 17
- 21
steps:
- name: Set start time
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout sources
uses: actions/checkout@v4
- name: Configure JDK
Expand All @@ -47,6 +51,9 @@ jobs:
shell: bash
run: |
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
- name: Upload metrics
if: always()
uses: ./.github/actions/workflow-metrics

all-platforms:
runs-on: ${{ matrix.os }}
Expand All @@ -55,6 +62,9 @@ jobs:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- name: Set start time
shell: bash
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout sources
uses: actions/checkout@v4
- name: Configure JDK
Expand All @@ -71,6 +81,9 @@ jobs:
echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties
./gradlew apiCheck
./gradlew test jvmTest
- name: Upload metrics
if: always()
uses: ./.github/actions/workflow-metrics
- name: Save Test Reports
if: failure()
uses: actions/upload-artifact@v4
Expand All @@ -81,6 +94,9 @@ jobs:
protocol-tests:
runs-on: ubuntu-latest
steps:
- name: Set start time
shell: bash
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout sources
uses: actions/checkout@v4
- name: Configure JDK
Expand All @@ -96,10 +112,16 @@ jobs:
run: |
./gradlew publishToMavenLocal
./gradlew testAllProtocols
- name: Upload metrics
if: always()
uses: ./.github/actions/workflow-metrics

downstream:
runs-on: ubuntu-latest
steps:
- name: Set start time
shell: bash
run: echo "WORKFLOW_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout sources
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -149,4 +171,7 @@ jobs:
sed -i "s/smithy-kotlin-codegen-version = .*$/smithy-kotlin-codegen-version = \"$SMITHY_KOTLIN_CODEGEN_VERSION\"/" gradle/libs.versions.toml
./gradlew --parallel publishToMavenLocal
./gradlew test jvmTest
./gradlew testAllProtocols
./gradlew testAllProtocols
- name: Upload metrics
if: always()
uses: ./smithy-kotlin/.github/actions/workflow-metrics
Loading