Skip to content

Commit

Permalink
feat: update code block to use col max words (#559)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jackton1 and github-actions[bot] committed Apr 26, 2024
1 parent 3bb922d commit 077a329
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 119 deletions.
50 changes: 30 additions & 20 deletions README.md
Expand Up @@ -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: ''

Expand All @@ -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: ''
Expand All @@ -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: ''
Expand All @@ -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: ''
Expand All @@ -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: ''
Expand Down
6 changes: 3 additions & 3 deletions internal/types/code_block.go
Expand Up @@ -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{}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
121 changes: 73 additions & 48 deletions test/README-codeBlocks.md
Expand Up @@ -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
Expand All @@ -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: ''
Expand All @@ -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: ''
Expand All @@ -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: ''
Expand All @@ -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: ''
Expand Down

0 comments on commit 077a329

Please sign in to comment.