Skip to content

Commit

Permalink
feat: add support for indicating deprecated inputs (#481)
Browse files Browse the repository at this point in the history
* feat: add support for indicating deprecated inputs

* Formatted code.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jackton1 and github-actions[bot] committed Jun 6, 2023
1 parent 7aae7c3 commit 1034c3e
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 181 deletions.
45 changes: 27 additions & 18 deletions internal/types/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ import (

// ActionInput represents the input of the action.yml
type ActionInput struct {
Description string `yaml:"description"`
Required bool `yaml:"required"`
Default string `yaml:"default,omitempty"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Default string `yaml:"default,omitempty"`
DeprecationMessage string `yaml:"deprecationMessage,omitempty"`
}

// ActionOutput represents the output of the action.yml
Expand Down Expand Up @@ -160,10 +161,10 @@ func (a *Action) RenderOutput() error {
}

// renderActionOutputTableOutput renders the action input table
func renderActionInputTableOutput(i map[string]ActionInput, inputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
func renderActionInputTableOutput(inputs map[string]ActionInput, inputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
inputTableOutput := &strings.Builder{}

if len(i) > 0 {
if len(inputs) > 0 {
_, err := fmt.Fprintln(inputTableOutput, internal.InputAutoDocStart)
if err != nil {
return inputTableOutput, err
Expand All @@ -175,8 +176,8 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns []strin
inputTable.SetCenterSeparator(internal.PipeSeparator)
inputTable.SetAlignment(tablewriter.ALIGN_CENTER)

keys := make([]string, 0, len(i))
for k := range i {
keys := make([]string, 0, len(inputs))
for k := range inputs {
keys = append(keys, k)
}
sort.Strings(keys)
Expand All @@ -189,18 +190,26 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns []strin
for _, col := range inputColumns {
switch col {
case "Input":
row = append(row, key)
if inputs[key].DeprecationMessage != "" {
row = append(row, fmt.Sprintf("~~%s~~ <br> **%s**", key, inputs[key].DeprecationMessage))
} else {
row = append(row, key)
}
case "Type":
row = append(row, "string")
case "Required":
row = append(row, strconv.FormatBool(i[key].Required))
row = append(row, strconv.FormatBool(inputs[key].Required))
case "Default":
row = append(row, utils.FormatValue(i[key].Default))
row = append(row, utils.FormatValue(inputs[key].Default))
case "Description":
row = append(row, utils.WordWrap(i[key].Description, maxWords))
if inputs[key].DeprecationMessage != "" {
row = append(row, utils.WordWrap(fmt.Sprintf("**Deprecated:** %s", inputs[key].Description), maxWords))
} else {
row = append(row, utils.WordWrap(inputs[key].Description, maxWords))
}
default:
return inputTableOutput, fmt.Errorf(
"unknown input column: '%s'. Please specify any of the following columns: %s",
"unknown inputs column: '%s'. Please specify any of the following columns: %s",
col,
strings.Join(internal.DefaultActionInputColumns, ", "),
)
Expand Down Expand Up @@ -230,10 +239,10 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns []strin
}

// renderActionOutputTableOutput renders the action output table
func renderActionOutputTableOutput(o map[string]ActionOutput, outputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
func renderActionOutputTableOutput(outputs map[string]ActionOutput, outputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
outputTableOutput := &strings.Builder{}

if len(o) > 0 {
if len(outputs) > 0 {
_, err := fmt.Fprintln(outputTableOutput, internal.OutputAutoDocStart)
if err != nil {
return outputTableOutput, err
Expand All @@ -245,8 +254,8 @@ func renderActionOutputTableOutput(o map[string]ActionOutput, outputColumns []st
outputTable.SetCenterSeparator(internal.PipeSeparator)
outputTable.SetAlignment(tablewriter.ALIGN_CENTER)

keys := make([]string, 0, len(o))
for k := range o {
keys := make([]string, 0, len(outputs))
for k := range outputs {
keys = append(keys, k)
}
sort.Strings(keys)
Expand All @@ -262,10 +271,10 @@ func renderActionOutputTableOutput(o map[string]ActionOutput, outputColumns []st
case "Type":
row = append(row, "string")
case "Description":
row = append(row, utils.WordWrap(o[key].Description, maxWords))
row = append(row, utils.WordWrap(outputs[key].Description, maxWords))
default:
return outputTableOutput, fmt.Errorf(
"unknown output column: '%s'. Please specify any of the following columns: %s",
"unknown outputs column: '%s'. Please specify any of the following columns: %s",
col,
strings.Join(internal.DefaultActionOutputColumns, ", "),
)
Expand Down
69 changes: 39 additions & 30 deletions internal/types/reusable.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import (

// ReusableInput represents the input of the reusable workflow
type ReusableInput struct {
Description string `yaml:"description"`
Required bool `yaml:"required"`
Default string `yaml:"default,omitempty"`
Type string `yaml:"type"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Default string `yaml:"default,omitempty"`
Type string `yaml:"type"`
DeprecationMessage string `yaml:"deprecationMessage,omitempty"`
}

// ReusableOutput represents the output of the reusable workflow
Expand Down Expand Up @@ -197,10 +198,10 @@ func (r *Reusable) RenderOutput() error {
}

// renderReusableInputTableOutput renders the reusable workflow input table
func renderReusableInputTableOutput(i map[string]ReusableInput, inputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
func renderReusableInputTableOutput(inputs map[string]ReusableInput, inputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
inputTableOutput := &strings.Builder{}

if len(i) > 0 {
if len(inputs) > 0 {
_, err := fmt.Fprintln(inputTableOutput, internal.InputAutoDocStart)
if err != nil {
return inputTableOutput, err
Expand All @@ -212,8 +213,8 @@ func renderReusableInputTableOutput(i map[string]ReusableInput, inputColumns []s
inputTable.SetCenterSeparator(internal.PipeSeparator)
inputTable.SetAlignment(tablewriter.ALIGN_CENTER)

keys := make([]string, 0, len(i))
for k := range i {
keys := make([]string, 0, len(inputs))
for k := range inputs {
keys = append(keys, k)
}
sort.Strings(keys)
Expand All @@ -226,23 +227,31 @@ func renderReusableInputTableOutput(i map[string]ReusableInput, inputColumns []s
for _, col := range inputColumns {
switch col {
case "Input":
row = append(row, key)
if inputs[key].DeprecationMessage != "" {
row = append(row, fmt.Sprintf("~~%s~~ <br> **%s**", key, inputs[key].DeprecationMessage))
} else {
row = append(row, key)
}
case "Type":
row = append(row, i[key].Type)
row = append(row, inputs[key].Type)
case "Required":
row = append(row, strconv.FormatBool(i[key].Required))
row = append(row, strconv.FormatBool(inputs[key].Required))
case "Default":
switch i[key].Type {
switch inputs[key].Type {
case "string":
row = append(row, utils.FormatValue(i[key].Default))
row = append(row, utils.FormatValue(inputs[key].Default))
default:
row = append(row, "`"+i[key].Default+"`")
row = append(row, "`"+inputs[key].Default+"`")
}
case "Description":
row = append(row, utils.WordWrap(i[key].Description, maxWords))
if inputs[key].DeprecationMessage != "" {
row = append(row, utils.WordWrap(fmt.Sprintf("**Deprecated:** %s", inputs[key].Description), maxWords))
} else {
row = append(row, utils.WordWrap(inputs[key].Description, maxWords))
}
default:
return inputTableOutput, fmt.Errorf(
"unknown input column: '%s'. Please specify any of the following columns: %s",
"unknown inputs column: '%s'. Please specify any of the following columns: %s",
col,
strings.Join(internal.DefaultReusableInputColumns, ", "),
)
Expand Down Expand Up @@ -272,10 +281,10 @@ func renderReusableInputTableOutput(i map[string]ReusableInput, inputColumns []s
}

// renderReusableOutputTableOutput renders the reusable workflow output table
func renderReusableOutputTableOutput(o map[string]ReusableOutput, reusableOutputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
func renderReusableOutputTableOutput(outputs map[string]ReusableOutput, reusableOutputColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
outputTableOutput := &strings.Builder{}

if len(o) > 0 {
if len(outputs) > 0 {
_, err := fmt.Fprintln(outputTableOutput, internal.OutputAutoDocStart)
if err != nil {
return outputTableOutput, err
Expand All @@ -287,8 +296,8 @@ func renderReusableOutputTableOutput(o map[string]ReusableOutput, reusableOutput
outputTable.SetCenterSeparator(internal.PipeSeparator)
outputTable.SetAlignment(tablewriter.ALIGN_CENTER)

keys := make([]string, 0, len(o))
for k := range o {
keys := make([]string, 0, len(outputs))
for k := range outputs {
keys = append(keys, k)
}
sort.Strings(keys)
Expand All @@ -302,12 +311,12 @@ func renderReusableOutputTableOutput(o map[string]ReusableOutput, reusableOutput
case "Output":
row = append(row, key)
case "Value":
row = append(row, utils.FormatValue(o[key].Value))
row = append(row, utils.FormatValue(outputs[key].Value))
case "Description":
row = append(row, utils.WordWrap(o[key].Description, maxWords))
row = append(row, utils.WordWrap(outputs[key].Description, maxWords))
default:
return outputTableOutput, fmt.Errorf(
"unknown output column: '%s'. Please specify any of the following columns: %s",
"unknown outputs column: '%s'. Please specify any of the following columns: %s",
col,
strings.Join(internal.DefaultReusableOutputColumns, ", "),
)
Expand Down Expand Up @@ -336,10 +345,10 @@ func renderReusableOutputTableOutput(o map[string]ReusableOutput, reusableOutput
}

// renderReusableSecretTableOutput renders the reusable workflow secret table
func renderReusableSecretTableOutput(s map[string]ReusableSecret, secretColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
func renderReusableSecretTableOutput(secrets map[string]ReusableSecret, secretColumns []string, maxWidth int, maxWords int) (*strings.Builder, error) {
secretTableOutput := &strings.Builder{}

if len(s) > 0 {
if len(secrets) > 0 {
_, err := fmt.Fprintln(secretTableOutput, internal.SecretsAutoDocStart)
if err != nil {
return secretTableOutput, err
Expand All @@ -351,8 +360,8 @@ func renderReusableSecretTableOutput(s map[string]ReusableSecret, secretColumns
secretTable.SetCenterSeparator(internal.PipeSeparator)
secretTable.SetAlignment(tablewriter.ALIGN_CENTER)

keys := make([]string, 0, len(s))
for k := range s {
keys := make([]string, 0, len(secrets))
for k := range secrets {
keys = append(keys, k)
}
sort.Strings(keys)
Expand All @@ -366,12 +375,12 @@ func renderReusableSecretTableOutput(s map[string]ReusableSecret, secretColumns
case "Secret":
row = append(row, key)
case "Required":
row = append(row, fmt.Sprintf("%v", s[key].Required))
row = append(row, fmt.Sprintf("%v", secrets[key].Required))
case "Description":
row = append(row, utils.WordWrap(s[key].Description, maxWords))
row = append(row, utils.WordWrap(secrets[key].Description, maxWords))
default:
return secretTableOutput, fmt.Errorf(
"unknown secrets column: '%s'. Please specify any of the following columns: %s",
"unknown secrets column: '%secrets'. Please specify any of the following columns: %secrets",
col,
strings.Join(internal.DefaultReusableSecretColumns, ", "),
)
Expand Down

0 comments on commit 1034c3e

Please sign in to comment.