add a metrics test check GH action (#11536)
Signed-off-by: FFMMM <FFMMM@users.noreply.github.com>
This commit is contained in:
parent
659e909fe3
commit
7495b38c56
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
### This script checks if any metric behavior has been modified.
|
||||
### The checks rely on the git diff against origin/main
|
||||
### It is still up to the reviewer to make sure that any tests added are needed and meaningful.
|
||||
|
||||
# search for any "new" or modified metric emissions
|
||||
metrics_modified=$(git --no-pager diff HEAD origin/main | grep -i "SetGauge\|EmitKey\|IncrCounter\|AddSample\|MeasureSince\|UpdateFilter")
|
||||
# search for PR body or title metric references
|
||||
metrics_in_pr_body=$(echo "${PR_BODY-""}" | grep -i "metric")
|
||||
metrics_in_pr_title=$(echo "${PR_TITLE-""}" | grep -i "metric")
|
||||
|
||||
# if there have been code changes to any metric or mention of metrics in the pull request body
|
||||
if [ "$metrics_modified" ] || [ "$metrics_in_pr_body" ] || [ "$metrics_in_pr_title" ]; then
|
||||
# need to check if there are modifications to metrics_test
|
||||
test_files_regex="*_test.go"
|
||||
modified_metrics_test_files=$(git --no-pager diff HEAD "$(git merge-base HEAD "origin/main")" -- "$test_files_regex" | grep -i "metric")
|
||||
if [ "$modified_metrics_test_files" ]; then
|
||||
# 1 happy path: metrics_test has been modified bc we modified metrics behavior
|
||||
echo "PR seems to modify metrics behavior. It seems it may have added tests to the metrics as well."
|
||||
exit 0
|
||||
else
|
||||
echo "PR seems to modify metrics behavior. It seems no tests or test behavior has been modified."
|
||||
echo "Please update the PR with any relevant updated testing or add a pr/no-metrics-test label to skip this check."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
# no metrics modified in code, nothing to check
|
||||
echo "No metric behavior seems to be modified."
|
||||
exit 0
|
||||
fi
|
|
@ -0,0 +1,25 @@
|
|||
name: "Check for metrics tests"
|
||||
on:
|
||||
pull_request:
|
||||
types: [ opened, synchronize, labeled ]
|
||||
# Runs on PRs to main
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
metrics_test_check:
|
||||
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-metrics-test')"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
name: "checkout repo"
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
|
||||
- name: "Check for metrics modifications"
|
||||
run: ./.github/scripts/metrics_checker.sh
|
||||
# as of now, cannot use github vars in "external" scripts; ref: https://github.community/t/using-github-action-environment-variables-in-shell-script/18330
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
PR_BODY: ${{ github.event.pull_request.body }}
|
||||
shell: bash
|
Loading…
Reference in New Issue