From 077a3295c910d6ce95ec08f7064fbbde4e8256f8 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 26 Apr 2024 03:08:21 -0600 Subject: [PATCH] feat: update code block to use col max words (#559) Co-authored-by: github-actions[bot] --- README.md | 50 ++++++----- internal/types/code_block.go | 6 +- test/README-codeBlocks.md | 121 ++++++++++++++++---------- test/README-codeBlocksMajorVersion.md | 121 ++++++++++++++++---------- 4 files changed, 179 insertions(+), 119 deletions(-) diff --git a/README.md b/README.md index c7680b9..eba8e90 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ Add any of the supported headings as a [`H2` header](https://github.com/adam-p/m - uses: tj-actions/auto-doc@v3 id: auto-doc with: - # Optionally pass a path to the auto-doc binary + # Optionally pass a path to + # the auto-doc binary # Type: string bin_path: '' @@ -98,7 +99,8 @@ Add any of the supported headings as a [`H2` header](https://github.com/adam-p/m # Default: "1000" col_max_width: '' - # Max number of words per line in a column + # Max number of words per + # line in a column # Type: string # Default: "5" col_max_words: '' @@ -108,13 +110,14 @@ Add any of the supported headings as a [`H2` header](https://github.com/adam-p/m # Default: "action.yml" filename: '' - # List of action.yml **input** columns names to display, default - # (display all columns) + # List of action.yml **input** columns + # names to display, default (display all columns) # Type: string input_columns: '' - # Boolean indicating whether to output input, output and secret - # names as markdown links + # Boolean indicating whether to output + # input, output and secret names + # as markdown links # Type: boolean # Default: "true" markdown_links: '' @@ -124,37 +127,43 @@ Add any of the supported headings as a [`H2` header](https://github.com/adam-p/m # Default: "README.md" output: '' - # List of action.yml **output** column names to display, default - # (display all columns) + # List of action.yml **output** column + # names to display, default (display all columns) # Type: string output_columns: '' - # Repository name with owner. For example, tj-actions/auto-doc + # Repository name with owner. For + # example, tj-actions/auto-doc # Type: string # Default: "${{ github.repository }}" repository: '' - # Boolean Indicating whether the file is a reusable workflow + # Boolean Indicating whether the file + # is a reusable workflow # Type: string reusable: '' - # List of reusable workflow **input** column names to display, - # default (display all columns) + # List of reusable workflow **input** + # column names to display, default + # (display all columns) # Type: string reusable_input_columns: '' - # List of reusable workflow **output** column names to display, - # default (display all columns) + # List of reusable workflow **output** + # column names to display, default + # (display all columns) # Type: string reusable_output_columns: '' - # List of reusable workflow **secret** column names to display, - # default (display all columns) + # List of reusable workflow **secret** + # column names to display, default + # (display all columns) # Type: string reusable_secret_columns: '' - # GitHub token or Personal Access Token used to fetch - # the repository latest tag. + # GitHub token or Personal Access + # Token used to fetch the + # repository latest tag. # Type: string # Default: "${{ github.token }}" token: '' @@ -164,8 +173,9 @@ Add any of the supported headings as a [`H2` header](https://github.com/adam-p/m # Default: "false" use_code_blocks: '' - # Use the major version of the repository tag e.g - # v1.0.0 -> v1 + # Use the major version of + # the repository tag e.g v1.0.0 + # -> v1 # Type: boolean # Default: "false" use_major_version: '' diff --git a/internal/types/code_block.go b/internal/types/code_block.go index efd0e2b..62e5b54 100644 --- a/internal/types/code_block.go +++ b/internal/types/code_block.go @@ -140,7 +140,7 @@ func (c *CodeBlock) getLatestTagForRepository() (string, error) { } // renderCodeBlockActionInputs renders the inputs as a code block -func renderCodeBlockActionInputs(inputs map[string]ActionInput, repository, tag string) (*strings.Builder, error) { +func renderCodeBlockActionInputs(inputs map[string]ActionInput, repository, tag string, maxWords int) (*strings.Builder, error) { // Output this as a code block codeBlock := &strings.Builder{} @@ -163,7 +163,7 @@ func renderCodeBlockActionInputs(inputs map[string]ActionInput, repository, tag codeBlock.WriteString(" with:\n") for _, key := range keys { - codeBlock.WriteString(fmt.Sprintf(" # %s\n", utils.WordWrap(inputs[key].Description, 9, "\n # "))) + codeBlock.WriteString(fmt.Sprintf(" # %s\n", utils.WordWrap(inputs[key].Description, maxWords, "\n # "))) if inputs[key].Default == "false" || inputs[key].Default == "true" { codeBlock.WriteString(" # Type: boolean\n") } else { @@ -213,7 +213,7 @@ func (c *CodeBlock) RenderOutput() error { return err } - inputCodeBlockOutput, err := renderCodeBlockActionInputs(c.Inputs, c.Repository, tag) + inputCodeBlockOutput, err := renderCodeBlockActionInputs(c.Inputs, c.Repository, tag, maxWords) // coverage:ignore if err != nil { diff --git a/test/README-codeBlocks.md b/test/README-codeBlocks.md index ca9bc85..8c16626 100644 --- a/test/README-codeBlocks.md +++ b/test/README-codeBlocks.md @@ -5,37 +5,43 @@ - uses: tj-actions/changed-files@v44.3.0 id: changed-files with: - # Specify a different base commit SHA used for comparing - # changes + # Specify a different base commit SHA + # used for comparing changes # Type: string base_sha: '' - # Exclude changes outside the current directory and show path - # names relative to it. **NOTE:** This requires you to - # specify the top level directory via the `path` input. + # Exclude changes outside the current directory + # and show path names relative to + # it. **NOTE:** This requires you to + # specify the top level directory via + # the `path` input. # Type: string diff_relative: '' - # Output unique changed directories instead of filenames. **NOTE:** This - # returns `.` for changed files located in the root + # Output unique changed directories instead of + # filenames. **NOTE:** This returns `.` for + # changed files located in the root # of the project. # Type: boolean # Default: "false" dir_names: '' - # Maximum depth of directories to output. e.g `test/test1/test2` with - # max depth of `2` returns `test/test1`. + # Maximum depth of directories to output. + # e.g `test/test1/test2` with max depth of + # `2` returns `test/test1`. # Type: string dir_names_max_depth: '' - # Depth of additional branch history fetched. **NOTE**: This can - # be adjusted to resolve errors with insufficient history. + # Depth of additional branch history fetched. + # **NOTE**: This can be adjusted to + # resolve errors with insufficient history. # Type: string # Default: "50" fetch_depth: '' - # File and directory patterns to detect changes using only - # these list of file(s) (Defaults to the entire repo) **NOTE:** Multiline file/directory patterns + # File and directory patterns to detect + # changes using only these list of + # file(s) (Defaults to the entire repo) **NOTE:** Multiline file/directory patterns # should not include quotes. # Type: string # Default: a.txt @@ -44,57 +50,67 @@ # files: '' - # Source file(s) used to populate the `files` input. + # Source file(s) used to populate the + # `files` input. # Type: string files_from_source_file: '' - # Ignore changes to these file(s) **NOTE:** Multiline file/directory patterns - # should not include quotes. + # Ignore changes to these file(s) **NOTE:** + # Multiline file/directory patterns should not include + # quotes. # Type: string files_ignore: '' - # Source file(s) used to populate the `files_ignore` input + # Source file(s) used to populate the + # `files_ignore` input # Type: string files_ignore_from_source_file: '' - # Separator used to split the `files_ignore` input + # Separator used to split the `files_ignore` + # input # Type: string # Default: "\n" files_ignore_separator: '' - # Separator used to split the `files` input + # Separator used to split the `files` + # input # Type: string # Default: "\n" files_separator: '' - # Include `all_old_new_renamed_files` output. Note this can generate a large - # output See: [#501](https://github.com/tj-actions/changed-files/issues/501). + # Include `all_old_new_renamed_files` output. Note this can + # generate a large output See: [#501](https://github.com/tj-actions/changed-files/issues/501). # Type: boolean # Default: "false" include_all_old_new_renamed_files: '' - # Output list of changed files in a JSON formatted - # string which can be used for matrix jobs. + # Output list of changed files in + # a JSON formatted string which can + # be used for matrix jobs. # Type: boolean # Default: "false" json: '' - # Output list of changed files in a raw format - # which means that the output will not be surrounded - # by quotes and special characters will not be escaped. + # Output list of changed files in + # a raw format which means that + # the output will not be surrounded + # by quotes and special characters will + # not be escaped. # Type: boolean # Default: "false" # Deprecated: Use `json_unescaped` instead. json_raw_format: '' - # Output list of changed files in a JSON formatted - # string without escaping special characters. + # Output list of changed files in + # a JSON formatted string without escaping + # special characters. # Type: boolean # Default: "false" json_unescaped: '' - # Boolean indicating whether to output input, output and secret - # names as markdown links + # Boolean indicating whether to output input, + # output and secret names as markdown + # links # Type: boolean # Default: "false" markdown_links: '' @@ -104,12 +120,14 @@ # Default: "true" match_directories: '' - # Split character for old and new renamed filename pairs. + # Split character for old and new + # renamed filename pairs. # Type: string # Default: " " old_new_files_separator: '' - # Split character for old and new filename pairs. + # Split character for old and new + # filename pairs. # Type: string # Default: "," old_new_separator: '' @@ -119,14 +137,15 @@ # Default: ".github/outputs" output_dir: '' - # Specify a relative path under `$GITHUB_WORKSPACE` to locate the - # repository. + # Specify a relative path under `$GITHUB_WORKSPACE` + # to locate the repository. # Type: string # Default: "." path: '' - # Use non ascii characters to match files and output - # the filenames completely verbatim by setting this to `false` + # Use non ascii characters to match + # files and output the filenames completely + # verbatim by setting this to `false` # Type: boolean # Default: "true" quotepath: '' @@ -136,36 +155,42 @@ # Default: "|" separator: '' - # Specify a different commit SHA used for comparing changes + # Specify a different commit SHA used + # for comparing changes # Type: string sha: '' - # Get changed files for commits whose timestamp is older - # than the given time. + # Get changed files for commits whose + # timestamp is older than the given + # time. # Type: string since: '' - # Use the last commit on the remote branch as - # the `base_sha`. Defaults to the last non merge commit - # on the target branch for pull request events and - # the previous remote commit of the current branch for + # Use the last commit on the + # remote branch as the `base_sha`. Defaults + # to the last non merge commit + # on the target branch for pull + # request events and the previous remote + # commit of the current branch for # push events. # Type: boolean # Default: "false" since_last_remote_commit: '' - # The GitHub token to use for authentication. + # The GitHub token to use for + # authentication. # Type: string # Default: "${{ github.token }}" token: '' - # Get changed files for commits whose timestamp is earlier - # than the given time. + # Get changed files for commits whose + # timestamp is earlier than the given + # time. # Type: string until: '' - # Write outputs to files in the `.github/outputs` folder by - # default. + # Write outputs to files in the + # `.github/outputs` folder by default. # Type: boolean # Default: "false" write_output_files: '' diff --git a/test/README-codeBlocksMajorVersion.md b/test/README-codeBlocksMajorVersion.md index c0c8695..c9158aa 100644 --- a/test/README-codeBlocksMajorVersion.md +++ b/test/README-codeBlocksMajorVersion.md @@ -5,37 +5,43 @@ - uses: tj-actions/changed-files@v44 id: changed-files with: - # Specify a different base commit SHA used for comparing - # changes + # Specify a different base commit SHA + # used for comparing changes # Type: string base_sha: '' - # Exclude changes outside the current directory and show path - # names relative to it. **NOTE:** This requires you to - # specify the top level directory via the `path` input. + # Exclude changes outside the current directory + # and show path names relative to + # it. **NOTE:** This requires you to + # specify the top level directory via + # the `path` input. # Type: string diff_relative: '' - # Output unique changed directories instead of filenames. **NOTE:** This - # returns `.` for changed files located in the root + # Output unique changed directories instead of + # filenames. **NOTE:** This returns `.` for + # changed files located in the root # of the project. # Type: boolean # Default: "false" dir_names: '' - # Maximum depth of directories to output. e.g `test/test1/test2` with - # max depth of `2` returns `test/test1`. + # Maximum depth of directories to output. + # e.g `test/test1/test2` with max depth of + # `2` returns `test/test1`. # Type: string dir_names_max_depth: '' - # Depth of additional branch history fetched. **NOTE**: This can - # be adjusted to resolve errors with insufficient history. + # Depth of additional branch history fetched. + # **NOTE**: This can be adjusted to + # resolve errors with insufficient history. # Type: string # Default: "50" fetch_depth: '' - # File and directory patterns to detect changes using only - # these list of file(s) (Defaults to the entire repo) **NOTE:** Multiline file/directory patterns + # File and directory patterns to detect + # changes using only these list of + # file(s) (Defaults to the entire repo) **NOTE:** Multiline file/directory patterns # should not include quotes. # Type: string # Default: a.txt @@ -44,57 +50,67 @@ # files: '' - # Source file(s) used to populate the `files` input. + # Source file(s) used to populate the + # `files` input. # Type: string files_from_source_file: '' - # Ignore changes to these file(s) **NOTE:** Multiline file/directory patterns - # should not include quotes. + # Ignore changes to these file(s) **NOTE:** + # Multiline file/directory patterns should not include + # quotes. # Type: string files_ignore: '' - # Source file(s) used to populate the `files_ignore` input + # Source file(s) used to populate the + # `files_ignore` input # Type: string files_ignore_from_source_file: '' - # Separator used to split the `files_ignore` input + # Separator used to split the `files_ignore` + # input # Type: string # Default: "\n" files_ignore_separator: '' - # Separator used to split the `files` input + # Separator used to split the `files` + # input # Type: string # Default: "\n" files_separator: '' - # Include `all_old_new_renamed_files` output. Note this can generate a large - # output See: [#501](https://github.com/tj-actions/changed-files/issues/501). + # Include `all_old_new_renamed_files` output. Note this can + # generate a large output See: [#501](https://github.com/tj-actions/changed-files/issues/501). # Type: boolean # Default: "false" include_all_old_new_renamed_files: '' - # Output list of changed files in a JSON formatted - # string which can be used for matrix jobs. + # Output list of changed files in + # a JSON formatted string which can + # be used for matrix jobs. # Type: boolean # Default: "false" json: '' - # Output list of changed files in a raw format - # which means that the output will not be surrounded - # by quotes and special characters will not be escaped. + # Output list of changed files in + # a raw format which means that + # the output will not be surrounded + # by quotes and special characters will + # not be escaped. # Type: boolean # Default: "false" # Deprecated: Use `json_unescaped` instead. json_raw_format: '' - # Output list of changed files in a JSON formatted - # string without escaping special characters. + # Output list of changed files in + # a JSON formatted string without escaping + # special characters. # Type: boolean # Default: "false" json_unescaped: '' - # Boolean indicating whether to output input, output and secret - # names as markdown links + # Boolean indicating whether to output input, + # output and secret names as markdown + # links # Type: boolean # Default: "false" markdown_links: '' @@ -104,12 +120,14 @@ # Default: "true" match_directories: '' - # Split character for old and new renamed filename pairs. + # Split character for old and new + # renamed filename pairs. # Type: string # Default: " " old_new_files_separator: '' - # Split character for old and new filename pairs. + # Split character for old and new + # filename pairs. # Type: string # Default: "," old_new_separator: '' @@ -119,14 +137,15 @@ # Default: ".github/outputs" output_dir: '' - # Specify a relative path under `$GITHUB_WORKSPACE` to locate the - # repository. + # Specify a relative path under `$GITHUB_WORKSPACE` + # to locate the repository. # Type: string # Default: "." path: '' - # Use non ascii characters to match files and output - # the filenames completely verbatim by setting this to `false` + # Use non ascii characters to match + # files and output the filenames completely + # verbatim by setting this to `false` # Type: boolean # Default: "true" quotepath: '' @@ -136,36 +155,42 @@ # Default: "|" separator: '' - # Specify a different commit SHA used for comparing changes + # Specify a different commit SHA used + # for comparing changes # Type: string sha: '' - # Get changed files for commits whose timestamp is older - # than the given time. + # Get changed files for commits whose + # timestamp is older than the given + # time. # Type: string since: '' - # Use the last commit on the remote branch as - # the `base_sha`. Defaults to the last non merge commit - # on the target branch for pull request events and - # the previous remote commit of the current branch for + # Use the last commit on the + # remote branch as the `base_sha`. Defaults + # to the last non merge commit + # on the target branch for pull + # request events and the previous remote + # commit of the current branch for # push events. # Type: boolean # Default: "false" since_last_remote_commit: '' - # The GitHub token to use for authentication. + # The GitHub token to use for + # authentication. # Type: string # Default: "${{ github.token }}" token: '' - # Get changed files for commits whose timestamp is earlier - # than the given time. + # Get changed files for commits whose + # timestamp is earlier than the given + # time. # Type: string until: '' - # Write outputs to files in the `.github/outputs` folder by - # default. + # Write outputs to files in the + # `.github/outputs` folder by default. # Type: boolean # Default: "false" write_output_files: ''