Giter Club home page Giter Club logo

toc-generator's Introduction

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

Details

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

name description default e.g.
TARGET_PATHS Target file path. (Comma separated, Detail) README*.md README*.md,CHANGELOG.md, .
TOC_TITLE TOC Title **Table of Contents** ''
MAX_HEADER_LEVEL Maximum heading level. (Detail) 3
CUSTOM_MODE Whether it is custom mode(Generated Example) false true
CUSTOM_TEMPLATE Custom template for custom mode <p align="center">${ITEMS}</p>
ITEM_TEMPLATE Item template for custom mode <a href="${LINK}">${TEXT}</a>
SEPARATOR Separator for custom mode <span>|</span>
FOLDING Whether to make TOC foldable false true
COMMIT_MESSAGE Commit message chore(docs): update TOC docs: update TOC
COMMIT_NAME Git commit name ${github.actor}
COMMIT_EMAIL Git commit email ${github.actor}@users.noreply.github.com
CREATE_PR Whether to create PullRequest false true
CHECK_ONLY_DEFAULT_BRANCH Whether to check only default branch false true
PR_BRANCH_PREFIX PullRequest branch prefix toc-generator/
PR_BRANCH_NAME PullRequest branch name
Context variables
update-toc-${PR_ID} toc-${PR_NUMBER}
PR_TITLE PullRequest title
Context variables
chore(docs): update TOC (${PR_MERGE_REF}) docs: update TOC
PR_BODY PullRequest body
Context PR variables
action.yml
PR_COMMENT_BODY PullRequest body for comment
Context PR variables
action.yml
PR_CLOSE_MESSAGE Message body when closing PullRequest This PR has been closed because it is no longer needed.
TARGET_BRANCH_PREFIX Filter by branch name release/
INCLUDE_LABELS Labels used to check if the PullRequest has it Label1, Label2
OPENING_COMMENT Opening comment (for other than DocToc) <!-- toc
CLOSING_COMMENT Closing comment (for other than DocToc) <!-- tocstop
SKIP_COMMENT Change skip comment (default: <!-- DOCTOC SKIP ) <!-- toc skip
GITHUB_TOKEN Access token ${{github.token}} ${{secrets.ACCESS_TOKEN}}
SIGNOFF Add Signed-off-by line true

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: action condition
push: * condition1
pull_request: [opened, synchronize, reopened, labeled, unlabeled] condition2
pull_request: [closed]
schedule, repository_dispatch, workflow_dispatch
  • The following activity types must be explicitly specified (detail)
    • labeled, unlabeled, closed

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

name description
PR_NUMBER pull_request.number (e.g. 11)
PR_NUMBER_REF #${pull_request.number} (e.g. #11)
PR_ID pull_request.id (e.g. 21031067)
PR_HEAD_REF pull_request.head.ref (e.g. change)
PR_BASE_REF pull_request.base.ref (e.g. main)
PR_MERGE_REF pull_request.base.ref (e.g. change -> main)
PR_TITLE pull_request.title (e.g. update the README with new information.)

Payload example

Context PR variables

name description
PR_LINK Link to PR
COMMANDS_OUTPUT Result of TOC command
FILES_SUMMARY e.g. Changed 2 files
FILES Changed 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

toc-generator's People

Contributors

dependabot-preview[bot] avatar github-actions[bot] avatar hanxiao avatar hexagonrecursion avatar janpio avatar technote-space avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

toc-generator's Issues

add support for horizontal TOC

Please describe your suggestion: 提案の概要

TOC generator now gives vertical TOC only, would be nice to have a horizontal one

Describe the solution you'd like: 考えうる解決方法

Add an option HORIZONTAL_TOC or FLATTEN_TOC as boolean value

Expected result:
image

Remark: horizontal toc only makes sense when MAX_HEADER_LEVEL = 1

Describe alternatives you've considered: 考えうる代替案

Additional context: 補足

fix: close message

package dependencies 更新用のやつのメッセージのままになっている

TOC generator seems broken when content is too long?

Describe the bug: バグの概要

First, thank you for providing this awesome action, we have been using it since early this year! Thanks ❤️ 🙇

Recently, we found the TOC generator seems not to work properly anymore. In particular, on this CHANGELOG.md, it stops working after 0.7.4. I suspect if the document is too long to process?

Screenshots: スクリーンショット

Github workflow

https://github.com/jina-ai/jina/blob/f087726b31f8901c27cc6e27211ebd82e473f100/.github/workflows/autocommit.yml#L67-L77

Here is the dump log from Github action

  with:
    MAX_HEADER_LEVEL: 2
    FOLDING: false
    GITHUB_TOKEN: ***
    COMMIT_NAME: Jina Dev Bot
    COMMIT_EMAIL: [email protected]
    TARGET_PATHS: README*.md,CHANGELOG.md,CONTRIBUTING.md
    COMMIT_MESSAGE: chore(docs): update TOC
    OPENING_COMMENT: <!-- toc 
    CLOSING_COMMENT: <!-- tocstop 
    CREATE_PR: true
    PR_BRANCH_PREFIX: toc-generator/
    PR_BRANCH_NAME: update-toc-${PR_ID}
    PR_TITLE: docs: update TOC (${PR_MERGE_REF})
    PR_BODY: ## Base PullRequest
  
  ${PR_TITLE} (${PR_NUMBER_REF})
  
  ## Command results
  <details>
    <summary>Details: </summary>
  
    ${COMMANDS_OUTPUT}
  
  </details>
  
  ## Changed files
  <details>
    <summary>${FILES_SUMMARY}: </summary>
  
    ${FILES}
  
  </details>
  
  <hr>
  
  [:octocat: Repo](${ACTION_URL}) | [:memo: Issues](${ACTION_URL}/issues) | [:department_store: Marketplace](${ACTION_MARKETPLACE_URL})
  
    PR_COMMENT_BODY: ## Command results
  <details>
    <summary>Details: </summary>
  
    ${COMMANDS_OUTPUT}
  
  </details>
  
  ## Changed files
  <details>
    <summary>${FILES_SUMMARY}: </summary>
  
    ${FILES}
  
  </details>
  
  <hr>
  
  [:octocat: Repo](${ACTION_URL}) | [:memo: Issues](${ACTION_URL}/issues) | [:department_store: Marketplace](${ACTION_MARKETPLACE_URL})
  
    PR_CLOSE_MESSAGE: This PR has been closed because it is no longer needed.
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.7.9/x64

