|
#!/usr/bin/env bash |
|
# .github/scripts/tsfixme_progress.sh |
|
|
|
set -ex |
|
|
|
# Measured on 2022-06-24 |
|
INITIAL_COUNT_TSFIXME_FILES=1938 |
|
INITIAL_COUNT_TSFIXME_INSTANCES=8398 |
|
INITIAL_COUNT_TSERROR_INSTANCES=1763 |
|
|
|
MAGIC_COMMENT_HINT="<!-- tsfixme:progress:comment -->" |
|
|
|
# Generated by a previous workflow step |
|
base_count_tsfixme_instances=$(cat /tmp/base_count_tsfixme_instances) |
|
base_count_tserror_instances=$(cat /tmp/base_count_tserror_instances) |
|
base_count_tsfixme_files=$(cat /tmp/base_count_tsfixme_files) |
|
|
|
count_tsfixme_instances=$(rg "\\\$TSFixMe" --stats . | rg '.*matches$' | head -1 | awk '{ print $1 }') |
|
count_tserror_instances=$(rg 'ts-expect-error ts-migrate' --stats . | rg '.*matches$' | head -1 | awk '{ print $1 }') |
|
count_tsfixme_files=$(rg "\\\$TSFixMe" --stats . | rg '.*matches$' | tail -1 | awk '{ print $1 }') |
|
|
|
main() { |
|
if [ "$count_tsfixme_files" -gt "$base_count_tsfixme_files" ] || [ "$count_tsfixme_instances" -gt "$base_count_tsfixme_instances" ] || [ "$count_tserror_instances" -gt "$base_count_tserror_instances" ]; then |
|
write_comment "$(error_comment)" |
|
exit 1 |
|
elif [ "$count_tsfixme_files" -lt "$base_count_tsfixme_files" ] || [ "$count_tsfixme_instances" -lt "$base_count_tsfixme_instances" ] || [ "$count_tserror_instances" -lt "$base_count_tserror_instances" ]; then |
|
write_comment "$(success_comment)" |
|
else |
|
cleanup_comment |
|
fi |
|
} |
|
|
|
success_comment() { |
|
echo "$MAGIC_COMMENT_HINT |
|
## :tada: Amount of \`\$TSFixMe\` decreased! |
|
|
|
$(table) |
|
" |
|
} |
|
|
|
error_comment() { |
|
echo "$MAGIC_COMMENT_HINT |
|
## :x: Amount of \`\$TSFixMe\` increased! |
|
|
|
$(table) |
|
" |
|
} |
|
|
|
write_comment() { |
|
comment_body="$1" |
|
|
|
magic_comment_id=$(/tmp/hub api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments?per_page=100" | jq -r ".[] | select(.body | startswith(\"${MAGIC_COMMENT_HINT}\")) | .id" | head -n 1) |
|
|
|
if [ -z "$magic_comment_id" ]; then |
|
/tmp/hub api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --raw-field "body=${comment_body}" |
|
else |
|
/tmp/hub api --method PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${magic_comment_id}" --raw-field "body=${comment_body}" |
|
fi |
|
} |
|
|
|
cleanup_comment() { |
|
magic_comment_id=$(/tmp/hub api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments?per_page=100" | jq -r ".[] | select(.body | startswith(\"${MAGIC_COMMENT_HINT}\")) | .id" | head -n 1) |
|
if [ -n "$magic_comment_id" ]; then |
|
/tmp/hub api --method DELETE "repos/${GITHUB_REPOSITORY}/issues/comments/${magic_comment_id}" |
|
fi |
|
} |
|
|
|
table() { |
|
diff_tsfixme_instances=$(printf "%+0.2f" "$(bc -q <<< "scale=4; (($count_tsfixme_instances / $base_count_tsfixme_instances) -1 ) * 100")") |
|
progress_tsfixme_instances=$(printf "%0.2f" "$(bc -q <<< "scale=4; (($INITIAL_COUNT_TSFIXME_INSTANCES - $count_tsfixme_instances) / $INITIAL_COUNT_TSFIXME_INSTANCES) * 100")") |
|
|
|
diff_tsfixme_files=$(printf "%+0.2f" "$(bc -q <<< "scale=4; (($count_tsfixme_files / $base_count_tsfixme_files) -1 ) * 100")") |
|
progress_tsfixme_files=$(printf "%0.2f" "$(bc -q <<< "scale=4; (($INITIAL_COUNT_TSFIXME_FILES - $count_tsfixme_files) / $INITIAL_COUNT_TSFIXME_FILES) * 100")") |
|
|
|
diff_tserror_instances=$(printf "%+0.2f" "$(bc -q <<< "scale=4; (($count_tserror_instances / $base_count_tserror_instances) -1 ) * 100")") |
|
progress_tserror_instances=$(printf "%0.2f" "$(bc -q <<< "scale=4; (($INITIAL_COUNT_TSERROR_INSTANCES - $count_tserror_instances) / $INITIAL_COUNT_TSERROR_INSTANCES) * 100")") |
|
|
|
|
|
echo " |
|
| Count | Base Branch | This Branch | Cumulative Progress since 2022-06-24 | |
|
|------------------------------------|-------------------------------|-------------------------------------------------------|------------------------------------------------------------------------| |
|
| \`\$TSFixMe\` | $base_count_tsfixme_instances | $count_tsfixme_instances (${diff_tsfixme_instances}%) | ${progress_tsfixme_instances}% (from $INITIAL_COUNT_TSFIXME_INSTANCES) | |
|
| Files containing \`\$TSFixMe\` | $base_count_tsfixme_files | $count_tsfixme_files (${diff_tsfixme_files}%) | ${progress_tsfixme_files}% (from $INITIAL_COUNT_TSFIXME_FILES) | |
|
| \`// ts-expect-error ts-migrate\` | $base_count_tserror_instances | $count_tserror_instances (${diff_tserror_instances}%) | ${progress_tserror_instances}% (from $INITIAL_COUNT_TSERROR_INSTANCES) | |
|
" |
|
} |
|
|
|
main |