graphql-engine/server/benchmarks/utils/hide-benchmark-reports.sh
awjchen cd957fb5ea ci: hide old benchmark reports on Github
https://github.com/hasura/graphql-engine-mono/pull/1996

GitOrigin-RevId: 0d2b607de9ea180e269c8f30f4a8b9618129d98f
2021-08-05 05:55:18 +00:00

40 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# This script looks at the comments on a hasura/graphql-engine-mono issue (or
# pull request) and rewrites all of the benchmark reports to hide them behind
# `<details>` tags. Our goal is to make benchmark reports less noisy on our
# PRs, especially when there are many reports, while retaining the visual
# prominence of the most recent report. To that end, this script is intended to
# be run just before posting a new benchmark report to a PR.
#
# This script depends on the `GITHUB_TOKEN` and `PR_NUMBER` environment
# variables. It identifies a comment as a benchmark report by checking whether
# the comment starts with "## Benchmark Results".
# Get all issue comments.
# https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
curl \
-s \
-H "Authorization: token ${GITHUB_TOKEN}" \
-X GET "https://api.github.com/repos/hasura/graphql-engine-mono/issues/${PR_NUMBER}/comments" | \
# Keep only the benchmark reports.
jq -r -c '.[] | {id: .id, body: .body} | select(.body | startswith("## Benchmark Results"))' | \
# Update the benchmark reports to hide them.
while read -r report; do
id=$(echo "${report}" | jq -r '.id')
echo "Updating existing benchmark report (comment id=${id})"
echo "${report}" | \
jq -r '{body: .body} | .body |= "<details>\n<summary>Outdated benchmark report (click to expand)</summary>\n\n" + . + "\n</details>"' | \
# https://docs.github.com/en/rest/reference/issues#update-an-issue-comment
curl \
-s \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/hasura/graphql-engine-mono/issues/comments/${id}" \
-d @-
done