Skip to content

Commit

Permalink
add ignore option
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed May 4, 2023
1 parent e282891 commit cbe83d9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
description: 'The directory containing Markdown files.'
required: true
default: '.'
ignore:
description: 'A regex of Markdown files to ignore.'
required: false
runs:
using: composite
steps:
Expand All @@ -22,4 +25,8 @@ runs:
pip install -r '${{ github.action_path }}/requirements.txt'
- name: Generate ReSpec
shell: bash
run: python3 "${{ github.action_path }}/respec_action.py" "${{ inputs.markdown_dir }}" --branch "${{ inputs.publish_branch }}"
run: |
python3 "${{ github.action_path }}/respec_action.py" \
"${{ inputs.markdown_dir }}" \
--branch "${{ inputs.publish_branch }}" \
--ignore "${{ inputs.ignore }}"
7 changes: 5 additions & 2 deletions respec_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import argparse
import frontmatter

def main(path, branch="gh-pages", skip_publish=False):
def main(path, branch="gh-pages", skip_publish=False, ignore=None):
"""Generate ReSpec HTML from Markdown files in supplied path.
"""
html_files = []
for markdown_file in markdown_files(path):
if ignore and re.match(ignore, str(markdown_file)):
continue
html_files.append(convert(markdown_file))

if not skip_publish:
Expand Down Expand Up @@ -189,5 +191,6 @@ def publish(branch_name, html_files):
parser.add_argument("path", default=".", help="Path to search for Markdown files")
parser.add_argument("--branch", help="Git branch to publish to")
parser.add_argument("--skip-publish", action="store_true", help="Skip publishing")
parser.add_argument("--ignore", help="A regex of Markdown files to ignore")
args = parser.parse_args()
main(args.path, branch=args.branch, skip_publish=args.skip_publish)
main(args.path, branch=args.branch, skip_publish=args.skip_publish, ignore=args.ignore)
1 change: 1 addition & 0 deletions test-data/ignore/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This markdown file should be ignored by respec-action because it was configured to ignore `test/ignore/index.md`.
6 changes: 5 additions & 1 deletion test_respec_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def test_run(setup_data):
assert pathlib.Path('test/embedded/index.md').is_file(), 'embedded file is there'
assert pathlib.Path('test/external/index.md').is_file(), 'external file is there'
assert pathlib.Path('test/external/index.json').is_file(), 'external config is there'
assert pathlib.Path('test/ignore/index.md').is_file(), 'ignored markdown is present'

# generate the respec using the test directory!
respec_action.main('test', skip_publish=True)
respec_action.main('test', skip_publish=True, ignore='test/ignore/index.md')

# html file was created using embedded config
html_file = pathlib.Path('test/embedded/index.html')
Expand All @@ -40,6 +41,9 @@ def test_run(setup_data):
assert '<section id="conformance">' in html
assert '"name": "Git Hub Jr"' in html

# ignored markdown was not processed
assert not pathlib.Path('test/ignore/index.html').is_file()

def test_parse():
markdown = \
"""
Expand Down

0 comments on commit cbe83d9

Please sign in to comment.