Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: add script to measure percentage of commits with failed status #13175

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions .github/workflows/measure-test-flakiness.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Measure Test Flakiness

on:
schedule:
- cron: "0 0 * * 0"

jobs:
measure-test-flakiness:
name: Measure Test Flakiness
runs-on: ubuntu-latest
steps:
- name: Run script to measure test flakiness
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: "./scripts/measure-test-flakiness.sh"
27 changes: 27 additions & 0 deletions scripts/measure-test-flakiness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e
set -o pipefail

if [[ -z ${GITHUB_TOKEN} ]]
then
echo "Please set the \$GITHUB_TOKEN environment variable for the script to work"
exit 1
fi

temp_dir=$(mktemp -d)

trap '{ rm -rf -- "${temp_dir}"; }' EXIT

json_file="${temp_dir}/commit-and-check-data.json"

curl --fail --show-error --silent -H "Authorization: token ${GITHUB_TOKEN}" \
-X POST \
-d '{
"query": "query { repository(owner: \"etcd-io\", name: \"etcd\") { defaultBranchRef { target { ... on Commit { history(first: 100) { edges { node { ... on Commit { commitUrl statusCheckRollup { state } } } } } } } } } }"
}' \
https://api.github.com/graphql | jq . > "${json_file}"

failure_percentage=$(jq '.data.repository.defaultBranchRef.target.history.edges | reduce .[] as $item (0; if $item.node.statusCheckRollup.state == "FAILURE" then (. + 1) else . end)' "${json_file}")

echo "Commit status failure percentage is - ${failure_percentage} %"