Skip to content

Commit 1c249bf

Browse files
authored
Merge pull request #120 from per1234/check-toc
Add infrastructure for maintaining the table of contents
2 parents a72d1b2 + ee9a057 commit 1c249bf

File tree

5 files changed

+1133
-0
lines changed

5 files changed

+1133
-0
lines changed

.github/workflows/check-toc-task.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-toc-task.md
2+
name: Check ToC
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-toc-task.ya?ml"
14+
- "package.json"
15+
- "package-lock.json"
16+
- "README.md"
17+
pull_request:
18+
paths:
19+
- ".github/workflows/check-toc-task.ya?ml"
20+
- "package.json"
21+
- "package-lock.json"
22+
- "README.md"
23+
schedule:
24+
# Run periodically to catch breakage caused by external changes.
25+
- cron: "0 3 * * WED"
26+
workflow_dispatch:
27+
repository_dispatch:
28+
29+
jobs:
30+
run-determination:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
result: ${{ steps.determination.outputs.result }}
34+
steps:
35+
- name: Determine if the rest of the workflow should run
36+
id: determination
37+
run: |
38+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
39+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
40+
if [[
41+
"${{ github.event_name }}" != "create" ||
42+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
43+
]]; then
44+
# Run the other jobs.
45+
RESULT="true"
46+
else
47+
# There is no need to run the other jobs.
48+
RESULT="false"
49+
fi
50+
51+
echo "result=$RESULT" >> $GITHUB_OUTPUT
52+
53+
check:
54+
name: ${{ matrix.file.name }}
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
57+
runs-on: ubuntu-latest
58+
59+
strategy:
60+
fail-fast: false
61+
62+
matrix:
63+
file:
64+
- name: README.md
65+
# Max ToC depth, for use with the markdown-toc --maxdepth flag.
66+
maxdepth: 5
67+
68+
steps:
69+
- name: Checkout repository
70+
uses: actions/checkout@v3
71+
72+
- name: Setup Node.js
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: ${{ env.NODE_VERSION }}
76+
77+
- name: Install Task
78+
uses: arduino/setup-task@v1
79+
with:
80+
repo-token: ${{ secrets.GITHUB_TOKEN }}
81+
version: 3.x
82+
83+
- name: Rebuild ToC
84+
run: |
85+
task markdown:toc \
86+
FILE_PATH="${{ github.workspace }}/${{ matrix.file.name }}" \
87+
MAX_DEPTH=${{ matrix.file.maxdepth }}
88+
89+
- name: Check ToC
90+
run: git diff --color --exit-code

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Check Prettier Formatting status](https://github.com/arduino/compile-sketches/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-prettier-formatting-task.yml)
1010
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
1111
[![Check Taskfiles status](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml)
12+
[![Check ToC status](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml)
1213
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
1314
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)
1415
[![Test Python status](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml)

Taskfile.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ tasks:
2525
- task: general:correct-spelling
2626
- task: general:format-prettier
2727
- task: markdown:fix
28+
- task: markdown:toc
29+
vars:
30+
FILE_PATH: README.md
31+
MAX_DEPTH: 5
2832
- task: python:format
2933

3034
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
@@ -266,6 +270,19 @@ tasks:
266270
cmds:
267271
- npx markdownlint-cli "**/*.md"
268272

273+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-toc-task/Taskfile.yml
274+
markdown:toc:
275+
desc: Update the table of contents
276+
deps:
277+
- task: npm:install-deps
278+
cmds:
279+
- |
280+
npx markdown-toc \
281+
--bullets=- \
282+
--maxdepth={{.MAX_DEPTH}} \
283+
-i \
284+
"{{.FILE_PATH}}"
285+
269286
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
270287
npm:install-deps:
271288
desc: Install dependencies managed by npm

0 commit comments

Comments
 (0)