Skip to content

Commit f74481e

Browse files
Merge pull request #127 from itsdakshjain/main
Implement github workflow automation for contributors
2 parents 552d3b1 + 22a0995 commit f74481e

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

.github/workflows/contributors.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: contributor automation
2+
3+
on:
4+
schedule: # runs daily at midnight
5+
- cron: '0 0 * * *'
6+
pull_request:
7+
types: [closed]
8+
branches:
9+
- main
10+
11+
# allows manual trigger
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
update-readme:
17+
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Fetch Merged PR Authors (Pagination)
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
set -euo pipefail
28+
PAGE=1
29+
echo "[]" > final_list.json
30+
while true; do
31+
# Using pulls endpoint to capture only merged contributors
32+
RESPONSE=$(gh api "/repos/steam-bell-92/python-mini-project/pulls?state=closed&per_page=100&page=${PAGE}")
33+
COUNT=$(echo "$RESPONSE" | jq '. | length')
34+
if [ "$COUNT" -eq 0 ]; then break; fi
35+
jq -s '.[0] + .[1]' final_list.json <(echo "$RESPONSE") > tmp.json && mv tmp.json final_list.json
36+
PAGE=$((PAGE + 1))
37+
done
38+
# Filters for actual merged PRs and unique users
39+
jq '[.[]
40+
| select(.merged_at != null and .user != null and .user.type != "Bot")
41+
| .user.login]
42+
| unique
43+
| sort' final_list.json > contributors.json
44+
- name: Build Gallery HTML
45+
run: |
46+
set -euo pipefail
47+
GALLERY_HTML=""
48+
for USERNAME in $(jq -r '.[]' contributors.json); do
49+
GALLERY_HTML="${GALLERY_HTML}<a href=\"https://github.com/${USERNAME}\"><img src=\"https://github.com/${USERNAME}.png\" width=\"50px\" loading=\"lazy\" title=\"${USERNAME}\" style=\"border-radius:50%;margin:5px;\" alt=\"${USERNAME}\" /></a>"
50+
done
51+
echo "$GALLERY_HTML" > gallery_fragment.txt
52+
53+
- name: Update README.md
54+
run: |
55+
set -euo pipefail
56+
# Safety check for markers
57+
start_count=$(grep -c '<!-- CONTRIBUTORS_START -->' README.md || true)
58+
end_count=$(grep -c '<!-- CONTRIBUTORS_END -->' README.md || true)
59+
if [ "$start_count" -ne 1 ] || [ "$end_count" -ne 1 ]; then
60+
echo "Error: README.md must contain exactly one pair of markers."
61+
exit 1
62+
fi
63+
64+
start_line=$(grep -n '<!-- CONTRIBUTORS_START -->' README.md | cut -d: -f1)
65+
end_line=$(grep -n '<!-- CONTRIBUTORS_END -->' README.md | cut -d: -f1)
66+
if [ "$start_line" -ge "$end_line" ]; then
67+
echo "Error: CONTRIBUTORS_START must appear before CONTRIBUTORS_END."
68+
exit 1
69+
fi
70+
71+
sed -i '/<!-- CONTRIBUTORS_START -->/,/<!-- CONTRIBUTORS_END -->/ {
72+
/<!-- CONTRIBUTORS_START -->/! { /<!-- CONTRIBUTORS_END -->/! d; }
73+
}' README.md
74+
sed -i '/<!-- CONTRIBUTORS_START -->/r gallery_fragment.txt' README.md
75+
76+
- name: Commit and Push
77+
run: |
78+
git config --global user.name "github-actions[bot]"
79+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
80+
git add README.md
81+
if git diff --staged --quiet; then
82+
echo "No changes to README."
83+
else
84+
git commit -m "docs: update contributor gallery"
85+
git push
86+
fi

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,13 @@ We love contributions! Here's how you can help:
575575
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
576576

577577
---
578+
## Contributors
578579

