peschmae / glab-component-generator

Golang tool CLI tool to generate README.md from Gitlab Components
MIT License
2 stars 1 forks source link

Small Golang CLI to generate README for Gitlab CI components

Very small CLI based on spf13/cobra to generate README.md from existing GitLab components.

The genreated README.md can be expanded using a header and footer file. By default those are HEADER.md and FOOTER.md in the project directory.

The same goes for each component, if the component is in it's own directory within templates/. For components that only consist of a file (eg. templates/component-name.yaml), no header or footer files will be used.

Supported inputs

The following fields on each input are supported

Example

The following spec in a component

spec:
  inputs:
    job-prefix:     # Mandatory string input
      description: |
        Define a prefix for the job name.
        Now with line break support
    job-stage:      # Optional string input with a default value when not provided
      default: test
    environment:    # Mandatory input that must match one of the options
      options: ['test', 'staging', 'production']
    concurrency:
      type: number  # Optional numeric input with a default value when not provided
      default: 1
    version:        # Mandatory string input that must match the regular expression
      type: string
      regex: /^v\d\.\d+(\.\d+)$/
    export_results: # Optional boolean input with a default value when not provided
      type: boolean
      default: true

Will result in the following markdown

| Input / Variable | Description | Default value | Type    | Options | Regex |
| ---------------- | ----------- | ------------- | ------- | ------- | ----- |
| `concurrency`    |             | _1_           | number  | __ | `` |
| `environment`    |             | __            |         | _test, staging, production_ | `` |
| `export_results` |             | _true_        | boolean | __ | `` |
| `job-prefix`     | Define a prefix for the job name.<br>Now with line break support | __            |         | __ | `` |
| `job-stage`      |             | _test_        |         | __ | `` |
| `version`        |             | __            | string  | __ | `/^v\d\.\d+(\.\d+)$/` |

Generated table

Input / Variable Description Default value Type Options Regex
concurrency 1 number __ ``
environment __ test, staging, production ``
export_results true boolean __ ``
job-prefix Define a prefix for the job name
Now with line break support
__ __ ``
job-stage test __ ``
version __ string __ /^v\d\.\d+(\.\d+)$/

.pre-commit hook

The generator can also be used as a .pre-commit-hook to verify that the README.md was updated on each commit.

repos:
  - repo: https://github.com/peschmae/glab-component-generator
    rev: 0.7.0
    hooks:
      - id: glab-component-readme
        args:
          - --header=docs/HEADER.md
          - --footer=docs/FOOTER.md