Skip to content

Commit 6e87e07

Browse files
author
Mike Weeks
committed
Adding Description heading for Actions
1 parent 596be03 commit 6e87e07

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ GitHub Action that generates beautiful, easy-to-read markdown tables with just a
4747

4848
## Usage
4949

50-
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.
50+
Add the `Inputs` and/or `Outputs`
51+
and/or `Secrets` (only supported by reusable workflows)
52+
and/or `Description` (only supported by actions)
53+
[`H2` header](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#headers) to any markdown file.
5154

5255
```yaml
5356
...
@@ -61,21 +64,21 @@ Add the `Inputs` and/or `Outputs` and/or `Secrets` (only supported by reusable w
6164
6265
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
6366
64-
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
65-
|-------------------------|--------|----------|----------------|--------------------------------------------------------------------------------------------------|
66-
| bin\_path | string | false | | Path to the auto-doc binary |
67-
| col\_max\_width | string | false | `"1000"` | Max width of a column |
68-
| col\_max\_words | string | false | `"5"` | Max number of words per line <br>in a column |
69-
| filename | string | false | `"action.yml"` | Path to the yaml file |
70-
| input\_columns | string | false | | List of action.yml **input** columns names <br>to display, default (display all columns) |
71-
| markdown\_links | string | false | `"true"` | Boolean indicating whether to output input, <br>output and secret names as markdown <br>links |
72-
| output | string | false | `"README.md"` | Path to the output file |
73-
| output\_columns | string | false | | List of action.yml **output** column names <br>to display, default (display all columns) |
74-
| reusable | string | false | | Boolean Indicating whether the file is <br>a reusable workflow |
75-
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column <br>names to display, default (display all columns) |
76-
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column <br>names to display, default (display all columns) |
77-
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column <br>names to display, default (display all columns) |
78-
| version | string | false | | The version number to run |
67+
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
68+
|---------------------------|--------|----------|----------------|-------------------------------------------------------------------------------------------------|
69+
| bin\_path | string | false | | Path to the auto-doc binary |
70+
| col\_max\_width | string | false | `"1000"` | Max width of a column |
71+
| col\_max\_words | string | false | `"5"` | Max number of words per line <br>in a column |
72+
| filename | string | false | `"action.yml"` | Path to the yaml file |
73+
| input\_columns | string | false | | List of action.yml **input** columns names <br>to display, default (display all columns) |
74+
| markdown\_links | string | false | `"true"` | Boolean indicating whether to output input, <br>output and secret names as markdown <br>links |
75+
| output | string | false | `"README.md"` | Path to the output file |
76+
| output\_columns | string | false | | List of action.yml **output** column names <br>to display, default (display all columns) |
77+
| reusable | string | false | | Boolean Indicating whether the file is <br>a reusable workflow |
78+
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column <br>names to display, default (display all columns) |
79+
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column <br>names to display, default (display all columns) |
80+
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column <br>names to display, default (display all columns) |
81+
| version | string | false | | The version number to run |
7982
8083
<!-- AUTO-DOC-INPUT:END -->
8184

internal/constants.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ const PipeSeparator = "|"
4242
// NewLineSeparator used for splitting lines
4343
const NewLineSeparator = "\n"
4444

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

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

5151
// InputAutoDocStart is the start of the input

internal/types/action.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Action struct {
5757
OutputColumns []string
5858
Inputs map[string]ActionInput `yaml:"inputs,omitempty"`
5959
Outputs map[string]ActionOutput `yaml:"outputs,omitempty"`
60-
Description string `yaml:"description,omitempty"`
60+
Description string `yaml:"description,omitempty"`
6161
InputMarkdownLinks bool
6262
}
6363

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

8383
var output []byte
8484

85-
hasDescriptionData, indices := utils.HasBytesInBetween(
85+
hasDescriptionData, indices := utils.HasBytesInBetween(
8686
input,
8787
[]byte(internal.DescriptionAutoDocStart),
8888
[]byte(internal.DescriptionAutoDocEnd),
8989
)
90-
output = input
90+
output = input
9191

92-
descriptionStr := strings.TrimSpace(description.String())
92+
descriptionStr := strings.TrimSpace(description.String())
9393

94-
95-
if hasDescriptionData {
94+
if hasDescriptionData {
9695
output = utils.ReplaceBytesInBetween(output, indices, []byte(descriptionStr))
9796
} else {
9897
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.DescriptionHeader))
9998
output = re.ReplaceAllFunc(input, func(match []byte) []byte {
10099
if bytes.HasPrefix(match, []byte(internal.DescriptionHeader)) {
101100
if descriptionStr != "" {
102101
return []byte(fmt.Sprintf("%s\n\n%v", internal.DescriptionHeader, descriptionStr))
103-
} else {
104-
return []byte(internal.DescriptionHeader)
105102
}
103+
return []byte(internal.DescriptionHeader)
106104
}
107105
return match
108106
})
@@ -114,11 +112,10 @@ func (a *Action) WriteDocumentation(inputTable, outputTable, description *string
114112
[]byte(internal.InputAutoDocEnd),
115113
)
116114

117-
118115
inputsStr := strings.TrimSpace(inputTable.String())
119116

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

179-
descriptionOutput, err := renderDescription(a.Description)
180-
if err != nil {
176+
descriptionOutput, err := renderDescription(a.Description)
177+
if err != nil {
181178
return err
182179
}
183180

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

202199
// renderDescription
203200
func renderDescription(description string) (*strings.Builder, error) {
204-
descriptionOutput := &strings.Builder{}
205-
_, err := fmt.Fprintln(descriptionOutput, internal.DescriptionAutoDocStart)
201+
descriptionOutput := &strings.Builder{}
202+
_, err := fmt.Fprintln(descriptionOutput, internal.DescriptionAutoDocStart)
206203
if err != nil {
207204
return descriptionOutput, err
208205
}
209206

210207
_, err = fmt.Fprintln(descriptionOutput)
211-
if err != nil {
212-
return descriptionOutput, err
213-
}
214-
descriptionOutput.WriteString(description)
215-
descriptionOutput.WriteString("\n")
216-
217-
_, err = fmt.Fprint(descriptionOutput, internal.DescriptionAutoDocEnd)
218-
if err != nil {
219-
return descriptionOutput, err
220-
}
221-
return descriptionOutput, nil
208+
if err != nil {
209+
return descriptionOutput, err
210+
}
211+
descriptionOutput.WriteString(description)
212+
descriptionOutput.WriteString("\n")
213+
214+
_, err = fmt.Fprint(descriptionOutput, internal.DescriptionAutoDocEnd)
215+
if err != nil {
216+
return descriptionOutput, err
217+
}
218+
return descriptionOutput, nil
222219
}
223220

224221
// renderActionOutputTableOutput renders the action input table

0 commit comments

Comments
 (0)