11name : Log Metric
2- description : Log data point to a metric with the provided value. If the metric is not there, it will create one
2+ description : Log data point to a metric with the provided value. If the metric is not there, it will create one.
33# To avoid 'Credentials could not be loaded' calling workflows must include:
44# permissions:
55# id-token: write
66# contents: read
77inputs :
88 aws-region :
99 required : true
10- description : The AWS region
10+ description : The AWS region.
1111 role-to-assume :
1212 required : true
13- description : The role to assume in the STS session
14- metric-name :
15- description : Name of the metric to track in Cloudwatch.
13+ description : The role to assume in the STS session.
14+ github-token :
1615 required : true
17- value :
18- # Why we publish value 0 on success: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#publishingZero
19- description : Value of the metric to track in Cloudwatch.
16+ description : Github token for requesting failing steps.
17+ job-status :
18+ description : Used to determine if we track success or failure.
19+ required : true
20+ job-identifier :
21+ description : For differentiating jobs of a run.
22+ required : true
23+
24+
25+ # Global Metric Dimensions
26+ testType :
27+ description : canary, integration, unit testType.
28+ required : true
29+ category :
30+ description : analytics, api, authenticator, etc.
2031 required : true
21- dimensions :
22- description : Dimensions of metric to track in Cloudwatch, in format dimensionName1=value,dimensionName2=value,...
32+ workflowName :
33+ description : The Github Action workflow.yaml file name. ie "AmplifyCanaries".
34+ required : true
35+
36+ # FlutterDart Workflows Metric Dimensions
37+ framework :
38+ description : flutter, dart.
39+ required : false
40+ flutterDartChannel :
41+ description : beta, stable.
42+ required : false
43+ dartVersion :
44+ description : 3, 2.19, 2.18, etc.
2345 required : false
46+ flutterVersion :
47+ description : 3.10.6, 3.10.5, etc.
48+ required : false
49+ dartCompiler :
50+ description : dart2js, ddc, dart, dart2wasm.
51+ required : false
52+
53+ # Platform Workflows Metric Dimensions
54+ platform :
55+ description : android, ios, web, linux, windows.
56+ required : false
57+ platformVersion :
58+ description : ios-14.5, ios-16, android-25-x86, etc.
59+ required : false
60+
2461runs :
2562 using : ' composite'
2663 steps :
64+ - name : Exit if not scheduled
65+ shell : bash
66+ run : |
67+ if [ "${{ github.event_name }}" != "schedule" ]; then
68+ echo "This was not triggered by a schedule, exiting."
69+ exit 0
70+ fi
71+
2772 - name : Configure AWS credentials
2873 uses : aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838 # 1.7.0
2974 with :
3075 role-to-assume : ${{ inputs.role-to-assume }}
3176 aws-region : ${{ inputs.aws-region }}
3277 role-duration-seconds : 900
3378
79+ - name : Get Job ID
80+ run : |
81+ substring="${{ inputs.job-identifier }}"
82+
83+ jobs_json=$(curl -s -H "Authorization: token ${{ inputs.github-token }}" \
84+ -H "Accept: application/vnd.github.v3+json" \
85+ "https://api.github.com/repos/fjnoyp/amplify-flutter/actions/runs/${{ github.run_id }}/jobs")
86+
87+ job_id=$(echo "$jobs_json" | jq --arg substring "$substring" '.jobs[] | select(.name | contains($substring)) | .id')
88+
89+ echo "substring is $substring"
90+ echo "job json is $jobs_json"
91+ echo "github run id is ${{ github.run_id}}"
92+
93+ echo "Job ID for job containing $substring is $job_id"
94+ echo "job_id=$job_id" >> $GITHUB_ENV
95+ shell : bash
96+
97+ - name : Get Failing Step
98+ if : ${{ job.status == 'failure' }}
99+ shell : bash
100+ run : |
101+ response=$(curl -s -H "Authorization: token ${{ inputs.github-token }}" \
102+ -H "Accept: application/vnd.github.v3+json" \
103+ "https://api.github.com/repos/fjnoyp/amplify-flutter/actions/jobs/${{ env.job_id }}")
104+ failing_step_name=$(echo "$response" | jq -r '.steps[] | select(.conclusion == "failure") | .name')
105+
106+ echo "FAILING_STEP=$failing_step_name" >> $GITHUB_ENV
107+
108+ - name : Change to Dart script directory
109+ run : cd ./tool
110+ shell : bash
111+
112+ - name : Install Dart dependencies (args)
113+ run : dart pub get
114+ shell : bash
115+
34116 - name : Run Dart script
35- # Run a Dart script to put metric data.
36- run : dart ./tool/send_metric_data.dart ${{ inputs.metric-name }} ${{ inputs.value }} ${{ inputs.dimensions }}
37- shell : bash
117+ run : |
118+ dart ./tool/send_metric_data.dart \
119+ --metric-name="github_metric_1.0" \
120+ --job-status="${{ job.status == 'failure' }}" \
121+ --test-type="${{ inputs.testType }}" \
122+ --category="${{ inputs.category }}" \
123+ --workflow-name="${{ inputs.workflowName }}" \
124+ --framework="${{ inputs.framework }}" \
125+ --flutter-dart-channel="${{ inputs.flutterDartChannel }}" \
126+ --dart-version="${{ inputs.dartVersion }}" \
127+ --flutter-version="${{ inputs.flutterVersion }}" \
128+ --dart-compiler="${{ inputs.dartCompiler }}" \
129+ --platform="${{ inputs.platform }}" \
130+ --platform-version="${{ inputs.platformVersion }}" \
131+ --failing-step="${{ env.FAILING_STEP }}"
132+ shell : bash
0 commit comments