Skip to content

Commit e30dcd2

Browse files
committed
Profile contributors
1 parent ce4147b commit e30dcd2

2 files changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Run gh-profiler against the author of each new PR and show the output in
2+
# the job log and step summary, reachable via the PR's checks.
3+
#
4+
# This runs unprivileged (read-only token, safe for PRs from forks), so it
5+
# cannot post a comment like profile-issue-authors.yml does for issues.
6+
# There is also nothing to delete when the PR is closed: the output expires
7+
# with the run logs.
8+
9+
name: Profile PR authors
10+
11+
on:
12+
pull_request:
13+
types: [opened]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
profile-author:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
24+
with:
25+
enable-cache: false
26+
ignore-empty-workdir: true
27+
28+
- name: Run gh-profiler (=== Expand this to see full profile output ===)
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
LOGIN: ${{ github.event.pull_request.user.login }}
32+
run: |
33+
uvx gh-profiler@latest "$LOGIN" > profiler.txt
34+
cat profiler.txt
35+
{
36+
echo '```text'
37+
cat profiler.txt
38+
echo '```'
39+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)