|
| 1 | +# Run gh-profiler against the author of each new issue. |
| 2 | +# Delete the profile output when the issue is closed. |
| 3 | +# PR authors are profiled by the unprivileged profile-pr-authors.yml instead, |
| 4 | +# so no dangerous trigger is needed for PRs from forks. |
| 5 | + |
| 6 | +name: Profile issue authors |
| 7 | + |
| 8 | +on: |
| 9 | + issues: |
| 10 | + types: [opened, closed] |
| 11 | + |
| 12 | +jobs: |
| 13 | + profile-author: |
| 14 | + if: github.event.action == 'opened' |
| 15 | + |
| 16 | + permissions: |
| 17 | + issues: write |
| 18 | + |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 |
| 23 | + |
| 24 | + - name: Run gh-profiler (=== Expand this to see full profile output ===) |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + LOGIN: ${{ github.event.issue.user.login }} |
| 28 | + run: | |
| 29 | + uvx gh-profiler@latest "$LOGIN" --concise > profiler.txt |
| 30 | + echo |
| 31 | + echo "======================== Full profile =========================" |
| 32 | + echo |
| 33 | + uvx gh-profiler@latest "$LOGIN" |
| 34 | + echo |
| 35 | + echo "===============================================================" |
| 36 | +
|
| 37 | + - name: Comment on issue |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + SERVER_URL: ${{ github.server_url }} |
| 41 | + REPOSITORY: ${{ github.repository }} |
| 42 | + RUN_ID: ${{ github.run_id }} |
| 43 | + CHECK_RUN_ID: ${{ job.check_run_id }} |
| 44 | + NUMBER: ${{ github.event.issue.number }} |
| 45 | + run: | |
| 46 | + { |
| 47 | + echo "<!-- gh-profiler:profile-link run-id=$RUN_ID -->" |
| 48 | + echo "Profile summary:" |
| 49 | + echo |
| 50 | + echo '```text' |
| 51 | + cat profiler.txt |
| 52 | + echo '```' |
| 53 | + echo |
| 54 | + echo "<a href=\"$SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID/job/$CHECK_RUN_ID\">Full profile</a>" |
| 55 | + echo |
| 56 | + echo "(This comment and the linked profile output will auto-delete when this issue is closed.)" |
| 57 | + } > body.txt |
| 58 | +
|
| 59 | + jq -Rs '{body: .}' body.txt > payload.json |
| 60 | +
|
| 61 | + gh api \ |
| 62 | + "repos/$REPOSITORY/issues/$NUMBER/comments" \ |
| 63 | + --input payload.json |
| 64 | +
|
| 65 | + delete-profile: |
| 66 | + if: github.event.action == 'closed' |
| 67 | + |
| 68 | + permissions: |
| 69 | + actions: write |
| 70 | + issues: write |
| 71 | + |
| 72 | + runs-on: ubuntu-latest |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Delete profile comment |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + REPOSITORY: ${{ github.repository }} |
| 79 | + NUMBER: ${{ github.event.issue.number }} |
| 80 | + run: | |
| 81 | + gh api --paginate \ |
| 82 | + "repos/$REPOSITORY/issues/$NUMBER/comments" \ |
| 83 | + --jq ' |
| 84 | + .[] |
| 85 | + | select(.user.login == "github-actions[bot]") |
| 86 | + | select(.body | startswith("<!-- gh-profiler:profile-link run-id=")) |
| 87 | + | [.id, (.body | capture("gh-profiler:profile-link run-id=(?<id>[0-9]+)").id)] |
| 88 | + | @tsv |
| 89 | + ' | |
| 90 | + while IFS=$'\t' read -r comment_id run_id; do |
| 91 | + echo "Deleting logs from workflow run $run_id." |
| 92 | + gh api --method DELETE \ |
| 93 | + "repos/$REPOSITORY/actions/runs/$run_id/logs" |
| 94 | +
|
| 95 | + echo "Deleting profile comment $comment_id." |
| 96 | + gh api --method DELETE \ |
| 97 | + "repos/$REPOSITORY/issues/comments/$comment_id" |
| 98 | + done |
0 commit comments