Skip to content

Commit

Permalink
Adding Description heading for Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mw-root committed Sep 18, 2023
1 parent bc1a0a7 commit 1169b3a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ GitHub Action that generates beautiful, easy-to-read markdown tables with just a

## Usage

Add the `Inputs` and/or `Outputs` and/or `Secrets` (only supported by reusable workflows) and/or `Description` (only supported by actions) [`H2` header](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#headers) to any markdown file.
Add the `Inputs` and/or `Outputs`
and/or `Secrets` (only supported by reusable workflows)
and/or `Description` (only supported by actions)
[`H2` header](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#headers) to any markdown file.

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 109 Warning

Expected: 80; Actual: 109

```yaml
...
Expand All @@ -61,21 +64,21 @@ Add the `Inputs` and/or `Outputs` and/or `Secrets` (only supported by reusable w

<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->

| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-------------------------|--------|----------|----------------|--------------------------------------------------------------------------------------------------|
| bin\_path | string | false | | Path to the auto-doc binary |
| col\_max\_width | string | false | `"1000"` | Max width of a column |
| col\_max\_words | string | false | `"5"` | Max number of words per line <br>in a column |
| filename | string | false | `"action.yml"` | Path to the yaml file |
| input\_columns | string | false | | List of action.yml **input** columns names <br>to display, default (display all columns) |
| markdown\_links | string | false | `"true"` | Boolean indicating whether to output input, <br>output and secret names as markdown <br>links |
| output | string | false | `"README.md"` | Path to the output file |
| output\_columns | string | false | | List of action.yml **output** column names <br>to display, default (display all columns) |
| reusable | string | false | | Boolean Indicating whether the file is <br>a reusable workflow |
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column <br>names to display, default (display all columns) |
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column <br>names to display, default (display all columns) |
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column <br>names to display, default (display all columns) |
| version | string | false | | The version number to run |
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
|---------------------------|--------|----------|----------------|-------------------------------------------------------------------------------------------------|
| bin\_path | string | false | | Path to the auto-doc binary |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| col\_max\_width | string | false | `"1000"` | Max width of a column |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| col\_max\_words | string | false | `"5"` | Max number of words per line <br>in a column |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br
| filename | string | false | `"action.yml"` | Path to the yaml file |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| input\_columns | string | false | | List of action.yml **input** columns names <br>to display, default (display all columns) |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br
| markdown\_links | string | false | `"true"` | Boolean indicating whether to output input, <br>output and secret names as markdown <br>links |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| output | string | false | `"README.md"` | Path to the output file |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| output\_columns | string | false | | List of action.yml **output** column names <br>to display, default (display all columns) |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| reusable | string | false | | Boolean Indicating whether the file is <br>a reusable workflow |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column <br>names to display, default (display all columns) |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column <br>names to display, default (display all columns) |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column <br>names to display, default (display all columns) |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

Check warning

Code scanning / Markdownlint (reported by Codacy)

Element: br Warning

Element: br
| version | string | false | | The version number to run |

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 164 Warning

Expected: 80; Actual: 164

<!-- AUTO-DOC-INPUT:END -->

Expand Down
4 changes: 2 additions & 2 deletions internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const PipeSeparator = "|"
// NewLineSeparator used for splitting lines
const NewLineSeparator = "\n"

// InputAutoDocStart is the start of the input
// DescriptionAutoDocStart is the start of the description
var DescriptionAutoDocStart = fmt.Sprintf(AutoDocStart, "DESCRIPTION")

// InputAutoDocEnd is the end of the input
// DescriptionAutoDocEnd is the end of the description
var DescriptionAutoDocEnd = fmt.Sprintf(AutoDocEnd, "DESCRIPTION")

// InputAutoDocStart is the start of the input
Expand Down
47 changes: 22 additions & 25 deletions internal/types/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Action struct {
OutputColumns []string
Inputs map[string]ActionInput `yaml:"inputs,omitempty"`
Outputs map[string]ActionOutput `yaml:"outputs,omitempty"`
Description string `yaml:"description,omitempty"`
Description string `yaml:"description,omitempty"`
InputMarkdownLinks bool
}

Expand All @@ -82,27 +82,25 @@ func (a *Action) WriteDocumentation(inputTable, outputTable, description *string

var output []byte

hasDescriptionData, indices := utils.HasBytesInBetween(
hasDescriptionData, indices := utils.HasBytesInBetween(
input,
[]byte(internal.DescriptionAutoDocStart),
[]byte(internal.DescriptionAutoDocEnd),
)
output = input
output = input

descriptionStr := strings.TrimSpace(description.String())
descriptionStr := strings.TrimSpace(description.String())


if hasDescriptionData {
if hasDescriptionData {
output = utils.ReplaceBytesInBetween(output, indices, []byte(descriptionStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.DescriptionHeader))
output = re.ReplaceAllFunc(input, func(match []byte) []byte {
if bytes.HasPrefix(match, []byte(internal.DescriptionHeader)) {
if descriptionStr != "" {
return []byte(fmt.Sprintf("%s\n\n%v", internal.DescriptionHeader, descriptionStr))
} else {
return []byte(internal.DescriptionHeader)
}
return []byte(internal.DescriptionHeader)
}
return match
})
Expand All @@ -114,11 +112,10 @@ func (a *Action) WriteDocumentation(inputTable, outputTable, description *string
[]byte(internal.InputAutoDocEnd),
)


inputsStr := strings.TrimSpace(inputTable.String())

if hasInputsData {
output = utils.ReplaceBytesInBetween(output, indices, []byte(inputsStr))
output = utils.ReplaceBytesInBetween(output, indices, []byte(inputsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.InputsHeader))
output = re.ReplaceAllFunc(input, func(match []byte) []byte {
Expand Down Expand Up @@ -176,8 +173,8 @@ func (a *Action) RenderOutput() error {
return err
}

descriptionOutput, err := renderDescription(a.Description)
if err != nil {
descriptionOutput, err := renderDescription(a.Description)
if err != nil {
return err
}

Expand All @@ -201,24 +198,24 @@ func (a *Action) RenderOutput() error {

// renderDescription
func renderDescription(description string) (*strings.Builder, error) {
descriptionOutput := &strings.Builder{}
_, err := fmt.Fprintln(descriptionOutput, internal.DescriptionAutoDocStart)
descriptionOutput := &strings.Builder{}
_, err := fmt.Fprintln(descriptionOutput, internal.DescriptionAutoDocStart)
if err != nil {
return descriptionOutput, err
}

_, err = fmt.Fprintln(descriptionOutput)
if err != nil {
return descriptionOutput, err
}
descriptionOutput.WriteString(description)
descriptionOutput.WriteString("\n")

_, err = fmt.Fprint(descriptionOutput, internal.DescriptionAutoDocEnd)
if err != nil {
return descriptionOutput, err
}
return descriptionOutput, nil
if err != nil {
return descriptionOutput, err
}
descriptionOutput.WriteString(description)
descriptionOutput.WriteString("\n")

_, err = fmt.Fprint(descriptionOutput, internal.DescriptionAutoDocEnd)
if err != nil {
return descriptionOutput, err
}
return descriptionOutput, nil
}

// renderActionOutputTableOutput renders the action input table
Expand Down

0 comments on commit 1169b3a

Please sign in to comment.