Skip to content

Commit

Permalink
Add disable, dot, and enable inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
nosborn committed Jun 8, 2022
1 parent ec9432f commit ee0bcd6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ repos:
- --config-file=.yamllint
- --strict

- repo: https://github.com/rhysd/actionlint
rev: v1.6.13
hooks:
- id: actionlint

minimum_pre_commit_version: !!str 2.19
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ Basic usage with all options enabled:
- name: markdownlint-cli
uses: nosborn/github-action-markdown-cli@v4.0.0
with:
cli-version: latest
config-file: .markdownlint.yaml
files: .
config-file: .markdownlint.yaml
disable: MD013 MD041
dot: true
enable: MD013 MD041
ignore-files: examples/ignore/*
ignore-path: examples/.markdownlintignore
rules: examples/rules/custom.js
cli-version: latest
```

## Inputs

- `files` - what to process (files, directories, globs)
- `config` (optional) - configuration file (JSON or YAML)
- `disable` (optional) - disable certain rules, for example `MD013 MD041`
- `dot` (optional) - if `true`, include files/folders with a dot (for example `.github`)
- `enable` (optional) - enable certain rules, for example `MD013 MD041`
- `ignore` (optional) - files to ignore/exclude (file, directory, glob)
- `ignore-path` (optional) - path to file with ignore patterns
- `rules` (optional) - custom rule files (file, directory, glob, package)
Expand Down
41 changes: 37 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ inputs:
description: configuration file (JSON or YAML)
required: false
deprecationMessage: Please use 'config' instead.
disable:
description: enable certain rules, for example 'MD013 MD041'
required: false
dot:
description: if 'true', include files/folders with a dot (for example '.github')
required: false
enable:
description: enable certain rules, for example 'MD013 MD041'
required: false
files:
description: files, directories, or globs
required: true
Expand Down Expand Up @@ -43,17 +52,38 @@ runs:
- run: |
echo '::group::Installing markdownlint-cli'
version="$(npm view --json markdownlint-cli@${INPUT_CLI_VERSION:?} | jq -r .version)"
IFS='.'; set -- "${version}"; unset IFS
major_version="$1"
minor_version="$2"
prefix="${RUNNER_TOOL_CACHE:-${RUNNER_TEMP:?}}/markdownlint-cli/${version}"
mkdir -p "${prefix}"
# FIXME: --global and --production are deprecated
NPM_CONFIG_PREFIX="${prefix}" npm install --global --production "markdownlint-cli@${version}"
echo '::endgroup::'
markdownlint="${prefix}/bin/markdownlint"
markdownlint="${markdownlint}${INPUT_CONFIG_FILE:+ -c ${INPUT_CONFIG_FILE:?}}"
markdownlint="${markdownlint}${INPUT_IGNORE:+ -i ${INPUT_IGNORE:?}}"
markdownlint="${markdownlint}${INPUT_IGNORE_PATH:+ -p ${INPUT_IGNORE_PATH:?}}"
markdownlint="${markdownlint}${INPUT_RULES:+ -r ${INPUT_RULES:?}}"
markdownlint+="${INPUT_CONFIG_FILE:+ -c ${INPUT_CONFIG_FILE:?}}"
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 30 ]]; then
markdownlint+="${INPUT_DISABLE:+ --disable ${INPUT_DISABLE:?}}"
fi
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 27 ]]; then
if [[ "$(tr '[:upper:]' '[:lower:]' <<<"${INPUT_DOT}")" == true ]]; then
markdownlint+=' --dot'
fi
fi
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 30 ]]; then
markdownlint+="${INPUT_ENABLE:+ --enable ${INPUT_ENABLE:?}}"
fi
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 7 ]]; then
markdownlint+="${INPUT_IGNORE:+ -i ${INPUT_IGNORE:?}}"
fi
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 22 ]]; then
markdownlint+="${INPUT_IGNORE_PATH:+ -p ${INPUT_IGNORE_PATH:?}}"
fi
if [[ ${major_version} -gt 0 ]] || [[ ${minor_version} -ge 11 ]]; then
markdownlint+="${INPUT_RULES:+ -r ${INPUT_RULES:?}}"
fi
printf 'Constructed %s\n' "${markdownlint}"
echo "::add-matcher::${GITHUB_ACTION_PATH:?}/markdownlint-problem-matcher.json"
# shellcheck disable=SC2086
Expand All @@ -65,6 +95,9 @@ runs:
env:
INPUT_CLI_VERSION: ${{ inputs.cli-version }}
INPUT_CONFIG_FILE: ${{ inputs.config || inputs.config_file }}
INPUT_DISABLE: ${{ inputs.disable }}
INPUT_DOT: ${{ inputs.dot }}
INPUT_ENABLE: ${{ inputs.enable }}
INPUT_FILES: ${{ inputs.files }}
INPUT_IGNORE: ${{ inputs.ignore || inputs.ignore_files }}
INPUT_IGNORE_PATH: ${{ inputs.ignore-path || inputs.ignore_path }}
Expand Down

0 comments on commit ee0bcd6

Please sign in to comment.