Update README.md #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Table of Contents | |
on: | |
push: | |
branches: | |
- main # Change this to your main branch name if different | |
paths: | |
- 'README.md' | |
jobs: | |
update-toc: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 # is a GitHub Actions community-maintained action that you can use in your workflows to check out your repository's code on the runner machine where the workflow is executed. The @v2 refers to a specific release version of the action (action at version v2). The v2 version tag represents a specific release version of the actions/checkout action. This version is often used. The purpose of this action is to clone or checkout the repository's code into the working directory of the GitHub Actions runner machine. When GitHub Actions workflows run, they start in a clean environment without the code of your repository. The actions/checkout action ensures that the code is available for the subsequent steps in the workflow. | |
- name: Run doctoc Docker Container | |
run: docker run --rm -v "$(pwd)":/app peterdavehello/npm-doctoc doctoc /app/README.md | |
- name: Check if README was modified | |
id: check-changes | |
continue-on-error: true # Allow non-zero exit code | |
run: | | |
git diff --exit-code README.md # if README.md was modified, it returns 1 (failure). If it wasn't modified, it returns 0 (success) | |
- name: Commit and Push Changes | |
if: steps.check-changes.outcome == 'failure' | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" # you can use [email protected] as the email address in the git config for GitHub Actions workflows. This email address is commonly used in automated workflows, and GitHub recognizes it as a generic or default email address associated with actions. | |
git add README.md | |
git commit -m "Update Table of Contents" | |
git push |