|
| 1 | +name: Update Fork Users List |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + update-fork-list: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Fetch Fork Users and Update Markdown |
| 19 | + id: generate |
| 20 | + uses: actions/github-script@v7 |
| 21 | + with: |
| 22 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + script: | |
| 24 | + const fs = require('fs'); |
| 25 | + const owner = context.repo.owner; |
| 26 | + const repo = context.repo.repo; |
| 27 | +
|
| 28 | + const allForks = await github.paginate( |
| 29 | + github.rest.repos.listForks, |
| 30 | + { owner, repo, per_page: 100 } |
| 31 | + ); |
| 32 | +
|
| 33 | + const forkUsernames = allForks.map(fork => `- [@${fork.owner.login}](https://github.com/${fork.owner.login})`); |
| 34 | + const forkCount = forkUsernames.length; |
| 35 | +
|
| 36 | + const newContent = [ |
| 37 | + '# Repo Fork Users', |
| 38 | + '', |
| 39 | + `Total Forks: **${forkCount}**`, |
| 40 | + '', |
| 41 | + '## List of Fork Users:', |
| 42 | + forkUsernames.join('\n') |
| 43 | + ].join('\n'); |
| 44 | +
|
| 45 | + fs.writeFileSync('repo-master.md', newContent); |
| 46 | +
|
| 47 | + - name: Check for changes in repo-master.md |
| 48 | + id: check_changes |
| 49 | + run: | |
| 50 | + git add repo-master.md |
| 51 | + if git diff --staged --quiet; then |
| 52 | + echo "No changes detected" |
| 53 | + else |
| 54 | + echo "changes_detected=true" >> $GITHUB_ENV |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Commit and Push Changes if Fork List Updated |
| 58 | + if: env.changes_detected == 'true' |
| 59 | + run: | |
| 60 | + git config user.name "GitHub Action Bot" |
| 61 | + git config user.email "action@github.com" |
| 62 | + git add repo-master.md |
| 63 | + git commit -m "Update repo-master.md with latest fork user list" |
| 64 | + git push |
0 commit comments