Home

Awesome

TOC Generator

CI Status codecov CodeFactor License: MIT

Read this in other languages: English, 日本語.

This is a GitHub Actions to generate TOC (Table of Contents),
which executes DocToc and commits if changed.

Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <details> <summary>Details</summary> </details> <!-- END doctoc generated TOC please keep comment here to allow auto update -->

Installation

  1. Specify location of TOC (option)
    e.g. README.md
    <!-- START doctoc -->
    <!-- END doctoc -->
    
    detail
  2. Setup workflow
    e.g. .github/workflows/toc.yml
    on: push
    name: TOC Generator
    jobs:
      generateTOC:
        name: TOC Generator
        runs-on: ubuntu-latest
        steps:
          - uses: technote-space/toc-generator@v4
    

Screenshot

behavior

Options

namedescriptiondefaulte.g.
TARGET_PATHSTarget file path. (Comma separated, Detail)README*.mdREADME*.md,CHANGELOG.md, .
TOC_TITLETOC Title**Table of Contents**''
MAX_HEADER_LEVELMaximum heading level. (Detail)3
CUSTOM_MODEWhether it is custom mode(Generated Example)falsetrue
CUSTOM_TEMPLATECustom template for custom mode<p align="center">${ITEMS}</p>
ITEM_TEMPLATEItem template for custom mode<a href="${LINK}">${TEXT}</a>
SEPARATORSeparator for custom mode<code><span>|</span></code>
FOLDINGWhether to make TOC foldablefalsetrue
COMMIT_MESSAGECommit messagechore(docs): update TOCdocs: update TOC
COMMIT_NAMEGit commit name${github.actor}
COMMIT_EMAILGit commit email${github.actor}@users.noreply.github.com
CREATE_PRWhether to create PullRequestfalsetrue
CHECK_ONLY_DEFAULT_BRANCHWhether to check only default branchfalsetrue
PR_BRANCH_PREFIXPullRequest branch prefixtoc-generator/
PR_BRANCH_NAMEPullRequest branch name<br>Context variablesupdate-toc-${PR_ID}toc-${PR_NUMBER}
PR_TITLEPullRequest title<br>Context variableschore(docs): update TOC (${PR_MERGE_REF})docs: update TOC
PR_BODYPullRequest body<br>Context PR variablesaction.yml
PR_COMMENT_BODYPullRequest body for comment<br>Context PR variablesaction.yml
PR_CLOSE_MESSAGEMessage body when closing PullRequestThis PR has been closed because it is no longer needed.
TARGET_BRANCH_PREFIXFilter by branch namerelease/
INCLUDE_LABELSLabels used to check if the PullRequest has itLabel1, Label2
OPENING_COMMENTOpening comment (for other than DocToc)<!-- toc
CLOSING_COMMENTClosing comment (for other than DocToc)<!-- tocstop
SKIP_COMMENTChange skip comment (default: <!-- DOCTOC SKIP )<!-- toc skip
GITHUB_TOKENAccess token${{github.token}}${{secrets.ACCESS_TOKEN}}
SIGNOFFAdd Signed-off-by linetrue

Specify options individually

The options used for doctoc can be commented to specify values.
If you want to generate multiple TOCs with different settings, specify the values individually as follows.

e.g.

<!-- START doctoc -->
<!-- param::isNotitle::true:: -->
<!-- param::isCustomMode::true:: -->

<!-- END doctoc -->

...

Action event details

Target event

eventName: actioncondition
push: *condition1
pull_request: [opened, synchronize, reopened, labeled, unlabeled]condition2
pull_request: [closed]
schedule, repository_dispatch, workflow_dispatch

Conditions

condition1

condition2

Addition

GITHUB_TOKEN

The GITHUB_TOKEN that is provided as a part of GitHub Actions doesn't have authorization to create any successive events.
So it won't spawn actions which triggered by push.

This can be a problem if you have branch protection configured.

If you want to trigger actions, use a personal access token instead.

  1. Generate a personal access token with the public_repo or repo scope.
    (repo is required for private repositories).
  2. Save as ACCESS_TOKEN
  3. Add input to use ACCESS_TOKEN instead of GITHUB_TOKEN.
    e.g. .github/workflows/toc.yml
    on: push
    name: TOC Generator
    jobs:
      generateTOC:
        name: TOC Generator
        runs-on: ubuntu-latest
        steps:
          - uses: technote-space/toc-generator@v4
            with:
              GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
    

Create PullRequest

If CREATE_PR is set to true, a PullRequest is created.

on: pull_request
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4
        with:
          CREATE_PR: true

create pr

If the closed activity type is set, this action closes the PR when it is no longer needed.

on:
  pull_request:
    types: [opened, synchronize, reopened, closed]
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4

Context variables

namedescription
PR_NUMBERpull_request.number (e.g. 11)
PR_NUMBER_REF#${pull_request.number} (e.g. #11)
PR_IDpull_request.id (e.g. 21031067)
PR_HEAD_REFpull_request.head.ref (e.g. change)
PR_BASE_REFpull_request.base.ref (e.g. main)
PR_MERGE_REFpull_request.base.ref (e.g. change -> main)
PR_TITLEpull_request.title (e.g. update the README with new information.)

Payload example

Context PR variables

namedescription
PR_LINKLink to PR
COMMANDS_OUTPUTResult of TOC command
FILES_SUMMARYe.g. Changed 2 files
FILESChanged file list

Configuration Examples

Example 1

Execute actions at push without limiting the branch and commit directly

on: push
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4

Example 2

Create or update a Pull Request by executing actions on a Pull Request update only for branches starting with release/.

on:
  pull_request:
    types: [opened, synchronize, reopened, closed]
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4
        with:
          CREATE_PR: true
          TARGET_BRANCH_PREFIX: release/

Example 3

Execute actions in the schedule for the default branch only and commit directly.
(Using the Token created for the launch of other workflows)

on:
  schedule:
    - cron: "0 23 * * *"
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4
        with:
          GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
          CHECK_ONLY_DEFAULT_BRANCH: true

Author

GitHub (Technote)
Blog