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

GitHub logo unfor19 / replacer-action

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

replacer-action

testing test-action

Auto-update README.md file according to the source code. When to use this action?

  • CLI Help Menu: Inject the help menu of your CLI to the README.md file, see Help Menu
  • Test Results: Share test results in your README.md file, see bargs test suite
  • API Response: Keep your README.md up-to-date with the response of your APIs

Tested in unfor19/replacer-action-test

How It Works

  1. Uses perl to manipulate the destination file - README.md
  2. Executes git diff to check if there are any changes in README.md
  3. If there are no changes, exits successfully
  4. If there are changes, executes git commit followed by git push

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 
โ€ฆ
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.

Oldest comments (0)