Skip to content

Commit

Permalink
Bump version to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpaone committed Sep 2, 2024
1 parent 3c9a84e commit 8bea092
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 396 deletions.
File renamed without changes.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Contributions are welcome! Please follow these steps:

1. Fork the project.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit your changes (`git commit -m 'Add a feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Open a Pull Request.
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Issues](https://img.shields.io/github/issues/gnpaone/dynamic-update-readme?color=orange&style=flat-square)](https://github.com/gnpaone/dynamic-update-readme/issues)
[![Go](https://img.shields.io/github/go-mod/go-version/gnpaone/dynamic-update-readme?color=maroon&style=flat-square)](https://github.com/gnpaone/dynamic-update-readme/blob/main/go.mod)
[![Godoc](https://pkg.go.dev/badge/github.com/gnpaone/dynamic-update-readme.svg?utm_source=godoc)](https://godoc.org/github.com/gnpaone/dynamic-update-readme)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-v1.0.2-undefined.svg?logo=github&logoColor=white&style=flat-square)](https://github.com/marketplace/actions/dynamic-update-readme)

#### As a power user, automate the updating of markdown text with content obtained from other actions in the workflow, as well as a Go module that can update markdown text

Expand All @@ -17,40 +18,47 @@ A Go module that updates markdown text and is integrated as a GitHub Action.

## Parameters

| Parameter | Workflow default | Description | Required | Possible values |
|:----------------:|:-------------------:|:-------------------------------------------|:-----------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| readme_path | ./README.md | Path of the markdown file | No | *File path relative to the root directory of the GitHub repo* |
| marker_text | *null* | Marker text to replace in markdown file | Yes | *Example markers to be added in the markdown:*<br>`<!-- `*marker_text*`_START --><!-- `*marker_text*`_END -->` |
| markdown_text | *null* | Markdown text that needs to be updated | Yes | *Any markdown compatible text (For GitHub markdown please check [GitHub Flavored Markdown parser](https://github.github.com/gfm/))* |
| table | false | Markdown text is a table | No | true, false |
| table_options | *null* | Alignment for the table | No | align-*Alignment*, head-align-*Alignment*, text-align-*Alignment*, col-*Column*-align-*Alignment*, col-*Column*-w-*Min-width*, colH-*Column*-align-*Alignment*, colT-*Column*-align-*Alignment* |
| Parameter | Workflow default | Description | Required | Possible values |
|:----------------:|:-------------------:|:-------------------------------------------|:-----------:|:-------------------|
| readme_path | ./README.md | Path of the markdown file | No | *File path relative to the root directory of the GitHub repo* |
| marker_text | *null* | Marker text to replace in markdown file | Yes | *Example markers to be added in the markdown:*<br>`<!-- `*marker_text*`_START --><!-- `*marker_text*`_END -->` |
| markdown_text | *null* | Markdown text that needs to be updated | Yes | *Any markdown compatible text* |
| table | false | Markdown text is a table | No | true, false |
| table_options | *null* | Alignment for the table | No | align-*Alignment*, col-*Column*-align-*Alignment*, col-*Column*-w-*Min-width* |

<sup>_Alignment_: `left, right, center`<br>_Column_: Column number of the table (starts with `0`)<br>_Min-width_: Minimum width of a column (in other words, minimum number of hyphens (`-`) in the delimiter row)</sup>

### Notes:
* Make sure to change the following in your GitHub repo settings: `Actions` > `General` > `Workflow permissions` > Choose `Read and write permissions` > Check `Allow GitHub Actions to create and approve pull requests` > `Save`.
* Other parameters `commit_user`, `commit_email`, `commit_message` and `confirm_and_push` related to action workflow are optional.
* If `confirm_and_push` is "false" committer detalis can be accessed via `outputs.commit_user`, `outputs.commit_email` & `outputs.commit_message` for further usage in the workflow.
* The syntax mostly revolves around [GitHub Flavored Markdown parser](https://github.github.com/gfm/).
* The `table` parameter is optional as `markdown_text` supports table markdown syntax by default but this parameter can be used as a simple alternative or any special use case. If `table` is "true":
- It uses [github.com/willabides/mdtable](https://godoc.org/github.com/willabides/mdtable) module
- `markdown_text` contents should follow these conditions:
+ Table row contents are seperated with ";" delimiter. First element will make up the table header.
+ For each element of table rows, table column contents are seperated with "," delimiter.
- `table_options` can be used only if `table` is "true".
+ Description of options/values:
1. `align-`: This option aligns the whole table according to the alignment set.
2. `head-`: This option aligns the header row of the table according to the alignment set.
3. `text-`: This option aligns all the data rows of the table according to the alignment set.
4. `col-`: This option sets properties of any particular column based on the column number.
5. `colH-`: This option sets properties of header row of any particular column based on the column number.
6. `colT-`: This option sets properties of data rows of any particular column based on the column number.
+ Order of preference of the alignment options:
1. Header rows: `colH-` > `col-` > `head-` > `align-`
2. Data rows: `colT-` > `col-` > `text-` > `align-`
2. `col-`: This option sets properties of any particular column based on the column number.
+ Order of preference of the alignment options: `col-` > `align-`
* The markdown file must contain start marker `<!-- EXAMPLE_MARKER_START -->` and end marker `<!-- EXAMPLE_MARKER_END -->` where "EXAMPLE_MARKER" is the input of `marker_text` parameter. Note that the `_START` and `_END` part is important.

## Usage
Check the example workflow [here](https://github.com/gnpaone/dynamic-update-readme/blob/main/examples/update.yml).

## Contributing
See [CONTRIBUTING.md](https://github.com/gnpaone/dynamic-update-readme/blob/main/CONTRIBUTING.md) for more details.

## Acknowledgements

This project uses few of the open-source Go modules, without which it would not have been possible. I extend my gratitude to the developers and maintainers of these modules for their valuable contributions to the open-source community:

* [github.com/willabides/mdtable](https://godoc.org/github.com/willabides/mdtable) - Generates markdown tables from string slices.
* [github.com/mattn/go-runewidth](https://godoc.org/github.com/mattn/go-runewidth) - Provides functions to get fixed width of the character or string.
* [github.com/rivo/uniseg](https://godoc.org/github.com/rivo/uniseg) - Implements Unicode Text Segmentation, Word Wrapping, and String Width Calculation.

## License
This project is licensed under GPL-3.0.
Copyright © 2024, Naveen Prashanth. All Rights Reserved.
3 changes: 2 additions & 1 deletion action/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module github.com/gnpaone/dynamic-update-readme/update-readme-action

go 1.22

require github.com/gnpaone/dynamic-update-readme v1.0.1
require github.com/gnpaone/dynamic-update-readme v1.0.2

require (
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/willabides/mdtable v0.3.1 // indirect
)
108 changes: 54 additions & 54 deletions dynreadme.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

table "github.com/gnpaone/dynamic-update-readme/helpers"
table "github.com/willabides/mdtable"
)

// UpdateContent parses and updates content between markers
Expand Down Expand Up @@ -69,57 +69,57 @@ func parseTableOptions(tableOptions string) []table.Option {
}
}

case strings.HasPrefix(part, "colH-"):
colHParts := strings.Split(part, "-")
if len(colHParts) >= 3 {
colHNum := parseColumnNumber(colHParts[1])
switch colHParts[2] {
case "align":
if len(colHParts) == 4 {
alignment := parseAlignment(colHParts[3])
options = append(options, table.ColumnHeaderAlignment(colHNum, alignment))
}
}
}

case strings.HasPrefix(part, "colT-"):
colTParts := strings.Split(part, "-")
if len(colTParts) >= 3 {
colTNum := parseColumnNumber(colTParts[1])
switch colTParts[2] {
case "align":
if len(colTParts) == 4 {
alignment := parseAlignment(colTParts[3])
options = append(options, table.ColumnTextAlignment(colTNum, alignment))
}
}
}

case strings.HasPrefix(part, "head-"):
headParts := strings.Split(part, "-")
if len(headParts) >= 2 {
switch headParts[1] {
case "align":
if len(headParts) == 3 {
alignment := parseAlignment(headParts[2])
options = append(options, table.HeaderAlignment(alignment))
}
}

}

case strings.HasPrefix(part, "text-"):
textParts := strings.Split(part, "-")
if len(textParts) >= 2 {
switch textParts[1] {
case "align":
if len(textParts) == 3 {
alignment := parseAlignment(textParts[2])
options = append(options, table.TextAlignment(alignment))
}
}

}
// case strings.HasPrefix(part, "colH-"):
// colHParts := strings.Split(part, "-")
// if len(colHParts) >= 3 {
// colHNum := parseColumnNumber(colHParts[1])
// switch colHParts[2] {
// case "align":
// if len(colHParts) == 4 {
// alignment := parseAlignment(colHParts[3])
// options = append(options, table.ColumnHeaderAlignment(colHNum, alignment))
// }
// }
// }

// case strings.HasPrefix(part, "colT-"):
// colTParts := strings.Split(part, "-")
// if len(colTParts) >= 3 {
// colTNum := parseColumnNumber(colTParts[1])
// switch colTParts[2] {
// case "align":
// if len(colTParts) == 4 {
// alignment := parseAlignment(colTParts[3])
// options = append(options, table.ColumnTextAlignment(colTNum, alignment))
// }
// }
// }

// case strings.HasPrefix(part, "head-"):
// headParts := strings.Split(part, "-")
// if len(headParts) >= 2 {
// switch headParts[1] {
// case "align":
// if len(headParts) == 3 {
// alignment := parseAlignment(headParts[2])
// options = append(options, table.HeaderAlignment(alignment))
// }
// }

// }

// case strings.HasPrefix(part, "text-"):
// textParts := strings.Split(part, "-")
// if len(textParts) >= 2 {
// switch textParts[1] {
// case "align":
// if len(textParts) == 3 {
// alignment := parseAlignment(textParts[2])
// options = append(options, table.TextAlignment(alignment))
// }
// }

// }
}
}
return options
Expand All @@ -142,15 +142,15 @@ func parseColumnNumber(num string) int {
var colNum int
if _, err := fmt.Sscanf(num, "%d", &colNum); err != nil {
log.Fatalf("Error parsing column number: %s", err)
}
}
return colNum
}

func parseColumnWidth(width string) int {
var w int
if _, err := fmt.Sscanf(width, "%d", &w); err != nil {
log.Fatalf("Error parsing column width: %s", err)
}
}
return w
}

Expand Down
10 changes: 5 additions & 5 deletions examples/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

# Marker as <!-- EXAMPLE_START --><!-- EXAMPLE_END -->
- name: Example 1 - multiple lines
uses: gnpaone/[email protected].1
uses: gnpaone/[email protected].2
with:
marker_text: "EXAMPLE"
markdown_text: |
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
### Requirements
- Node.js >= 18.0.0
- npm >= 6.0.0
- npm >= 9.0.0
## Usage
Expand Down Expand Up @@ -168,15 +168,15 @@ jobs:
# Marker as <!-- MARKER_TEXT_START --><!-- MARKER_TEXT_END -->
- name: Example 2 - single line
uses: gnpaone/[email protected].1
uses: gnpaone/[email protected].2
with:
marker_text: "MARKER_TEXT"
markdown_text: "This is a sample text."
markdown_text: "#### This is a sample text."
confirm_and_push: "false"

# Marker as <!-- TABLE_START --><!-- TABLE_END -->
- name: Example 3 - add table
uses: gnpaone/[email protected].1
uses: gnpaone/[email protected].2
with:
marker_text: "TABLE"
table: "true"
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ go 1.22

require (
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/willabides/mdtable v0.3.1 // indirect
)
Loading

0 comments on commit 8bea092

Please sign in to comment.