==================================================
Version:  technote-space/[email protected]
          b1dc535f5ffbd5cd62324411eb2a1874074337e5
Event:    schedule
Action:   undefined
sha:      af9777d515ed03b8f1b6cff80545685976f8102b
ref:      refs/heads/master
owner:    jina-ai
repo:     jina

Dump context
  Context {
    payload: { schedule: '0 23 * * *' },
    eventName: 'schedule',
    sha: 'af9777d515ed03b8f1b6cff80545685976f8102b',
    ref: 'refs/heads/master',
    workflow: 'Autocommit',
    action: 'technote-spacetoc-generator',
    actor: 'hanxiao',
    job: 'autocommit',
    runNumber: 25,
    runId: 375316966
  }
Dump Payload
  { schedule: '0 23 * * *' }
==================================================

Operating environment: バグが発生した環境

  • Version of software
  • OS: [e.g. Windows10]
  • Browser: [e.g. Chrome, Safari]
  • etc.

Additional context: 補足

Mirrored: jina-ai/jina#1321

Emojis in headers don't work

Describe the bug: バグの概要

When you add emojis to your headers, TOC doesn't work - it generates correctly, but it's links don't always work:

  • some generate without the emoji - those usually work, but some not (the ☎️ phone emoji acts like this - doesn't work)
  • some generate with emoji - and all of those don't work for me :/

What always work, is links on the Github itself (when you click on left of header) - some of them also generate with or without emoji encoded in the url - and work/don't work if you remove it

To Reproduce: 再現手順

Steps to reproduce the behavior:

  1. Make header with rainbow emoji 🌈 - fully works
  2. Make header with termometer emoji 🌡 - doesn't work
  3. Make header with phone emoji ☎️ - doesn't work most, and it's the most weird one

Expected behavior: 期待する動作

Should direct you to this header section

Create PullRequest

Please describe your suggestion: 提案の概要

変更を直接commitするのではなくプルリクを作成する機能を追加

Describe the solution you'd like: 考えうる解決方法

Describe alternatives you've considered: 考えうる代替案

Additional context: 補足

Action fails to run because of broken dependency.

Describe the bug: バグの概要

Currently facing an issue running this action, where it prints this error:

command [npx doctoc /home/runner/work/codeql-learninglab-actions/codeql-learninglab-actions/README*.md --title '**Table of Contents**' --github] exited with code 1. message: Command failed: npx doctoc /home/runner/work/codeql-learninglab-actions/codeql-learninglab-actions/README*.md --title '**Table of Contents**' --github
  internal/modules/cjs/loader.js:796
      throw err;
      ^
  
  Error: Cannot find module 'which'
  Require stack:
  - /usr/local/lib/node_modules/npm/node_modules/libnpx/index.js
  - /usr/local/lib/node_modules/npm/bin/npx-cli.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
      at Function.Module._load (internal/modules/cjs/loader.js:686:27)
      at Module.require (internal/modules/cjs/loader.js:848:19)
      at require (internal/modules/cjs/helpers.js:74:18)
      at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/libnpx/index.js:10:25)
      at Module._compile (internal/modules/cjs/loader.js:955:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
      at Module.load (internal/modules/cjs/loader.js:811:32)
      at Function.Module._load (internal/modules/cjs/loader.js:723:14)
      at Module.require (internal/modules/cjs/loader.js:848:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [

See: https://github.com/github/codeql-learninglab-actions/runs/411835295?check_suite_focus=true

Looks like it's probably a dependency issue in doctoc, maybe some dependency relying on an implicit dependency?

To Reproduce: 再現手順

Steps to reproduce the behavior:

  1. Run a workflow with this action
  2. See error

Expected behavior: 期待する動作

Action runs without module resolution error.

Operating environment: バグが発生した環境

Workflow with this config:

jobs:
  generateTOC:
    runs-on: ubuntu-latest
    name: Generate Table of Contents
    steps:
      - name: TOC Generator
        uses: technote-space/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Seems to also happen when bumping to v2.0.9

private repository への対応

git コマンドで clone している + access token を使用していないため private なものは取得不可

access token の設定は面倒なので使用しない
actions/checkout などで取得済みの場合はそれを使用するように対応
無ければ今まで通りgitコマンドで取得

wrap toc

e.g.

WRAP = details
TITLE = <summary>Table of Contents</summary>

<!-- 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>Table of Contents</summary>

- [TOC Test1](#toc-test1)
- [TOC Test2](#toc-test2)
  - [Test2-1](#test2-1)
  - [Test2-2](#test2-2)

</details>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Use library

  • @technote-space/filter-github-action
  • @technote-space/github-action-helper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.