DEV Community

abhigoyani
abhigoyani

Posted on • Edited on

4 1

Add members to the .md file using github action

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 }}
Enter fullscreen mode Exit fullscreen mode

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>")
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

We are using this action in BauddhikGeeks

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay