Skip to content

Commit 10fb3a0

Browse files
committed
Add template workflow to check for missed updates to Markdown ToC
On every push or pull request that affects the Markdown files of the repository which have generated table of contents, check whether the table of contents matches the content.
1 parent 27e0b6a commit 10fb3a0

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
tasks:
5+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-toc-task/Taskfile.yml
6+
markdown:toc:
7+
desc: Update the table of contents
8+
cmds:
9+
- |
10+
npx markdown-toc \
11+
--bullets=- \
12+
--maxdepth={{.MAX_DEPTH}} \
13+
-i \
14+
"{{.FILE_PATH}}"

workflow-templates/check-toc-task.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# "Check ToC" workflow (Task)
2+
3+
Workflow file: [check-toc-task.yml](check-toc-task.yml)
4+
5+
Check whether the generated table of contents in Markdown files matches their heading structure.
6+
7+
This should be used in repositories that generate the table of contents with [markdown-toc](https://github.com/jonschlinkert/markdown-toc).
8+
9+
This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.
10+
11+
## Assets
12+
13+
- [`Taskfile.yml`](assets/check-toc-task/Taskfile.yml] - Formatting task.
14+
- Install to: repository root (or add the `markdown:toc` task into the existing `Taskfile.yml`)
15+
16+
## Readme badge
17+
18+
Markdown badge:
19+
20+
```markdown
21+
[![Check ToC status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-toc-task.yml)
22+
```
23+
24+
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
25+
26+
---
27+
28+
Asciidoc badge:
29+
30+
```adoc
31+
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-toc-task.yml/badge.svg["Check ToC status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-toc-task.yml"]
32+
```
33+
34+
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
35+
36+
## Commit message
37+
38+
```
39+
Add CI workflow to check for missed updates to readme ToC
40+
41+
On every push or pull request that affects the repository's README.md, check whether the table of contents matches the
42+
content.
43+
```
44+
45+
## PR message
46+
47+
```markdown
48+
On every push or pull request that affects the repository's README.md, use [markdown-toc](https://github.com/jonschlinkert/markdown-toc) to check whether the table of contents matches the content.
49+
```

workflow-templates/check-toc-task.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Source: https://github.com/arduino/.github/blob/master/workflow-templates/check-toc-task.md
2+
name: Check ToC
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-toc-task.ya?ml"
9+
# TODO: Update this if ToC of any other files should be checked.
10+
- "README.md"
11+
pull_request:
12+
paths:
13+
- ".github/workflows/check-toc-task.ya?ml"
14+
# TODO: Update this if ToC of any other files should be checked.
15+
- "README.md"
16+
workflow_dispatch:
17+
repository_dispatch:
18+
19+
jobs:
20+
check:
21+
name: ${{ matrix.file.name }}
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
fail-fast: false
26+
27+
matrix:
28+
file:
29+
# TODO: Update this if any other files should be checked.
30+
- name: README.md
31+
# Max ToC depth, for use with the markdown-toc --maxdepth flag.
32+
maxdepth: 3
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
- name: Install Task
39+
uses: arduino/setup-task@v1
40+
with:
41+
repo-token: ${{ secrets.GITHUB_TOKEN }}
42+
version: 3.x
43+
44+
- name: Rebuild ToC
45+
run: |
46+
task markdown:toc \
47+
FILE_PATH="${{ github.workspace }}/${{ matrix.file.name }}" \
48+
MAX_DEPTH=${{ matrix.file.maxdepth }}
49+
50+
- name: Check ToC
51+
run: git diff --color --exit-code
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Source: https://github.com/arduino/.github/blob/master/workflow-templates/check-toc-task.md
2+
name: Check ToC
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-toc-task.ya?ml"
9+
# TODO: Update this if ToC of any other files should be checked.
10+
- "README.md"
11+
pull_request:
12+
paths:
13+
- ".github/workflows/check-toc-task.ya?ml"
14+
# TODO: Update this if ToC of any other files should be checked.
15+
- "README.md"
16+
workflow_dispatch:
17+
repository_dispatch:
18+
19+
jobs:
20+
check:
21+
name: ${{ matrix.file.name }}
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
fail-fast: false
26+
27+
matrix:
28+
file:
29+
# TODO: Update this if any other files should be checked.
30+
- name: README.md
31+
# Max ToC depth, for use with the markdown-toc --maxdepth flag.
32+
maxdepth: 3
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
- name: Install Task
39+
uses: arduino/setup-task@v1
40+
with:
41+
repo-token: ${{ secrets.GITHUB_TOKEN }}
42+
version: 3.x
43+
44+
- name: Rebuild ToC
45+
run: |
46+
task markdown:toc \
47+
FILE_PATH="${{ github.workspace }}/${{ matrix.file.name }}" \
48+
MAX_DEPTH=${{ matrix.file.maxdepth }}
49+
50+
- name: Check ToC
51+
run: git diff --color --exit-code

0 commit comments

Comments
 (0)