Skip to content

Commit

Permalink
feat: add code blocks and explicit empty sections
Browse files Browse the repository at this point in the history
  • Loading branch information
matty-rose committed Oct 24, 2021
1 parent deed3c4 commit 4f2167d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 46 deletions.
4 changes: 4 additions & 0 deletions pkg/document/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ func (m *MarkdownDocument) WriteTable(columns []string, rows [][]string) (*Markd
func CreateMarkdownLink(title, url string) string {
return fmt.Sprintf("[%s](%s)", title, url)
}

func FormatCode(text string) string {
return fmt.Sprintf("`%s`", text)
}
105 changes: 67 additions & 38 deletions pkg/generator/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,85 @@ func (mdg markdownGenerator) Generate(action *types.CompositeAction) string {
doc.WriteText(action.Description)
doc.WriteNewLine()

if len(action.Inputs) != 0 {
var inputs [][]string
for _, inp := range action.Inputs {
inputs = append(inputs, []string{inp.Name, inp.Description, strconv.FormatBool(inp.Required), inp.Default})
}
doc.WriteNewLine()
doc.WriteHeading("Inputs", 2)

if len(action.Inputs) != 0 {
mdg.generateInputTable(action, doc)
} else {
doc.WriteText("No inputs.")
doc.WriteNewLine()
doc.WriteHeading("Inputs", 2)
_, _ = doc.WriteTable(
[]string{"Name", "Description", "Required", "Default"},
inputs,
)
}

doc.WriteNewLine()
doc.WriteHeading("Outputs", 2)

if len(action.Outputs) != 0 {
var outputs [][]string
for _, out := range action.Outputs {
outputs = append(outputs, []string{out.Name, out.Description, out.Value})
}
mdg.generateOutputTable(action, doc)
} else {
doc.WriteText("No outputs.")
doc.WriteNewLine()
}

doc.WriteNewLine()
doc.WriteHeading("External Actions", 2)

if len(action.Uses) != 0 {
mdg.generateExternalActionTable(action, doc)
} else {
doc.WriteText("No external actions.")
doc.WriteNewLine()
doc.WriteHeading("Outputs", 2)
_, _ = doc.WriteTable(
[]string{"Name", "Description", "Value"},
outputs,
}

return doc.Render()
}

func (mdg markdownGenerator) generateInputTable(act *types.CompositeAction, doc *document.MarkdownDocument) {
columns := []string{"Name", "Description", "Required", "Default"}

var rows [][]string
for _, inp := range act.Inputs {
rows = append(
rows,
[]string{
inp.Name,
inp.Description,
strconv.FormatBool(inp.Required),
document.FormatCode(inp.Default),
},
)
}

if len(action.Uses) != 0 {
var externalActions [][]string
for _, act := range action.Uses {
externalActions = append(
externalActions,
[]string{
document.CreateMarkdownLink(act.Name, act.GetLink()),
act.Creator,
act.Version,
act.StepName,
act.StepID,
},
)
}
_, _ = doc.WriteTable(columns, rows)
}

doc.WriteNewLine()
doc.WriteHeading("External Actions", 2)
_, _ = doc.WriteTable(
[]string{"Name", "Creator", "Version", "Step Name", "Step ID"},
externalActions,
func (mdg markdownGenerator) generateOutputTable(act *types.CompositeAction, doc *document.MarkdownDocument) {
columns := []string{"Name", "Description", "Value"}

var rows [][]string
for _, out := range act.Outputs {
rows = append(rows, []string{out.Name, out.Description, document.FormatCode(out.Value)})
}

_, _ = doc.WriteTable(columns, rows)
}

func (mdg markdownGenerator) generateExternalActionTable(act *types.CompositeAction, doc *document.MarkdownDocument) {
columns := []string{"Name", "Creator", "Version", "Step Name", "Step ID"}

var rows [][]string
for _, act := range act.Uses {
rows = append(
rows,
[]string{
document.CreateMarkdownLink(act.Name, act.GetLink()),
act.Creator,
act.Version,
act.StepName,
act.StepID,
},
)
}

return doc.Render()
_, _ = doc.WriteTable(columns, rows)
}
46 changes: 38 additions & 8 deletions pkg/generator/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ func TestGenerateMarkdownFull(t *testing.T) {
func getMarkdownNameDesc() string {
return `# test
also test
## Inputs
No inputs.
## Outputs
No outputs.
## External Actions
No external actions.
`
}

Expand All @@ -193,27 +202,45 @@ also test
## Inputs
| Name | Description | Required | Default |
| --- | --- | --- | --- |
| a | a | false | a |
| b | b | true | |
| a | a | false | ` + "`a`" + ` |
| b | b | true | ` + "``" + ` |
## Outputs
No outputs.
## External Actions
No external actions.
`
}

func getMarkdownOutputs() string {
return `# test
also test
## Inputs
No inputs.
## Outputs
| Name | Description | Value |
| --- | --- | --- |
| a | a | a |
| b | b | b |
| a | a | ` + "`a`" + ` |
| b | b | ` + "`b`" + ` |
## External Actions
No external actions.
`
}

func getMarkdownExternal() string {
return `# test
also test
## Inputs
No inputs.
## Outputs
No outputs.
## External Actions
| Name | Creator | Version | Step Name | Step ID |
| --- | --- | --- | --- | --- |
Expand All @@ -229,13 +256,16 @@ also test
## Inputs
| Name | Description | Required | Default |
| --- | --- | --- | --- |
| a | a | false | a |
| b | b | true | |
| a | a | false | ` + "`a`" + ` |
| b | b | true | ` + "``" + ` |
## Outputs
| Name | Description | Value |
| --- | --- | --- |
| a | a | a |
| b | b | b |
| a | a | ` + "`a`" + ` |
| b | b | ` + "`b`" + ` |
## External Actions
No external actions.
`
}
26 changes: 26 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Bump Version in Package.json & Release
Increments the version following semver conventions, updates the version in package.json and creates a release with a generated changelog.

## Inputs
| Name | Description | Required | Default |
| --- | --- | --- | --- |
| git-chglog-version | git-chglog version to install. Defaults to latest. | false | `latest` |
| go-version | Go version to install. Defaults to ^1.17. | false | `^1.17` |
| tag-prefix | Prefix to add to the created tag. | true | `` |
| project-name | The project scope this change relates to | true | `` |
| project-path | The directory to the package.json to update | false | `.` |
| changelog-config | Path to the configuration file for git-chglog. | false | `.chglog/releaselog-config.yaml` |

## Outputs
| Name | Description | Value |
| --- | --- | --- |
| new-tag | New tag created for the release. | `${{ steps.bump-version.outputs.new_tag }}` |

## External Actions
| Name | Creator | Version | Step Name | Step ID |
| --- | --- | --- | --- | --- |
| [setup-go](https://github.com/actions/setup-go/tree/v2) | actions | v2 | Set up go | |
| [cache](https://github.com/actions/cache/tree/v2) | actions | v2 | Set up Go cache | |
| [github-tag-action](https://github.com/mathieudutour/github-tag-action/tree/v5.6) | mathieudutour | v5.6 | Bump version | bump-version |
| [git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action/tree/v4) | stefanzweifel | v4 | Commit version | auto-commit-action |
| [release-action](https://github.com/ncipollo/release-action/tree/v1) | ncipollo | v1 | Create release | |

0 comments on commit 4f2167d

Please sign in to comment.