Update Profile README #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Update Profile README | |
| "on": | |
| schedule: | |
| - cron: "0 6 * * 1" # Every Monday at 06:00 UTC | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| update-readme: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Fetch recently updated cookbooks | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api "orgs/sous-chefs/repos?sort=updated&direction=desc&per_page=30&type=public" \ | |
| --jq ' | |
| [ | |
| .[] | |
| | select( | |
| .name != ".github" | |
| and .archived == false | |
| and .fork == false | |
| ) | |
| ] | |
| | .[0:10] | |
| ' > /tmp/repos.json | |
| echo "Fetched $(jq 'length' /tmp/repos.json) cookbooks" | |
| - name: Fetch latest merged PRs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mkdir -p /tmp/prs | |
| for repo in $(jq -r '.[].name' /tmp/repos.json); do | |
| gh api "repos/sous-chefs/${repo}/pulls?state=closed&sort=updated&direction=desc&per_page=5" \ | |
| --jq '[.[] | select(.merged_at != null)][0]' \ | |
| > "/tmp/prs/${repo}.json" 2>/dev/null || echo 'null' > "/tmp/prs/${repo}.json" | |
| done | |
| - name: Fetch org members | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api "orgs/sous-chefs/members?per_page=60" \ | |
| --jq ' | |
| .[] | |
| | "<a href=\"\(.html_url)\"><img src=\"\(.avatar_url)&s=64\" width=\"48\" height=\"48\" alt=\"\(.login)\" title=\"\(.login)\" /></a>" | |
| ' > /tmp/members.txt | |
| echo "Fetched $(wc -l < /tmp/members.txt) members" | |
| - name: Update README | |
| run: | | |
| ruby - <<'RUBYEOF' | |
| require "json" | |
| require "time" | |
| readme = "profile/README.md" | |
| content = File.read(readme) | |
| repos = JSON.parse(File.read("/tmp/repos.json")) | |
| rows = repos.map do |repo| | |
| name = repo["name"] | |
| url = repo["html_url"] | |
| desc = repo["description"] || "A Chef cookbook" | |
| updated = Time.parse(repo["updated_at"]).strftime("%b %d, %Y") | |
| pr_path = "/tmp/prs/#{name}.json" | |
| pr = begin | |
| data = JSON.parse(File.read(pr_path)) | |
| data unless data.nil? || data.is_a?(String) | |
| rescue JSON::ParserError, Errno::ENOENT | |
| nil | |
| end | |
| change = if pr | |
| "[#{pr['title']}](#{pr['html_url']})" | |
| else | |
| "—" | |
| end | |
| "| [#{name}](#{url}) | #{desc} | #{change} | #{updated} |" | |
| end | |
| unless rows.empty? | |
| table = "| Cookbook | Description | Latest Change | Last Updated |\n| --- | --- | --- | --- |\n#{rows.join("\n")}" | |
| content.gsub!(/<!-- COOKBOOKS_START -->.*?<!-- COOKBOOKS_END -->/m, | |
| "<!-- COOKBOOKS_START -->\n#{table}\n<!-- COOKBOOKS_END -->") | |
| end | |
| avatars = File.read("/tmp/members.txt").strip | |
| unless avatars.empty? | |
| content.gsub!(/<!-- CONTRIBUTORS_START -->.*?<!-- CONTRIBUTORS_END -->/m, | |
| "<!-- CONTRIBUTORS_START -->\n#{avatars}\n<!-- CONTRIBUTORS_END -->") | |
| end | |
| File.write(readme, content) | |
| puts "README updated successfully" | |
| RUBYEOF | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add profile/README.md | |
| git diff --staged --quiet \ | |
| || git commit -m "chore: update profile README with latest cookbooks and members" | |
| git push |