forked from Pradeepsingh61/DSA_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (135 loc) Β· 6.53 KB
/
update-contributors.yml
File metadata and controls
167 lines (135 loc) Β· 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: π Update Contributors
on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]
workflow_dispatch: # Allow manual trigger
permissions:
contents: write
pull-requests: write
jobs:
update-contributors:
runs-on: ubuntu-latest
# Only run on push to main or when PR is merged (not just closed)
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: π Get contributor stats
id: contributors
run: |
echo "π Fetching contributor statistics..."
# Get contributors with commit counts, excluding GitHub Actions users
contributors=$(curl -s "https://api.github.com/repos/${{ github.repository }}/contributors?per_page=100" | \
jq -r '.[] | select(.login != "github-actions[bot]" and .login != "actions-user" and .type != "Bot") | "\(.login) \(.contributions)"')
echo "Contributors found (excluding bots):"
echo "$contributors"
# Count total contributors (excluding bots)
total_contributors=$(echo "$contributors" | grep -v '^$' | wc -l)
echo "total_contributors=$total_contributors" >> $GITHUB_OUTPUT
# Get top contributors
top_contributors=$(echo "$contributors" | head -10)
echo "top_contributors<<EOF" >> $GITHUB_OUTPUT
echo "$top_contributors" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: π Update repository stats
run: |
echo "π Updating repository statistics..."
# Update stats in README.md
if [ -f "README.md" ]; then
# Update contributor count in README
sed -i "s/π― \*\*[0-9]*+ Contributors\*\*/π― **${{ steps.contributors.outputs.total_contributors }}+ Contributors**/g" README.md
echo "β
Updated README.md with new contributor count"
fi
# Update stats in HALL_OF_FAME.md
if [ -f "HALL_OF_FAME.md" ]; then
# Update contributor count in Hall of Fame
sed -i "s/\*\*Total 2024 Contributors: [0-9]*+ Amazing Developers!\*\*/\*\*Total 2024 Contributors: ${{ steps.contributors.outputs.total_contributors }}+ Amazing Developers!\*\*/g" HALL_OF_FAME.md
sed -i "s/We extend our heartfelt gratitude to all \*\*[0-9]*+ contributors\*\*/We extend our heartfelt gratitude to all **${{ steps.contributors.outputs.total_contributors }}+ contributors**/g" HALL_OF_FAME.md
sed -i "s/| π₯ \*\*Total Contributors\*\* | [0-9]*+ Amazing Developers |/| π₯ **Total Contributors** | ${{ steps.contributors.outputs.total_contributors }}+ Amazing Developers |/g" HALL_OF_FAME.md
echo "β
Updated HALL_OF_FAME.md with new contributor count"
fi
- name: π Update language statistics
run: |
echo "π Updating language statistics..."
# Count files by language
c_files=$(find C/ -name "*.c" 2>/dev/null | wc -l || echo 0)
cpp_files=$(find CPP/ -name "*.cpp" 2>/dev/null | wc -l || echo 0)
java_files=$(find Java/ -name "*.java" 2>/dev/null | wc -l || echo 0)
python_files=$(find Python/ -name "*.py" 2>/dev/null | wc -l || echo 0)
js_files=$(find . -name "*.js" -not -path "./node_modules/*" 2>/dev/null | wc -l || echo 0)
go_files=$(find . -name "*.go" 2>/dev/null | wc -l || echo 0)
rust_files=$(find . -name "*.rs" 2>/dev/null | wc -l || echo 0)
total_implementations=$((c_files + cpp_files + java_files + python_files + js_files + go_files + rust_files))
echo "π Language Statistics:"
echo "C: $c_files files"
echo "C++: $cpp_files files"
echo "Java: $java_files files"
echo "Python: $python_files files"
echo "JavaScript: $js_files files"
echo "Go: $go_files files"
echo "Rust: $rust_files files"
echo "Total: $total_implementations implementations"
# Count supported languages
supported_languages=4 # Base languages: C, C++, Java, Python
[ $js_files -gt 0 ] && supported_languages=$((supported_languages + 1))
[ $go_files -gt 0 ] && supported_languages=$((supported_languages + 1))
[ $rust_files -gt 0 ] && supported_languages=$((supported_languages + 1))
echo "Supported languages: $supported_languages"
# Update README stats
if [ -f "README.md" ]; then
sed -i "s/π» \*\*[0-9]*+ Languages\*\*/π» **${supported_languages}+ Languages**/g" README.md
fi
- name: π
Update last modified date
run: |
echo "π
Updating last modified date..."
current_date=$(date +"%B %Y")
if [ -f "HALL_OF_FAME.md" ]; then
sed -i "s/\*Last updated: .* [0-9]*\*/\*Last updated: $current_date\*/g" HALL_OF_FAME.md
echo "β
Updated last modified date in HALL_OF_FAME.md"
fi
- name: π Check for changes
id: changes
run: |
if git diff --quiet; then
echo "No changes to commit"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changed files:"
git diff --name-only
fi
- name: πΎ Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md HALL_OF_FAME.md
git commit -m "π Auto-update contributor statistics
- Updated contributor count: ${{ steps.contributors.outputs.total_contributors }}+ amazing developers
- Refreshed repository statistics
- Updated last modified date
π€ Generated by GitHub Actions"
git push
- name: π Generate summary
run: |
echo "π Contributors Update Summary"
echo "=============================="
echo ""
echo "π Statistics:"
echo " π₯ Total Contributors: ${{ steps.contributors.outputs.total_contributors }}"
echo " π₯ Repository Status: Active"
echo " π
Last Updated: $(date)"
echo ""
echo "π Contributor statistics updated successfully!"
if [ "${{ steps.changes.outputs.has_changes }}" == "true" ]; then
echo "β
Changes committed and pushed"
else
echo "βΉοΈ No changes needed"
fi