Skip to content

Commit

Permalink
Add 'Used By' section and GitHub Action to update it
Browse files Browse the repository at this point in the history
  • Loading branch information
byt3n33dl3 committed Jul 18, 2024
1 parent b871dd1 commit 2c1d698
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/update-used-by.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Update Used By Section

on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
workflow_dispatch: # Allows for manual triggering of the workflow

jobs:
update-used-by:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Fetch repositories using this project
run: |
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/search/repositories?q=BlackMarlinExec+in:file \
> used_by_repos.json
- name: Update README
run: |
python update_readme.py
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m 'Update Used By section'
git push
Empty file added README.md
Empty file.
17 changes: 17 additions & 0 deletions blackmarlinexec_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json

with open('used_by_repos.json') as f:
data = json.load(f)

repos = data.get('items', [])

with open('README.md', 'r') as f:
lines = f.readlines()

start_idx = next(i for i, line in enumerate(lines) if line.strip() == "## Used By") + 1
end_idx = next((i for i, line in enumerate(lines[start_idx:], start=start_idx) if line.startswith("##")), len(lines))

new_lines = lines[:start_idx] + [f"- [{repo['full_name']}]({repo['html_url']}): {repo.get('description', 'No description available')}\n" for repo in repos] + lines[end_idx:]

with open('README.md', 'w') as f:
f.writelines(new_lines)

0 comments on commit 2c1d698

Please sign in to comment.