580+
<!-- CONTRIBUTORS_START -->
581+
<a href="https://github.com/Aayuiiitmg"><img src="https://github.com/Aayuiiitmg.png" width="50px" style="border-radius:50%;margin:5px;" alt="Aayuiiitmg" /></a><a href="https://github.com/Arpitawork24"><img src="https://github.com/Arpitawork24.png" width="50px" style="border-radius:50%;margin:5px;" alt="Arpitawork24" /></a><a href="https://github.com/Bhairavi-28"><img src="https://github.com/Bhairavi-28.png" width="50px" style="border-radius:50%;margin:5px;" alt="Bhairavi-28" /></a><a href="https://github.com/C4aZy"><img src="https://github.com/C4aZy.png" width="50px" style="border-radius:50%;margin:5px;" alt="C4aZy" /></a><a href="https://github.com/Diksha57-git"><img src="https://github.com/Diksha57-git.png" width="50px" style="border-radius:50%;margin:5px;" alt="Diksha57-git" /></a><a href="https://github.com/Facelessism"><img src="https://github.com/Facelessism.png" width="50px" style="border-radius:50%;margin:5px;" alt="Facelessism" /></a><a href="https://github.com/Indrayani11-15"><img src="https://github.com/Indrayani11-15.png" width="50px" style="border-radius:50%;margin:5px;" alt="Indrayani11-15" /></a><a href="https://github.com/Juhi4433"><img src="https://github.com/Juhi4433.png" width="50px" style="border-radius:50%;margin:5px;" alt="Juhi4433" /></a><a href="https://github.com/Kartikeyji17"><img src="https://github.com/Kartikeyji17.png" width="50px" style="border-radius:50%;margin:5px;" alt="Kartikeyji17" /></a><a href="https://github.com/KhushiVadadoriya"><img src="https://github.com/KhushiVadadoriya.png" width="50px" style="border-radius:50%;margin:5px;" alt="KhushiVadadoriya" /></a><a href="https://github.com/Kunal241207"><img src="https://github.com/Kunal241207.png" width="50px" style="border-radius:50%;margin:5px;" alt="Kunal241207" /></a><a href="https://github.com/Mounika-39"><img src="https://github.com/Mounika-39.png" width="50px" style="border-radius:50%;margin:5px;" alt="Mounika-39" /></a><a href="https://github.com/Naveen-Boddepalli"><img src="https://github.com/Naveen-Boddepalli.png" width="50px" style="border-radius:50%;margin:5px;" alt="Naveen-Boddepalli" /></a><a href="https://github.com/PRODHOSH"><img src="https://github.com/PRODHOSH.png" width="50px" style="border-radius:50%;margin:5px;" alt="PRODHOSH" /></a><a href="https://github.com/SANDHIYAPRIYADHARSHINI"><img src="https://github.com/SANDHIYAPRIYADHARSHINI.png" width="50px" style="border-radius:50%;margin:5px;" alt="SANDHIYAPRIYADHARSHINI" /></a><a href="https://github.com/Sanjhivvarshan-b-s"><img src="https://github.com/Sanjhivvarshan-b-s.png" width="50px" style="border-radius:50%;margin:5px;" alt="Sanjhivvarshan-b-s" /></a><a href="https://github.com/Sreekuttan-007"><img src="https://github.com/Sreekuttan-007.png" width="50px" style="border-radius:50%;margin:5px;" alt="Sreekuttan-007" /></a><a href="https://github.com/TheBinaryAVA"><img src="https://github.com/TheBinaryAVA.png" width="50px" style="border-radius:50%;margin:5px;" alt="TheBinaryAVA" /></a><a href="https://github.com/Tiago-Vier-Preto"><img src="https://github.com/Tiago-Vier-Preto.png" width="50px" style="border-radius:50%;margin:5px;" alt="Tiago-Vier-Preto" /></a><a href="https://github.com/ayushyadav0707"><img src="https://github.com/ayushyadav0707.png" width="50px" style="border-radius:50%;margin:5px;" alt="ayushyadav0707" /></a><a href="https://github.com/codewithakshyaaa"><img src="https://github.com/codewithakshyaaa.png" width="50px" style="border-radius:50%;margin:5px;" alt="codewithakshyaaa" /></a><a href="https://github.com/gatiksolanki13-netizen"><img src="https://github.com/gatiksolanki13-netizen.png" width="50px" style="border-radius:50%;margin:5px;" alt="gatiksolanki13-netizen" /></a><a href="https://github.com/iamprasoon2006-cell"><img src="https://github.com/iamprasoon2006-cell.png" width="50px" style="border-radius:50%;margin:5px;" alt="iamprasoon2006-cell" /></a><a href="https://github.com/jyotish6699"><img src="https://github.com/jyotish6699.png" width="50px" style="border-radius:50%;margin:5px;" alt="jyotish6699" /></a><a href="https://github.com/kumudasrip"><img src="https://github.com/kumudasrip.png" width="50px" style="border-radius:50%;margin:5px;" alt="kumudasrip" /></a><a href="https://github.com/madhavcodes25"><img src="https://github.com/madhavcodes25.png" width="50px" style="border-radius:50%;margin:5px;" alt="madhavcodes25" /></a><a href="https://github.com/mahi-8758"><img src="https://github.com/mahi-8758.png" width="50px" style="border-radius:50%;margin:5px;" alt="mahi-8758" /></a><a href="https://github.com/nene-hana"><img src="https://github.com/nene-hana.png" width="50px" style="border-radius:50%;margin:5px;" alt="nene-hana" /></a><a href="https://github.com/nishtha-agarwal-211"><img src="https://github.com/nishtha-agarwal-211.png" width="50px" style="border-radius:50%;margin:5px;" alt="nishtha-agarwal-211" /></a><a href="https://github.com/parasmani-dev"><img src="https://github.com/parasmani-dev.png" width="50px" style="border-radius:50%;margin:5px;" alt="parasmani-dev" /></a><a href="https://github.com/sanzzzz-g"><img src="https://github.com/sanzzzz-g.png" width="50px" style="border-radius:50%;margin:5px;" alt="sanzzzz-g" /></a><a href="https://github.com/ssuyashhhh"><img src="https://github.com/ssuyashhhh.png" width="50px" style="border-radius:50%;margin:5px;" alt="ssuyashhhh" /></a>
582+
<!-- CONTRIBUTORS_END -->
583+
584+
---
579585
## 📝 License
580586

581587
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -603,4 +609,4 @@ Found this helpful? Show some love!
603609

604610
[⬆ Back to Top](#-python-mini-projects-collection-)
605611

606-
</div>
612+
</div>

0 commit comments

Comments
 (0)