Skip to content

Commit

Permalink
Merge b84d4ec into cd60cdd
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Mar 9, 2023
2 parents cd60cdd + b84d4ec commit 1fa788b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 26 deletions.
16 changes: 16 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Package cmd provides a cli script that parses the GitHub action.yml and reusable workflow files and outputs a Markdown table to a specified path.
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
29 changes: 29 additions & 0 deletions internal/constants.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
// Package internal/constants contains all internal constants
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package internal

import "fmt"

// InputsHeader represents the markdown header of inputs
const InputsHeader = "## Inputs"
// OutputsHeader represents the markdown header of outputs
const OutputsHeader = "## Outputs"
// SecretsHeader represents the markdown header of secrets
const SecretsHeader = "## Secrets"
// AutoDocStart placeholder that represents the start of the input table
const AutoDocStart = "<!-- AUTO-DOC-%s:START - Do not remove or modify this section -->"
// AutoDocEnd placeholder that represents the end of the input table
const AutoDocEnd = "<!-- AUTO-DOC-%s:END -->"
// PipeSeparator represents the separator used for the distinguishing between columns
const PipeSeparator = "|"
// NewLineSeparator used for splitting lines
const NewLineSeparator = "\n"
// InputAutoDocStart is the start of the input
var InputAutoDocStart = fmt.Sprintf(AutoDocStart, "INPUT")
// InputAutoDocEnd is the end of the input
var InputAutoDocEnd = fmt.Sprintf(AutoDocEnd, "INPUT")
// OutputAutoDocStart is the start of the output
var OutputAutoDocStart = fmt.Sprintf(AutoDocStart, "OUTPUT")
// OutputAutoDocEnd is the end of the output
var OutputAutoDocEnd = fmt.Sprintf(AutoDocEnd, "OUTPUT")
// SecretsAutoDocStart is the start of the secrets
var SecretsAutoDocStart = fmt.Sprintf(AutoDocStart, "SECRETS")
// SecretsAutoDocEnd is the end of the secrets
var SecretsAutoDocEnd = fmt.Sprintf(AutoDocEnd, "SECRETS")

// action.yml
Expand Down
47 changes: 22 additions & 25 deletions internal/types/action.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package types contains all defined types
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package types

import (
Expand Down Expand Up @@ -39,6 +55,7 @@ type Action struct {
Outputs map[string]ActionOutput `yaml:"outputs,omitempty"`
}

// GetData parses the source yaml file
func (a *Action) GetData() error {
actionYaml, err := os.ReadFile(a.InputFileName)
if err != nil {
Expand All @@ -49,6 +66,7 @@ func (a *Action) GetData() error {
return err
}

// WriteDocumentation write the table to the output file
func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) error {
input, err := os.ReadFile(a.OutputFileName)

Expand Down Expand Up @@ -95,6 +113,7 @@ func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) er
return nil
}

// RenderOutput renders the output and writes it to the given output
func (a *Action) RenderOutput() error {
var err error
maxWidth, err := strconv.Atoi(a.ColMaxWidth)
Expand Down Expand Up @@ -125,6 +144,7 @@ func (a *Action) RenderOutput() error {
return nil
}

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

Expand All @@ -149,30 +169,6 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns[]string
inputTable.SetColWidth(maxWidth)

for _, key := range keys {
var inputDefault string
if len(i[key].Default) > 0 {
inputDefault = i[key].Default
var defaultValue string
var parts = strings.Split(inputDefault, "\n")

if len(parts) > 1 && inputDefault != internal.NewLineSeparator {
for _, part := range parts {
if part != "" {
defaultValue += "`\"" + part + "\"`" + "<br>"
}
}
} else {
if strings.Contains(inputDefault, internal.PipeSeparator) {
inputDefault = strings.Replace(inputDefault, internal.PipeSeparator, "\"\\"+internal.PipeSeparator+"\"", -1)
} else {
inputDefault = fmt.Sprintf("%#v", i[key].Default)
}
defaultValue = "`" + inputDefault + "`"
}

inputDefault = defaultValue
}

var row []string

for _, col := range inputColumns {
Expand All @@ -184,7 +180,7 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns[]string
case "Required":
row = append(row, strconv.FormatBool(i[key].Required))
case "Default":
row = append(row, inputDefault)
row = append(row, utils.FormatValue(i[key].Default))
case "Description":
row = append(row, utils.WordWrap(i[key].Description, maxWords))
default:
Expand Down Expand Up @@ -218,6 +214,7 @@ func renderActionInputTableOutput(i map[string]ActionInput, inputColumns[]string
return inputTableOutput, nil
}

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

Expand Down
16 changes: 16 additions & 0 deletions internal/types/documentation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package types contains all defined types
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package types

// Documentation is the interface for Action and Reusable
Expand Down
22 changes: 22 additions & 0 deletions internal/types/reusable.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package types contains all defined types
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package types

import (
Expand Down Expand Up @@ -51,6 +67,7 @@ type Reusable struct {
}
}

// GetData parses the source yaml file
func (r *Reusable) GetData() error {
reusableYaml, err := os.ReadFile(r.InputFileName)
if err != nil {
Expand All @@ -61,6 +78,7 @@ func (r *Reusable) GetData() error {
return err
}

// WriteDocumentation write the table to the output file
func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *strings.Builder) error {
input, err := os.ReadFile(r.OutputFileName)

Expand Down Expand Up @@ -121,6 +139,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
return nil
}

// RenderOutput renders the output and writes it to the given output
func (r *Reusable) RenderOutput() error {
var err error
maxWidth, err := strconv.Atoi(r.ColMaxWidth)
Expand Down Expand Up @@ -155,6 +174,7 @@ func (r *Reusable) RenderOutput() error {
return nil
}

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

Expand Down Expand Up @@ -224,6 +244,7 @@ func renderReusableInputTableOutput(i map[string]ReusableInput, inputColumns[]st
return inputTableOutput, nil
}

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

Expand Down Expand Up @@ -287,6 +308,7 @@ func renderReusableOutputTableOutput(o map[string]ReusableOutput, reusableOutput
return outputTableOutput, nil
}

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

Expand Down
16 changes: 16 additions & 0 deletions internal/utils/bytes_utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package utils is a package that contains all the utility functions
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils

import "bytes"
Expand Down
18 changes: 17 additions & 1 deletion internal/utils/format_value.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package utils is a package that contains all the utility functions
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils

import (
Expand All @@ -13,7 +29,7 @@ func FormatValue(v string) string {

var inputDefault = v
var defaultValue string
var parts = strings.Split(inputDefault, "\n")
var parts = strings.Split(inputDefault, internal.NewLineSeparator)

if len(parts) > 1 && inputDefault != internal.NewLineSeparator {
for _, part := range parts {
Expand Down
16 changes: 16 additions & 0 deletions internal/utils/word_wrap.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//Package utils is a package that contains all the utility functions
/*
Copyright © 2021 Tonye Jack <jtonye@ymail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils

import (
Expand Down

0 comments on commit 1fa788b

Please sign in to comment.