Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tj-actions/auto-doc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4.0
Choose a base ref
...
head repository: tj-actions/auto-doc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.0
Choose a head ref
  • 7 commits
  • 11 files changed
  • 4 contributors

Commits on Apr 30, 2023

  1. Merge pull request #464 from tj-actions/upgrade-to-v2.4.0

    Upgraded to v2.4.0
    repo-ranger[bot] authored Apr 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4713314 View commit details

Commits on May 1, 2023

  1. Update README.md

    jackton1 authored May 1, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e07ced3 View commit details

Commits on May 2, 2023

  1. Copy the full SHA
    3cc77da View commit details

Commits on May 3, 2023

  1. fix: Update bytes_utils.go (#468)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    jackton1 and github-actions[bot] authored May 3, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8dc1ee9 View commit details

Commits on May 4, 2023

  1. feat: improve handling description data (#469)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    jackton1 and github-actions[bot] authored May 4, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    22dba1f View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    68d8e50 View commit details
  3. Copy the full SHA
    cda3a43 View commit details
Showing with 289 additions and 265 deletions.
  1. +1 −1 .github/workflows/sync-release-version.yml
  2. +19 −7 HISTORY.md
  3. +14 −15 README.md
  4. +4 −8 internal/types/action.go
  5. +8 −13 internal/types/reusable.go
  6. +20 −30 internal/utils/bytes_utils.go
  7. +64 −30 internal/utils/word_wrap.go
  8. +51 −51 test/README-inputColumns.md
  9. +28 −28 test/README-outputColumns.md
  10. +79 −81 test/README.md
  11. +1 −1 test/action.yml
2 changes: 1 addition & 1 deletion .github/workflows/sync-release-version.yml
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ jobs:
token: ${{ secrets.PAT_TOKEN }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.0
uses: peter-evans/create-pull-request@v5.0.1
with:
base: "main"
labels: "merge when passing"
26 changes: 19 additions & 7 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# Changelog

## [v2.4.0](https://github.com/tj-actions/auto-doc/tree/v2.4.0) (2023-04-30)
## [v2.5.0](https://github.com/tj-actions/auto-doc/tree/v2.5.0) (2023-05-04)

[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2.3.2...v2.4.0)
[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2.4.0...v2.5.0)

**Closed issues:**

- Dependency Dashboard [\#2](https://github.com/tj-actions/auto-doc/issues/2)

**Merged pull requests:**

- chore: rename variable [\#470](https://github.com/tj-actions/auto-doc/pull/470) ([jackton1](https://github.com/jackton1))
- feat: improve handling description data [\#469](https://github.com/tj-actions/auto-doc/pull/469) ([jackton1](https://github.com/jackton1))
- fix: Update bytes\_utils.go [\#468](https://github.com/tj-actions/auto-doc/pull/468) ([jackton1](https://github.com/jackton1))
- chore\(deps\): update peter-evans/create-pull-request action to v5.0.1 [\#465](https://github.com/tj-actions/auto-doc/pull/465) ([renovate[bot]](https://github.com/apps/renovate))
- Upgraded to v2.4.0 [\#464](https://github.com/tj-actions/auto-doc/pull/464) ([jackton1](https://github.com/jackton1))

## [v2.4.0](https://github.com/tj-actions/auto-doc/tree/v2.4.0) (2023-04-30)

[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2...v2.4.0)

## [v2](https://github.com/tj-actions/auto-doc/tree/v2) (2023-04-30)

[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2.3.2...v2)

**Merged pull requests:**

- feat: move to use shellscript [\#463](https://github.com/tj-actions/auto-doc/pull/463) ([jackton1](https://github.com/jackton1))
- chore\(deps\): update peter-evans/create-pull-request action to v5 [\#462](https://github.com/tj-actions/auto-doc/pull/462) ([renovate[bot]](https://github.com/apps/renovate))
- fix\(deps\): update module github.com/spf13/cobra to v1.7.0 [\#461](https://github.com/tj-actions/auto-doc/pull/461) ([renovate[bot]](https://github.com/apps/renovate))
@@ -19,11 +35,7 @@

## [v2.3.2](https://github.com/tj-actions/auto-doc/tree/v2.3.2) (2023-03-28)

[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2...v2.3.2)

## [v2](https://github.com/tj-actions/auto-doc/tree/v2) (2023-03-28)

[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2.3.0...v2)
[Full Changelog](https://github.com/tj-actions/auto-doc/compare/v2.3.0...v2.3.2)

**Fixed bugs:**

29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -60,20 +60,20 @@ Add the `Inputs` and/or `Outputs` and/or `Secrets` (only supported by reusable w
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-------------------------|--------|----------|----------------|----------------------------------------------------------------------------------------------------|
| bin\_path | string | false | | Path to the auto-doc binary |
| col\_max\_width | string | false | `"1000"` | Max width of a column |
| col\_max\_words | string | false | `"5"` | Max number of words per line<br>in a column |
| filename | string | false | `"action.yml"` | Path to the yaml file |
| input\_columns | string | false | | List of action.yml **input** columns names<br>to display, default (display all columns) |
| output | string | false | `"README.md"` | Path to the output file |
| output\_columns | string | false | | List of action.yml **output** column names<br>to display, default (display all columns) |
| reusable | string | false | | Boolean Indicating whether the file is<br>a reusable workflow |
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column<br> names to display, default (display all<br>columns) |
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column<br> names to display, default (display all<br>columns) |
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column<br> names to display, default (display all<br>columns) |
| version | string | false | | The version number to run |
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-------------------------|--------|----------|----------------|------------------------------------------------------------------------------------------------|
| bin\_path | string | false | | Path to the auto-doc binary |
| col\_max\_width | string | false | `"1000"` | Max width of a column |
| col\_max\_words | string | false | `"5"` | Max number of words per line<br>in a column |
| filename | string | false | `"action.yml"` | Path to the yaml file |
| input\_columns | string | false | | List of action.yml **input** columns names<br>to display, default (display all columns) |
| output | string | false | `"README.md"` | Path to the output file |
| output\_columns | string | false | | List of action.yml **output** column names<br>to display, default (display all columns) |
| reusable | string | false | | Boolean Indicating whether the file is<br>a reusable workflow |
| reusable\_input\_columns | string | false | | List of reusable workflow **input** column<br>names to display, default (display all columns) |
| reusable\_output\_columns | string | false | | List of reusable workflow **output** column<br>names to display, default (display all columns) |
| reusable\_secret\_columns | string | false | | List of reusable workflow **secret** column<br>names to display, default (display all columns) |
| version | string | false | | The version number to run |
<!-- AUTO-DOC-INPUT:END -->
@@ -179,7 +179,6 @@ This package was created with [Cookiecutter](https://github.com/cookiecutter/coo

* [cobra](https://github.com/spf13/cobra)
* [goreleaser](https://github.com/goreleaser/goreleaser/)
* [gobinaries](https://github.com/tj/gobinaries)

## Report Bugs

12 changes: 4 additions & 8 deletions internal/types/action.go
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) er

var output []byte

hasInputsData, inputStartIndexes, inputEndIndexes := utils.HasBytesInBetween(
hasInputsData, indices := utils.HasBytesInBetween(
input,
[]byte(internal.InputAutoDocStart),
[]byte(internal.InputAutoDocEnd),
@@ -90,9 +90,7 @@ func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) er
inputsStr := strings.TrimSpace(inputTable.String())

if hasInputsData {
for i := 0; i < len(inputStartIndexes); i++ {
output = utils.ReplaceBytesInBetween(output, inputStartIndexes[i], inputEndIndexes[i], []byte(inputsStr))
}
output = utils.ReplaceBytesInBetween(output, indices, []byte(inputsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.InputsHeader))
output = re.ReplaceAllFunc(input, func(match []byte) []byte {
@@ -103,7 +101,7 @@ func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) er
})
}

hasOutputsData, outputStartIndexes, outputEndIndexes := utils.HasBytesInBetween(
hasOutputsData, indices := utils.HasBytesInBetween(
output,
[]byte(internal.OutputAutoDocStart),
[]byte(internal.OutputAutoDocEnd),
@@ -112,9 +110,7 @@ func (a *Action) WriteDocumentation(inputTable, outputTable *strings.Builder) er
outputsStr := strings.TrimSpace(outputTable.String())

if hasOutputsData {
for i := 0; i < len(outputStartIndexes); i++ {
output = utils.ReplaceBytesInBetween(output, outputStartIndexes[i], outputEndIndexes[i], []byte(outputsStr))
}
output = utils.ReplaceBytesInBetween(output, indices, []byte(outputsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.OutputsHeader))
output = re.ReplaceAllFunc(output, func(match []byte) []byte {
21 changes: 8 additions & 13 deletions internal/types/reusable.go
Original file line number Diff line number Diff line change
@@ -27,9 +27,10 @@ import (

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/tj-actions/auto-doc/v2/internal"
"github.com/tj-actions/auto-doc/v2/internal/utils"
"gopkg.in/yaml.v3"
)

// ReusableInput represents the input of the reusable workflow
@@ -92,7 +93,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str

var output []byte

hasInputsData, inputStartIndexes, inputEndIndexes := utils.HasBytesInBetween(
hasInputsData, indices := utils.HasBytesInBetween(
input,
[]byte(internal.InputAutoDocStart),
[]byte(internal.InputAutoDocEnd),
@@ -102,9 +103,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
inputsStr := strings.TrimSpace(inputTable.String())

if hasInputsData {
for i := 0; i < len(inputStartIndexes); i++ {
output = utils.ReplaceBytesInBetween(output, inputStartIndexes[i], inputEndIndexes[i], []byte(inputsStr))
}
output = utils.ReplaceBytesInBetween(output, indices, []byte(inputsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.InputsHeader))
output = re.ReplaceAllFunc(input, func(match []byte) []byte {
@@ -115,7 +114,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
})
}

hasOutputsData, outputStartIndexes, outputEndIndexes := utils.HasBytesInBetween(
hasOutputsData, indices := utils.HasBytesInBetween(
output,
[]byte(internal.OutputAutoDocStart),
[]byte(internal.OutputAutoDocEnd),
@@ -124,9 +123,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
outputsStr := strings.TrimSpace(outputTable.String())

if hasOutputsData {
for i := 0; i < len(outputStartIndexes); i++ {
output = utils.ReplaceBytesInBetween(output, outputStartIndexes[i], outputEndIndexes[i], []byte(outputsStr))
}
output = utils.ReplaceBytesInBetween(output, indices, []byte(outputsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.OutputsHeader))
output = re.ReplaceAllFunc(output, func(match []byte) []byte {
@@ -137,7 +134,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
})
}

hasSecretsData, secretsStartIndexes, secretsEndIndexes := utils.HasBytesInBetween(
hasSecretsData, indices := utils.HasBytesInBetween(
output,
[]byte(internal.SecretsAutoDocStart),
[]byte(internal.SecretsAutoDocEnd),
@@ -146,9 +143,7 @@ func (r *Reusable) WriteDocumentation(inputTable, outputTable, secretsTable *str
secretsStr := strings.TrimSpace(secretsTable.String())

if hasSecretsData {
for i := 0; i < len(secretsStartIndexes); i++ {
output = utils.ReplaceBytesInBetween(output, secretsStartIndexes[i], secretsEndIndexes[i], []byte(secretsStr))
}
output = utils.ReplaceBytesInBetween(output, indices, []byte(secretsStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.SecretsHeader))
output = re.ReplaceAllFunc(output, func(match []byte) []byte {
50 changes: 20 additions & 30 deletions internal/utils/bytes_utils.go
Original file line number Diff line number Diff line change
@@ -17,44 +17,34 @@ limitations under the License.
package utils

import (
"fmt"
"regexp"
)

// HasBytesInBetween checks if a byte array has a start and end byte array and returns true if and all occurrences of start and end
func HasBytesInBetween(value, start, end []byte) (found bool, startIndexes []int, endIndexes []int) {
startRegexp := regexp.MustCompile("(?m)^" + string(start))
endRegexp := regexp.MustCompile("(?m)^" + string(end))

// Find all start and end indexes
for i := 0; i < len(value); i++ {
startLoc := startRegexp.FindIndex(value[i:])
endLoc := endRegexp.FindIndex(value[i:])
if len(startLoc) > 0 && len(endLoc) > 0 {
startIndex := startLoc[0] + i
endIndex := endLoc[1] + i

if startIndex < endIndex {
startIndexes = append(startIndexes, startIndex)
endIndexes = append(endIndexes, endIndex)
}
i += endIndex // skip the content between end and next start
}
}
func HasBytesInBetween(value, start, end []byte) (found bool, indices [][]int) {
// Multiline regex
findRegex := regexp.MustCompile(fmt.Sprintf(`(?s)%s(.*?)%s`, regexp.QuoteMeta(string(start)), regexp.QuoteMeta(string(end))))
indices = findRegex.FindAllIndex(value, -1)

if len(startIndexes) == 0 || len(endIndexes) == 0 {
return false, nil, nil
if len(indices) == 0 {
return false, indices
}

return true, startIndexes, endIndexes
return true, indices
}

// ReplaceBytesInBetween replaces a byte array between a start and end index with a new byte array
func ReplaceBytesInBetween(value []byte, startIndex int, endIndex int, new []byte) []byte {
t := make([]byte, len(value)+len(new))
w := 0
// ReplaceBytesInBetween replaces a byte array between an array of start and end indices with a new byte array
func ReplaceBytesInBetween(value []byte, indices [][]int, new []byte) []byte {
t := make([]byte, 0, len(value)+len(new)*len(indices))
prevIndex := 0

for _, v := range indices {
t = append(t, value[prevIndex:v[0]]...)
t = append(t, new...)
prevIndex = v[1]
}

w += copy(t[:startIndex], value[:startIndex])
w += copy(t[w:w+len(new)], new)
w += copy(t[w:], value[endIndex:])
return t[0:w]
t = append(t, value[prevIndex:]...)
return t
}
94 changes: 64 additions & 30 deletions internal/utils/word_wrap.go
Original file line number Diff line number Diff line change
@@ -19,54 +19,88 @@ package utils
import (
"regexp"
"strings"
"unicode"
)

// WordWrap wraps lengthy words with the br html tag except code blocks, links, and code
// WordWrap wraps text at the specified number of columns
func WordWrap(s string, limit int) string {
if strings.TrimSpace(s) == "" {
return s
}
// compile regular expressions for Markdown links and code blocks and code
linkRegex := regexp.MustCompile(`\[.*]\(.*\)`)
codeBlockRegex := regexp.MustCompile(`\` + "```" + `.*` + "```" + `\s*`)

// convert string to slice
strSlice := strings.Fields(s)
currentLimit := limit
var (
linkIndices = getAllLinksIndex(s)
codeBlockIndices = getAllCodeBlocksIndex(s)
codeIndices = getAllCodeIndex(s)
parenthesisIndices = getAllParenthesisIndex(s)
italicIndices = getAllItalicIndex(s)
start = 0
)

var result string
// split the string into words that aren't between any of the links, code blocks, code and parenthesis
strSlice := strings.FieldsFunc(s, func(r rune) bool {
shouldExclude := isWithin(start, linkIndices) || isWithin(start, codeBlockIndices) || isWithin(start, codeIndices) || isWithin(start, parenthesisIndices) || isWithin(start, italicIndices)
start++
return !shouldExclude && unicode.IsSpace(r)
})

var result = ""

for len(strSlice) >= 1 {
// convert slice/array back to string
// but insert <br> at specified limit
// unless the current slice contains a Markdown link or code block or code
hasMore := len(strSlice) > currentLimit

if hasMore && len(result) > 0 {
result += " "
// but insert \r\n at specified limit
if len(strSlice) < limit {
limit = len(strSlice)
}

if len(strSlice) < currentLimit {
currentLimit = len(strSlice)
result = result + strings.Join(strSlice[:currentLimit], " ")
} else if currentLimit == limit && !linkRegex.MatchString(strings.Join(strSlice[:currentLimit], " ")) && !codeBlockRegex.MatchString(strings.Join(strSlice[:currentLimit], " ")) {
result = result + strings.Join(strSlice[:currentLimit], " ") + "<br>"
} else {
result = result + strings.Join(strSlice[:currentLimit], " ")
}
result = result + strings.Join(strSlice[:limit], " ") + "<br>"

// discard the elements that were copied over to result
strSlice = strSlice[currentLimit:]
strSlice = strSlice[limit:]
}

// Trim the last <br> tag
result = strings.TrimSuffix(result, "<br>")

// change the limit
// to cater for the last few words in the line
if len(strSlice) < currentLimit {
currentLimit = len(strSlice)
return result
}

func isWithin(index int, ranges [][]int) bool {
for _, r := range ranges {
if index >= r[0] && index < r[1] {
return true
}
}

// Remove trailing <br> if any
result = strings.TrimSuffix(result, "<br>")
return false
}

func getAllLinksIndex(s string) [][]int {
linkRegex := regexp.MustCompile(`\[(.*?)\]\((.*?)\)`)

return linkRegex.FindAllStringIndex(s, -1)
}

func getAllCodeBlocksIndex(s string) [][]int {
codeBlockRegex := regexp.MustCompile("```[^`]*```")

return codeBlockRegex.FindAllStringIndex(s, -1)
}

func getAllCodeIndex(s string) [][]int {
codeRegex := regexp.MustCompile("`[^`]*`")

return codeRegex.FindAllStringIndex(s, -1)
}

func getAllParenthesisIndex(s string) [][]int {
parenthesisRegex := regexp.MustCompile(`\((.*?)\)`)

return parenthesisRegex.FindAllStringIndex(s, -1)
}

func getAllItalicIndex(s string) [][]int {
italicRegex := regexp.MustCompile(`\*(.*?)\*`)

return strings.TrimSpace(result)
return italicRegex.FindAllStringIndex(s, -1)
}
Loading