Skip to content

Commit

Permalink
Generate config documentation from application.properties
Browse files Browse the repository at this point in the history
Leverages the `GenerateConfigDocs` JBang script (https://github.com/DependencyTrack/jbang-catalog/blob/main/GenerateConfigDocs.java) to generate reference documentation from the `application.properties` file.

This makes `application.properties` the single source of truth for configuration options. We no longer need to copy-paste its contents to multiple places for documentation purposes.

The documentation is re-generated automatically whenever `application.properties` changes.

This is already done for the Hyades project (https://github.com/DependencyTrack/hyades/blob/2f95363fbf51423876a8eb2c7f0bc55a53ba85f9/DEVELOPING.md?plain=1#L11-L61) and turned out to be useful, so backporting it here.

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed May 28, 2024
1 parent 1f2cc28 commit f9f8c8f
Show file tree
Hide file tree
Showing 6 changed files with 3,039 additions and 628 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/update-config-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file is part of Dependency-Track.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.
name: Update Config Documentation

on:
push:
branches:
- master
paths:
- ".github/workflows/update-config-docs.yml"
- "dev/scripts/config-docs.md.peb"
- "src/main/resources/application.properties"
workflow_dispatch: { }

permissions: { }

jobs:
generate-docs:
name: Generate Documentation
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
pull-requests: write
if: "${{ github.repository_owner == 'DependencyTrack' }}"
steps:
- name: Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # tag=v4.1.6
- name: Generate Documentation
uses: jbangdev/jbang-action@74844c9631cf1f35650427323e9bb3ffa41dfbd9 # tag=v0.115.0
with:
trust: https://github.com/DependencyTrack/jbang-catalog
script: gen-config-docs@DependencyTrack
scriptargs: >-
--template ./dev/scripts/config-docs.md.peb
--output docs/_docs/getting-started/configuration-apiserver.md
./src/main/resources/application.properties
- name: Create Pull Request
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # tag=v6.0.5
with:
add-paths: "docs/_docs/getting-started/configuration-apiserver.md"
branch: update-config-docs
body: "Updates configuration documentation."
commit-message: Update config docs
delete-branch: true
labels: documentation
signoff: true
title: Update config docs
57 changes: 57 additions & 0 deletions dev/scripts/config-docs.md.peb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: Configuration - API Server
category: Getting Started
chapter: 1
order: 6
---
<!--
GENERATED. DO NOT EDIT.

Generated with: {{ generateCommand }}
-->
{% for entry in propertiesByCategory %}
### {{ entry.key }}

{% for property in entry.value -%}
#### {{ property.name }}

{{ property.description }}

<table>
<tbody style="border: 0">
<tr>
<th style="text-align: right">Required</th>
<td style="border-width: 0">{{ property.required ? "Yes" : "No" }}</td>
</tr>
<tr>
<th style="text-align: right">Type</th>
<td style="border-width: 0">{{ property.type }}</td>
</tr>
{% if property.validValues -%}
<tr>
<th style="text-align: right">Valid Values</th>
<td style="border-width: 0">{{ property.validValues }}</td>
</tr>
{% endif -%}
<tr>
<th style="text-align: right">Default</th>
<td style="border-width: 0">{{ property.defaultValue }}</td>
</tr>
{% if property.example -%}
<tr>
<th style="text-align: right">Example</th>
<td style="border-width: 0">{{ property.example }}</td>
</tr>
{% endif -%}
<tr>
<th style="text-align: right">ENV</th>
<td style="border-width: 0">{{ property.env }}</td>
</tr>
</tbody>
</table>

{% if not loop.last %}
---
{% endif %}
{% endfor %}
{% endfor %}
Loading

0 comments on commit f9f8c8f

Please sign in to comment.