|
| 1 | +name: Update Contributors (Git-based) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [closed] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + update-contributors: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Generate Contributors List |
| 27 | + run: | |
| 28 | + echo "# Contributors" > CONTRIBUTORS.md |
| 29 | + echo "" >> CONTRIBUTORS.md |
| 30 | + echo "Thank you to all our contributors! This file is automatically generated from git history." >> CONTRIBUTORS.md |
| 31 | + echo "" >> CONTRIBUTORS.md |
| 32 | +
|
| 33 | + # Get all contributors sorted by number of commits |
| 34 | + echo "## Contributors by Commits" >> CONTRIBUTORS.md |
| 35 | + echo "" >> CONTRIBUTORS.md |
| 36 | + git log --format='%aN' | sort | uniq -c | sort -rn | while read count name; do |
| 37 | + echo "- **$name** - $count commits" >> CONTRIBUTORS.md |
| 38 | + done |
| 39 | +
|
| 40 | + echo "" >> CONTRIBUTORS.md |
| 41 | + echo "## All Contributors (Alphabetical)" >> CONTRIBUTORS.md |
| 42 | + echo "" >> CONTRIBUTORS.md |
| 43 | +
|
| 44 | + # Get unique contributors alphabetically |
| 45 | + git log --format='%aN' | sort -u | while read name; do |
| 46 | + echo "- $name" >> CONTRIBUTORS.md |
| 47 | + done |
| 48 | +
|
| 49 | + echo "" >> CONTRIBUTORS.md |
| 50 | + echo "---" >> CONTRIBUTORS.md |
| 51 | + echo "_Last updated: $(date -u +"%Y-%m-%d %H:%M:%S UTC")_" >> CONTRIBUTORS.md |
| 52 | +
|
| 53 | + - name: Check for changes |
| 54 | + id: check_changes |
| 55 | + run: | |
| 56 | + if git diff --quiet CONTRIBUTORS.md; then |
| 57 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 58 | + else |
| 59 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 60 | + fi |
| 61 | +
|
| 62 | + - name: Commit changes |
| 63 | + if: steps.check_changes.outputs.changed == 'true' |
| 64 | + run: | |
| 65 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | + git config --local user.name "github-actions[bot]" |
| 67 | + git add CONTRIBUTORS.md |
| 68 | + git commit -m "docs: update CONTRIBUTORS.md [skip ci]" |
| 69 | +
|
| 70 | + - name: Push changes |
| 71 | + if: steps.check_changes.outputs.changed == 'true' |
| 72 | + uses: ad-m/github-push-action@master |
| 73 | + with: |
| 74 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + branch: ${{ github.ref }} |
0 commit comments