|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +DRY_RUN=false |
| 4 | + |
| 5 | +owner=pymc-devs |
| 6 | +repo=pytensor |
| 7 | +issue_number=1124 |
| 8 | +title="Speed up test times :rocket:" |
| 9 | +workflow=Tests |
| 10 | +latest_id=$(gh run list --workflow $workflow --status success --limit 1 --json databaseId --jq '.[0].databaseId') |
| 11 | +jobs=$(gh api /repos/$owner/$repo/actions/runs/$latest_id/jobs --jq '.jobs | map({name: .name, run_id: .run_id, id: .id, started_at: .started_at, completed_at: .completed_at})') |
| 12 | + |
| 13 | +# Skip 3.10, float32, and Benchmark tests |
| 14 | +function skip_job() { |
| 15 | + name=$1 |
| 16 | + if [[ $name == *"py3.10"* ]]; then |
| 17 | + return 0 |
| 18 | + fi |
| 19 | + |
| 20 | + if [[ $name == *"float32 1"* ]]; then |
| 21 | + return 0 |
| 22 | + fi |
| 23 | + |
| 24 | + if [[ $name == *"Benchmark"* ]]; then |
| 25 | + return 0 |
| 26 | + fi |
| 27 | + |
| 28 | + return 1 |
| 29 | +} |
| 30 | + |
| 31 | +# Remove common prefix from the name |
| 32 | +function remove_prefix() { |
| 33 | + name=$1 |
| 34 | + echo $name | sed -e 's/^ubuntu-latest test py3.12 : fast-compile 0 : float32 0 : //' |
| 35 | +} |
| 36 | + |
| 37 | +function human_readable_time() { |
| 38 | + started_at=$1 |
| 39 | + completed_at=$2 |
| 40 | + |
| 41 | + start_seconds=$(date -d "$started_at" +%s) |
| 42 | + end_seconds=$(date -d "$completed_at" +%s) |
| 43 | + |
| 44 | + seconds=$(($end_seconds - $start_seconds)) |
| 45 | + |
| 46 | + if [ $seconds -lt 60 ]; then |
| 47 | + echo "$seconds seconds" |
| 48 | + else |
| 49 | + echo "$(date -u -d @$seconds +'%-M minutes %-S seconds')" |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | +all_times="" |
| 54 | +echo "$jobs" | jq -c '.[]' | while read -r job; do |
| 55 | + id=$(echo $job | jq -r '.id') |
| 56 | + name=$(echo $job | jq -r '.name') |
| 57 | + run_id=$(echo $job | jq -r '.run_id') |
| 58 | + started_at=$(echo $job | jq -r '.started_at') |
| 59 | + completed_at=$(echo $job | jq -r '.completed_at') |
| 60 | + |
| 61 | + if skip_job $name; then |
| 62 | + echo "Skipping $name" |
| 63 | + continue |
| 64 | + fi |
| 65 | + |
| 66 | + echo "Processing job: $name (ID: $id, Run ID: $run_id)" |
| 67 | + times=$(gh run view --job $id --log | python extract-slow-tests.py) |
| 68 | + |
| 69 | + if [ -z "$times" ]; then |
| 70 | + # Some of the jobs are non-test jobs, so we skip them |
| 71 | + echo "No tests found for '$name', skipping" |
| 72 | + continue |
| 73 | + fi |
| 74 | + |
| 75 | + echo $times |
| 76 | + |
| 77 | + human_readable=$(human_readable_time $started_at $completed_at) |
| 78 | + name=$(remove_prefix $name) |
| 79 | + |
| 80 | + top="<details><summary>($human_readable) $name</summary>\n\n\n\`\`\`" |
| 81 | + bottom="\`\`\`\n\n</details>" |
| 82 | + |
| 83 | + formatted_times="$top\n$times\n$bottom" |
| 84 | + |
| 85 | + if [ -n "$all_times" ]; then |
| 86 | + all_times="$all_times\n$formatted_times" |
| 87 | + else |
| 88 | + all_times="$formatted_times" |
| 89 | + fi |
| 90 | +done |
| 91 | + |
| 92 | +run_date=$(date +"%Y-%m-%d") |
| 93 | +body=$(cat << EOF |
| 94 | +If you are motivated to help speed up some tests, we would appreciate it! |
| 95 | +
|
| 96 | +Here are some of the slowest test times: |
| 97 | +
|
| 98 | +$all_times |
| 99 | +
|
| 100 | +You can find more information on how to contribute [here](https://pytensor.readthedocs.io/en/latest/dev_start_guide.html) |
| 101 | +
|
| 102 | +Automatically generated by [GitHub Action](https://github.com/pymc-devs/pytensor/blob/main/.github/workflows/slow-tests-issue.yml) |
| 103 | +Latest run date: $run_date |
| 104 | +EOF |
| 105 | +) |
| 106 | + |
| 107 | +if [ "$DRY_RUN" = true ]; then |
| 108 | + echo "Dry run, not updating issue" |
| 109 | + echo $body |
| 110 | + exit |
| 111 | +fi |
| 112 | +echo $body | gh issue edit $issue_number --body-file - --title "$title" |
| 113 | +echo "Updated issue $issue_number with all times" |
0 commit comments