diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf6ef86..8a28176 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,3 +38,38 @@ jobs: globs: | *.md test/* + command-config: + name: Command = config (test/errors.md, errors) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + command: config + globs: | + config/.markdownlint.jsonc + test/* + command-config-missing: + name: Command = config (missing configuration file) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + command: config + command-fix: + name: Command = fix (test/errors.md, no errors) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + command: fix + command-unsupported: + name: Command = unsupported (fails) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + command: unsupported diff --git a/README.md b/README.md index 72a7d26..6f6501e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,20 @@ information. ## Inputs +### command (optional) + +Command to run (unset, `fix`, or `config`) + +If unspecified or `""`, the `markdownlint-cli2` command is run. + +If set to `fix`, the `markdownlint-cli2-fix` command is run and supported +issues will be fixed automatically. + +If set to `config`, the `markdownlint-cli2-config` command is run and the +first element of `globs` should specify a supported configuration file. + +For more detail: [command line documentation for `markdownlint-cli2`][command-line]. + ### globs (optional) Glob expression(s) of files to lint (newline-delimited) @@ -20,7 +34,7 @@ Glob expression(s) of files to lint (newline-delimited) The default `*.{md,markdown}` lints all Markdown files in the base directory of a project. -For more detail, read about [glob syntax in `markdownlint-cli2`][glob-syntax]. +For more detail: [glob syntax in `markdownlint-cli2`][glob-syntax]. ## Outputs @@ -63,6 +77,7 @@ To prevent linting issues from failing the workflow run: See [`example.yml`][example-yml] for a simple GitHub workflow that uses `markdownlint-cli2-action`. +[command-line]: https://github.com/DavidAnson/markdownlint-cli2#command-line [commonmark]: https://commonmark.org/ [example-yml]: .github/workflows/example.yml [glob-syntax]: https://github.com/DavidAnson/markdownlint-cli2#use diff --git a/action.yml b/action.yml index 1055839..edff190 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ branding: icon: 'check-square' color: 'orange' inputs: + command: + description: 'Command to run (unset, "fix", or "config")' + default: '' + required: false globs: description: 'Glob expression(s) of files to lint (newline-delimited)' default: '*.{md,markdown}' diff --git a/config/.markdownlint.jsonc b/config/.markdownlint.jsonc new file mode 100644 index 0000000..35c7d6f --- /dev/null +++ b/config/.markdownlint.jsonc @@ -0,0 +1,3 @@ +{ + "single-trailing-newline": false +} diff --git a/dist/index.js b/dist/index.js index 4801f9a..dca01d5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32158,14 +32158,36 @@ const argv = split("\n"). filter(String); -markdownlintCli2({ +const parameters = { argv, logMessage, logError -}).then( - (code) => code && core.setFailed(`Failed with exit code: ${code}`), - (error) => core.setFailed(`Failed due to error: ${error}`) -); +}; +let invoke = true; +const command = core.getInput("command"); +switch (command) { +case "": + // Default behavior + break; +case "config": + parameters.name = "markdownlint-cli2-config"; + break; +case "fix": + parameters.name = "markdownlint-cli2-fix"; + parameters.fixDefault = true; + break; +default: + core.setFailed(`Unsupported command: ${command}`); + invoke = false; + break; +} + +if (invoke) { + markdownlintCli2(parameters).then( + (code) => code && core.setFailed(`Failed with exit code: ${code}`), + (error) => core.setFailed(`Failed due to error: ${error}`) + ); +} })(); diff --git a/markdownlint-cli2-action.js b/markdownlint-cli2-action.js index ddce6d7..316b246 100644 --- a/markdownlint-cli2-action.js +++ b/markdownlint-cli2-action.js @@ -37,11 +37,33 @@ const argv = split("\n"). filter(String); -markdownlintCli2({ +const parameters = { argv, logMessage, logError -}).then( - (code) => code && core.setFailed(`Failed with exit code: ${code}`), - (error) => core.setFailed(`Failed due to error: ${error}`) -); +}; +let invoke = true; +const command = core.getInput("command"); +switch (command) { +case "": + // Default behavior + break; +case "config": + parameters.name = "markdownlint-cli2-config"; + break; +case "fix": + parameters.name = "markdownlint-cli2-fix"; + parameters.fixDefault = true; + break; +default: + core.setFailed(`Unsupported command: ${command}`); + invoke = false; + break; +} + +if (invoke) { + markdownlintCli2(parameters).then( + (code) => code && core.setFailed(`Failed with exit code: ${code}`), + (error) => core.setFailed(`Failed due to error: ${error}`) + ); +} diff --git a/package.json b/package.json index e16e392..435a7b0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "build": "ncc build markdownlint-cli2-action.js", "docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm install", "docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm run upgrade", - "lint": "eslint *.js", + "lint": "eslint *.js && markdownlint-cli2 *.md", "test": "npm run lint && npm run build && git diff --exit-code", "upgrade": "npx --yes npm-check-updates --upgrade" },