Skip to content

Commit

Permalink
feat: add external action generation
Browse files Browse the repository at this point in the history
matty-rose committed Oct 24, 2021
1 parent e75ab78 commit 12040aa
Showing 2 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/generator/markdown.go
Original file line number Diff line number Diff line change
@@ -65,5 +65,19 @@ func (mdg markdownGenerator) Generate(action *types.CompositeAction) string {
)
}

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

doc.WriteNewLine()
doc.WriteHeading("External Actions", 2)
_, _ = doc.WriteTable(
[]string{"Name", "Creator", "Version", "Step Name", "Step ID"},
externalActions,
)
}

return doc.Render()
}
43 changes: 43 additions & 0 deletions pkg/generator/markdown_test.go
Original file line number Diff line number Diff line change
@@ -106,6 +106,37 @@ func TestGenerateMarkdownOutputs(t *testing.T) {
assert.Equal(t, expected, content)
}

func TestGenerateMarkdownExternal(t *testing.T) {
g, err := generator.New("markdown")
if err != nil {
t.Fatal(err)
}

action := types.CompositeAction{
Name: "test",
Description: "also test",
Uses: []types.ExternalAction{
{
Creator: "actions",
Name: "cache",
Version: "v2.1.6",
},
{
Creator: "actions",
Name: "setup-python",
Version: "v2",
StepName: "Set up python",
},
},
}

expected := getMarkdownExternal()

content := g.Generate(&action)

assert.Equal(t, expected, content)
}

func TestGenerateMarkdownFull(t *testing.T) {
g, err := generator.New("markdown")
if err != nil {
@@ -179,6 +210,18 @@ also test
`
}

func getMarkdownExternal() string {
return `# test
also test
## External Actions
| Name | Creator | Version | Step Name | Step ID |
| --- | --- | --- | --- | --- |
| cache | actions | v2.1.6 | | |
| setup-python | actions | v2 | Set up python | |
`
}

func getMarkdownFull() string {
return `# test
also test

0 comments on commit 12040aa

Please sign in to comment.