Skip to content

GH Actions/publish-wiki: auto-generate table of contents #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 14, 2025

This commit adds steps to the workflow to auto-generate a GitHub wiki compatible table of contents in most wiki pages.

This reduces the risk of a TOC being out-of-date or containing incorrectly formatted links, as well as reduces the maintenance burden.

This action uses the doctoc pages to generate the table of contents and this can be tested locally using the same steps as used in the GH Actions workflow:

npm install -g doctoc
cp -v -a wiki _wiki
doctoc ./_wiki/ --github --maxlevel 4 --update-only
doctoc ./_wiki/Version-4.0-User-Upgrade-Guide.md --github --maxlevel 3 --update-only

Notes:

  • The files are copied to a _wiki directory - which is .gitignored - before pre-processing to reduce the risk of the source files being accidentally updated (and committed), which would undo the automation.
  • The --github flag puts the TOC generation in GitHub compatible mode.
  • The --update-only flag means that only markdown files containing the <!-- START doctoc --> and <!-- END doctoc --> markers will be updated and files without those markers will be left alone.
  • By default, the TOC will contain all headers up to the indicated --maxlevel. For the V 4.0 Dev upgrade guide, this looked weird, what with some "Upgrading" headers being at level 4 and some at level 5. To mitigate this, a couple of headers have been turned into "bold phrases" instead. Along the same lines, for the V 4.0 User upgrade guide, the level 4 headers were always "Upgrading". Those belong with their parent heading and IMO do not need to be separately called out in the TOC, which explains the second call to doctoc to overrule the TOC for that file specifically with a --maxlevel 3 setting.
  • The start/end markers have been added to all files which contained a TOC, except for one: Reporting.md. The reason for this exception is that the section order in the file does not match the current TOC order, with the existing TOC order making sense from a TOC point of view, while the section order makes sense from a "types of reports most used" point of view. Whether this page should be re-organized or not, is outside the scope of this PR.

To allow contributors to review the resulting pre-processed wiki files, the files are uploaded as an artifact when a PR dry-run is being executed and a comment is posted on the PR requesting the contributor to review the pre-processed files.

Includes adding a TOC to the Coding Standards Tutorial page and adding "back to top" links within the page.

Ref:

This commit adds steps to the workflow to auto-generate a GitHub wiki compatible table of contents in most wiki pages.

This reduces the risk of a TOC being out-of-date or containing incorrectly formatted links, as well as reduces the maintenance burden.

This action uses the `doctoc` pages to generate the table of contents and this can be tested locally using the same steps as used in the GH Actions workflow:
```
npm install -g doctoc
cp -v -a wiki _wiki
doctoc ./_wiki/ --github --maxlevel 4 --update-only
doctoc ./_wiki/Version-4.0-User-Upgrade-Guide.md --github --maxlevel 3 --update-only
```

Notes:
* The files are copied to a `_wiki` directory - which is `.gitignore`d - before pre-processing to reduce the risk of the source files being accidentally updated (and committed), which would undo the automation.
* The `--github` flag puts the TOC generation in GitHub compatible mode.
* The `--update-only` flag means that only markdown files containing the `<!-- START doctoc -->` and `<!-- END doctoc -->` markers will be updated and files without those markers will be left alone.
* By default, the TOC will contain all headers up to the indicated `--maxlevel`.
    For the V 4.0 Dev upgrade guide, this looked weird, what with some "Upgrading" headers being at level 4 and some at level 5.
    To mitigate this, a couple of headers have been turned into "bold phrases" instead.
    Along the same lines, for the V 4.0 User upgrade guide, the level 4 headers were always "Upgrading". Those belong with their parent heading and IMO do not need to be separately called out in the TOC, which explains the second call to `doctoc` to overrule the TOC for that file specifically with a `--maxlevel 3` setting.
* The start/end markers have been added to all files which contained a TOC, except for one: `Reporting.md`.
    The reason for this exception is that the section order in the file does not match the current TOC order, with the existing TOC order making sense from a TOC point of view, while the section order makes sense from a "types of reports most used" point of view.
    Whether this page should be re-organized or not, is outside the scope of this PR.

