My Workflow
This workflow read all the files in members folder and add in a table in the Members.md file it runs on PUSH event.
github Repo
Submission Category:
Wacky Wildcards
Yaml File or Link to Code
Workflow:
name: Add members to .md file
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner
- name: setup python
uses: actions/setup-python@v2
with:
python-version: '3.7.7' # install the python version needed
- name: execute py script # run sj-gobierno.py to get the latest data
run: python add.py
- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Added member" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
add.py :
import os
users = []
data = '<td align="center"><a href="https://github.com/{username}"><img src="https://github.com/{username}.png" width="100px;" alt=""/><br /><sub><b>{name}</b></sub></a></td>\n'
for filename in os.listdir("members"):
with open(os.path.join("members", filename), 'r') as f:
text = f.readlines()
users.append({"name":text[1][7:-1],"username":text[2][11:-1]})
with open("Members.md","w") as f:
f.write("<table>\n")
for i in range(len(users)):
if(i%10 == 0):
f.write("<tr>\n")
f.write(data.format(name=users[i]["name"],username=users[i]["username"]))
if((i+1)%10 == 0):
f.write("</tr>\n")
f.write("</table>")
Additional Resources / Info
We are using this action in BauddhikGeeks
Top comments (0)