Skip to content

Commit 490991b

Browse files
authored
Use reusable workflow to publish status (#276)
* Use reusable workflow to publish status Signed-off-by: Raphael Silva <[email protected]> * Fix typo in publish-status wf Signed-off-by: Raphael Silva <[email protected]>
1 parent d1ee0f2 commit 490991b

File tree

3 files changed

+83
-47
lines changed

3 files changed

+83
-47
lines changed

.github/workflows/main-build.yml

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,17 @@ jobs:
145145
VALIDATOR_COMMAND: -c spark-otel-trace-metric-validation.yml --endpoint http://app:4567 --metric-namespace aws-otel-integ-test -t ${{ github.run_id }}-${{ github.run_number }}
146146

147147
publish-build-status:
148-
runs-on: ubuntu-latest
149148
needs: [test_Spring_App_With_Java_Agent, test_Spark_App_With_Java_Agent, test_Spark_AWS_SDK_V1_App_With_Java_Agent]
150-
if: always()
151-
steps:
152-
- name: Configure AWS Credentials
153-
uses: aws-actions/configure-aws-credentials@v1-node16
154-
with:
155-
role-to-assume: ${{ secrets.METRICS_ROLE_ARN }}
156-
aws-region: us-west-2
157-
role-duration-seconds: 21600
158-
159-
- name: Publish CI status
160-
run: |
161-
if [ '${{ needs.test_Spring_App_With_Java_Agent.result }}' = 'success' ] && \
162-
[ '${{ needs.test_Spark_App_With_Java_Agent.result }}' = 'success' ] && \
163-
[ '${{ needs.test_Spark_AWS_SDK_V1_App_With_Java_Agent.result }}' = 'success' ]; then
164-
aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \
165-
--metric-name Success \
166-
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=main-build \
167-
--value 1.0
168-
else
169-
aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \
170-
--metric-name Success \
171-
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=main-build \
172-
--value 0.0
173-
fi
149+
if: ${{ always() }}
150+
uses: ./.github/workflows/publish-status.yml
151+
with:
152+
namespace: 'ADOT/GitHubActions'
153+
repository: ${{ github.repository }}
154+
branch: ${{ github.ref_name }}
155+
workflow: main-build
156+
success: ${{ needs.test_Spring_App_With_Java_Agent.result == 'success' &&
157+
needs.test_Spark_App_With_Java_Agent.result }}' == 'success' &&
158+
needs.test_Spark_AWS_SDK_V1_App_With_Java_Agent.result == 'success' }}
159+
region: us-west-2
160+
secrets:
161+
roleArn: ${{ secrets.METRICS_ROLE_ARN }}

.github/workflows/nightly-upstream-snapshot-build.yml

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,16 @@ jobs:
4747
name: aws-opentelemetry-agent.jar
4848
path: otelagent/build/libs/aws-opentelemetry-agent-*.jar
4949
publish-build-status:
50-
runs-on: ubuntu-latest
5150
needs: [build]
52-
if: always()
53-
steps:
54-
- name: Configure AWS Credentials
55-
uses: aws-actions/configure-aws-credentials@v1-node16
56-
with:
57-
role-to-assume: ${{ secrets.METRICS_ROLE_ARN }}
58-
aws-region: us-west-2
59-
role-duration-seconds: 21600
51+
if: ${{ always() }}
52+
uses: ./.github/workflows/publish-status.yml
53+
with:
54+
namespace: 'ADOT/GitHubActions'
55+
repository: ${{ github.repository }}
56+
branch: ${{ github.ref_name }}
57+
workflow: nightly-upstream-snapshot-build
58+
success: ${{ needs.build.result == 'success' }}
59+
region: us-west-2
60+
secrets:
61+
roleArn: ${{ secrets.METRICS_ROLE_ARN }}
6062

61-
- name: Publish CI status
62-
run: |
63-
if [ '${{ needs.build.result }}' = 'success' ]; then
64-
aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \
65-
--metric-name Success \
66-
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=nightly-upstream-snapshot-build \
67-
--value 1.0
68-
else
69-
aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \
70-
--metric-name Success \
71-
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=nightly-upstream-snapshot-build \
72-
--value 0.0
73-
fi
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Reusable workflow used to publish status of the caller github workflow to Cloudwatch metrics
2+
name: Publish status
3+
on:
4+
workflow_call:
5+
inputs:
6+
# Cloudwatch Metrics namespace
7+
namespace:
8+
required: true
9+
type: string
10+
# Dimensions
11+
repository:
12+
required: true
13+
type: string
14+
branch:
15+
required: true
16+
type: string
17+
workflow:
18+
required: true
19+
type: string
20+
# Metric name
21+
success:
22+
required: true
23+
type: boolean
24+
# Region where the metric is published
25+
region:
26+
required: true
27+
type: string
28+
secrets:
29+
roleArn:
30+
required: true
31+
32+
jobs:
33+
publish-status:
34+
runs-on: ubuntu-latest
35+
permissions:
36+
id-token: write
37+
contents: read
38+
steps:
39+
- name: Configure AWS Credentials
40+
uses: aws-actions/configure-aws-credentials@v1-node16
41+
with:
42+
role-to-assume: ${{ secrets.roleArn }}
43+
aws-region: ${{ inputs.region }}
44+
role-duration-seconds: 21600
45+
46+
- name: Publish status success
47+
if: ${{ inputs.success }}
48+
run: |
49+
aws cloudwatch put-metric-data --namespace '${{ inputs.namespace }}' \
50+
--metric-name Success \
51+
--dimensions repository=${{ inputs.repository }},branch=${{ inputs.branch }},workflow=${{ inputs.workflow }} \
52+
--value 1.0
53+
- name: Publish status failure
54+
if: ${{ !inputs.success }}
55+
run: |
56+
aws cloudwatch put-metric-data --namespace '${{ inputs.namespace }}' \
57+
--metric-name Success \
58+
--dimensions repository=${{ inputs.repository }},branch=${{ inputs.branch }},workflow=${{ inputs.workflow }} \
59+
--value 0.0

0 commit comments

Comments
 (0)