A simple GitHub action to update sections in a markdown file.
Replaces the contents of a markdown (or, technically any file) between a pair of delimiters.
My repository
<!-- start-dynamic-section -->
<!-- end-dynamic-section -->
More test
Can become
My repository
<!-- start-dynamic-section -->
+<pre>
+# Something Dynamic
+
+Lorem ipsum dolor sit amet
+</pre>
<!-- end-dynamic-section -->
More test
Update a section in a markdown with arbitrary markup
name | description | required | default |
---|---|---|---|
file |
Relative path to markdown document to update |
false |
README.md |
delimiter_open |
Opening delimiter to indicate the section to update |
false |
<!-- start-section --> |
delimiter_close |
Closing delimiter to indicate the section to update |
false |
<!-- end-section --> |
content |
Contents to place inside the section delimiters |
true |
"" |
This action is a node20
action.
- uses: alistaircol/update-markdown-action@v0.2.0
with:
file:
# Relative path to markdown document to update
#
# Required: false
# Default: README.md
delimiter_open:
# Opening delimiter to indicate the section to update
#
# Required: false
# Default: `<!-- start-section -->`
delimiter_close:
# Closing delimiter to indicate the section to update
#
# Required: false
# Default: `<!-- end-section -->`
content:
# Contents to place inside the section delimiters
#
# Required: true
# Default: ""
This workflow repository has an example workflow.
It updates the development section below with contents of task --list
.
I have used this workflow elsewhere to:
Project uses nvm
.
nvm use
npm install
[!NOTE] This comment marks the start of a section which is updated using this action in an example workflow!
task: Available tasks for this project:
* actionlint: Lint all workflow yaml files
* build: Build action source for `dist`
* yamllint: Lint all yaml files (and actionlint on workflow files)
[!NOTE] This comment marks the end of a section which is updated using this action!
Once code has been updated, it must be built.
task build
ncc: Version 0.38.1 ncc: Compiling file index.js into CJS 6kB dist/licenses.txt 459kB dist/index.js 465kB [1037ms] - ncc 0.38.1
Get the most recent version that has been tagged and then increment the version.
git --no-pager tag --sort=refname
Update package.json
's version
attribute with the new version.
Tag and push to create a new version.
git tag --annotate --message "Update action to node 20" v0.2.0
git push --follow-tags
npm run test
Testing the action locally for a sanity check.
cat <<EOF > e2e.md && \
INPUT_FILE=e2e.md \
INPUT_DELIMITER_OPEN='<!-- e2e-start-section -->' \
INPUT_DELIMITER_CLOSE='<!-- e2e-end-section -->' \
INPUT_CONTENT='Lorem ipsum dolor sit amet' \
node dist/index.js \
&& less e2e.md \
&& rm e2e.md
<!-- e2e-start-section -->
<!-- e2e-end-section -->
EOF
You should see less
open with:
<pre>
<!-- e2e-start-section -->
<!-- DO NOT EDIT THIS SECTION - IT IS UPDATED BY A GITHUB WORKFLOW -->
Lorem ipsum dolor sit amet
<!-- e2e-end-section -->
</pre>