To allow contributors to review the resulting pre-processed wiki files, the files are uploaded as an artifact when a PR dry-run is being executed and a comment is posted on the PR requesting the contributor to review the pre-processed files.

Includes adding a TOC to the Coding Standards Tutorial page and adding "back to top" links within the page.

Ref:
* https://github.com/thlorenz/doctoc
@jrfnl
Copy link
Member Author

jrfnl commented Jul 14, 2025

Thank you for your PR.
A dry-run has been executed on your PR, executing all markdown pre-processing for the wiki files.

Please review the resulting final markdown files via the created artifact.
This is especially important when adding new pages.

N.B.: the above link will automatically be updated when this PR is updated.

@jrfnl
Copy link
Member Author

jrfnl commented Jul 14, 2025

Hmm... looks like the PR comment is posted with me as commenter because the secrets.COMMENT_ON_PRS_TOKEN Personal Access Token being used to allow for commenting on PRs was created from my account. Not sure I really like that, but also not sure how I could change it.

@jrfnl
Copy link
Member Author

jrfnl commented Jul 14, 2025

Switching to use ${{ secrets.GITHUB_TOKEN }} for the repo_token would switch the account to Github[bot], however, that may prevent the adding of comments to PRs coming from forks (when the comment would be all the more relevant).

Maybe let's start with ${{ secrets.GITHUB_TOKEN }} and then once this is merged, either @rodrigoprimo or @fredden could submit a PR from a fork to see if the comment shows up ?

@jrfnl jrfnl merged commit 80b84f3 into main Jul 15, 2025
2 checks passed
@jrfnl jrfnl deleted the feature/ghactions-automate-toc-creation branch July 15, 2025 10:55
@jrfnl jrfnl mentioned this pull request Jul 17, 2025
6 tasks
jrfnl added a commit that referenced this pull request Jul 17, 2025
In the original PR (#6), a Personal Access Token (PAT) was used, but that resulted in the comment being left as if coming from my account, which is misleading, which is why the `repo_token` was initially switched back to `secrets.GITHUB_TOKEN`, with a reminder that a test would need to be done with a PR coming from a fork to verify that the auto-comment would still work.

As the first PR from a fork has now come in (#38), it has become clear that the auto-comment does not work with the default GitHub token, so this commit switches the `repo_token` back to the Personal Access Token and updates the message to make it clear I did not leave the comment.

We'll still have to test (again) whether using the PAT works for PRs coming from forks. If not, we'll have to revisit this workflow step.
jrfnl added a commit that referenced this pull request Jul 17, 2025
In the original PR (#6), a Personal Access Token (PAT) was used, but that resulted in the comment being left as if coming from my account, which is misleading, which is why the `repo_token` was initially switched back to `secrets.GITHUB_TOKEN`, with a reminder that a test would need to be done with a PR coming from a fork to verify that the auto-comment would still work.

As the first PR from a fork has now come in (#38), it has become clear that the auto-comment does not work with the default GitHub token, so this commit switches the `repo_token` back to the Personal Access Token and updates the message to make it clear I did not leave the comment.

We'll still have to test (again) whether using the PAT works for PRs coming from forks. If not, we'll have to revisit this workflow step.
jrfnl added a commit that referenced this pull request Jul 17, 2025
In the original PR (#6), a Personal Access Token (PAT) was used, but that resulted in the comment being left as if coming from my account, which is misleading, which is why the `repo_token` was initially switched back to `secrets.GITHUB_TOKEN`, with a reminder that a test would need to be done with a PR coming from a fork to verify that the auto-comment would still work.

As the first PR from a fork has now come in (#38), it has become clear that the auto-comment does not work with the default GitHub token, so this commit switches the `repo_token` back to the Personal Access Token and updates the message to make it clear I did not leave the comment.

We'll still have to test (again) whether using the PAT works for PRs coming from forks. If not, we'll have to revisit this workflow step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant