DEV Community

Cover image for Auto-Update README.md According To Source Code
Meir Gabay
Meir Gabay

Posted on • Updated on

 

Auto-Update README.md According To Source Code

My Workflow

This action assists with keeping README.md files up to date with your application's outputs.

Some use cases for auto-generating text blocks in a README.md file

  • Showing available commands of the CLI that you've created (--help)
  • Results after querying an API endpoint
  • Bragging with tests results

How it works

  1. Add <! -- replacer_start --> before the text block
  2. Add <!-- replacer_end --> after the text block
  3. Set the inputs
    • src-file-path
    • dst-file-path

For more information, jump to the Getting Started section

Submission Category:

  • Maintainer Must-Haves
  • DIY Deployments

Yaml File or Link to Code

View in GitHub Market Place

replacer-action

testing

Auto-update README.md file according to the source code.

Requirements

  1. Insert a start tag and stop tag to a text file, for example
<!-- replacer_start -->

<div>User name will appear here instead</div>

<!-- replacer_end -->
Enter fullscreen mode Exit fullscreen mode
  1. Prepare a file with the text that you want to inject
$ echo -e '<div>This is the incoming text block</div>\n<div>It worked!</div>' > test_results.log
Enter fullscreen mode Exit fullscreen mode

Usage

GitHub Action

name: Update README.md
on
  push:
    branches: [master]
    paths-ignore:
      - "README.md"

jobs:
  update-readme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Prepare source file
        run: |
          echo "<div>$(whoami)</div>" > test_results.log
      - uses: unfor19/replacer-action@v1.0.2
        name: Update README.md file
        with:
          src-file-path: "test_results.log"
          dst-file-path: "README.md"
          start-value: "<!-- replacer_start -->"
          end-value: "<!-- replacer_end -->"
          git-user-name: "
Enter fullscreen mode Exit fullscreen mode

pipeline.yml

name: Update README.md
on:
  push:
    branches: [master]
    paths-ignore:
      - "README.md"

jobs:
  update-readme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Prepare source file
        run: |
          echo "<div>$(whoami)</div>" > test_results.log
      - uses: unfor19/replacer-action@v1.0.0
        name: Update README.md file
        with:
          src-file-path:   "test_results.log"
          dst-file-path:   "README.md"
          start-value:     "<!-- replacer_start -->"
          end-value:       "<!-- replacer_end -->"
          git-user-name:   "GitHub Actions"
          git-user-email:  "githubactions@meirg.co.il"
          git-commit-msg:  "Updated by GitHubActions"
          git-skip-commit: false
          git-skip-push:   false
          create-backup:   true
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

Repositories which are using this workflow

  • replacer - replacer-action is based on this repository and also uses replacer to auto-generate the help message
  • bargs - Parsing command-line arguments in Bash easily, read more about it in this blog post. This repository is generating tests results automatically, see here

Feel free to doubt/ask questions/contribute to this project, any feedback is good feedback.

Top comments (0)