Skip to content

Commit ed34033

Browse files
authored
Add workflow to update README with topics
Signed-off-by: mlamp99 <michael.lamp@avnet.com>
1 parent eddb8c1 commit ed34033

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Update README with Topics
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-readme:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v3
14+
- name: Fetch current Topics via GitHub API
15+
id: get_topics
16+
run: |
17+
RESPONSE=$(curl -s \
18+
-H "Accept: application/vnd.github.v3+json" \
19+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
20+
https://api.github.com/repos/${{ github.repository }}/topics)
21+
TOPIC_NAMES=$(echo "$RESPONSE" | jq -r '.names | join(",")')
22+
echo "names=$TOPIC_NAMES" >> $GITHUB_OUTPUT
23+
- name: Update README with current Topics
24+
id: update_readme
25+
run: |
26+
BULLET_LIST=$(echo ${{ steps.get_topics.outputs.names }} | sed 's/,/\n- /g')
27+
sed -i "/<!-- START:topics -->/,/<!-- END:topics -->/c\\<!-- START:topics -->\n- $BULLET_LIST\n<!-- END:topics -->" README.md
28+
29+
- name: Commit and Push changes (if any)
30+
run: |
31+
if [ -n "$(git status --porcelain)" ]; then
32+
git config user.name "github-actions"
33+
git config user.email "github-actions@github.com"
34+
git add README.md
35+
git commit -m "Auto-update README with latest topics"
36+
git push
37+
else
38+
echo "No changes to commit."

0 commit comments

Comments
 (0)