Skip to content

Commit 2f00d8c

Browse files
authored
fix(workflow): use shared contributors workflow (#24)
1 parent 3a2084c commit 2f00d8c

File tree

1 file changed

+4
-72
lines changed

1 file changed

+4
-72
lines changed

.github/workflows/contributors.yml

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,10 @@ name: Update Contributors
22

33
on:
44
schedule:
5-
- cron: '0 0 * * *' # Run daily at midnight UTC
6-
workflow_dispatch: # Allow manual trigger
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
77

88
jobs:
99
contributors:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
13-
with:
14-
token: ${{ secrets.CONTRIBUTORS_TOKEN }}
15-
16-
- name: Update contributors
17-
env:
18-
GH_TOKEN: ${{ secrets.CONTRIBUTORS_TOKEN }}
19-
run: |
20-
# Fetch code contributors (exclude bots)
21-
code_contributors=$(gh api repos/${{ github.repository }}/contributors --paginate --jq '.[] | select(.type != "Bot") | select(.login | test("\\[bot\\]$") | not) | .login')
22-
23-
# Fetch closed issues and check if they were closed by a merged PR
24-
issue_authors=""
25-
closed_issues=$(gh api "repos/${{ github.repository }}/issues?state=closed" --paginate -q '.[] | select(.pull_request == null) | {number, login: .user.login}')
26-
27-
for row in $(echo "$closed_issues" | jq -c '.'); do
28-
issue_num=$(echo "$row" | jq -r '.number')
29-
login=$(echo "$row" | jq -r '.login')
30-
31-
# Check timeline for cross-referenced merged PR that closed this issue
32-
closed_by_pr=$(gh api repos/${{ github.repository }}/issues/$issue_num/timeline --jq '
33-
[.[] | select(.event == "cross-referenced") |
34-
select(.source.issue.pull_request.merged_at)] |
35-
.[0].source.issue.number // empty')
36-
37-
if [[ -n "$closed_by_pr" ]]; then
38-
issue_authors="$issue_authors$login"$'\n'
39-
fi
40-
done
41-
issue_authors=$(echo "$issue_authors" | sort -u)
42-
43-
# Combine and deduplicate
44-
all_contributors=$(echo -e "$code_contributors\n$issue_authors" | sort -u | grep -v '^$')
45-
46-
# Build markdown for each contributor
47-
contributor_md=""
48-
for login in $all_contributors; do
49-
# Skip bots
50-
if [[ "$login" == *"[bot]" ]]; then
51-
continue
52-
fi
53-
54-
# Get user info
55-
user_info=$(gh api users/$login --jq '{avatar_url, html_url}')
56-
avatar=$(echo "$user_info" | jq -r '.avatar_url')
57-
url=$(echo "$user_info" | jq -r '.html_url')
58-
59-
contributor_md="$contributor_md[![$login](${avatar}&s=64)]($url) "
60-
done
61-
62-
# Build the contributors section
63-
contrib_section="<!-- readme: contributors -start -->
64-
$contributor_md
65-
<!-- readme: contributors -end -->"
66-
67-
# Update README between the markers
68-
awk -v contrib="$contrib_section" '
69-
/<!-- readme: contributors -start -->/{found=1; print contrib; next}
70-
/<!-- readme: contributors -end -->/{found=0; next}
71-
!found{print}
72-
' README.md > README.tmp && mv README.tmp README.md
73-
74-
- name: Commit and push
75-
run: |
76-
git config user.name "github-actions[bot]"
77-
git config user.email "github-actions[bot]@users.noreply.github.com"
78-
git add README.md
79-
git diff --staged --quiet || (git commit -m "docs: update contributors [skip ci]" && git push)
10+
uses: CodingWithCalvin/.github/.github/workflows/contributors.yml@main
11+
secrets: inherit

0 commit comments

Comments
 (0)