0
0
Fork 0
mirror of https://github.com/DavidAnson/markdownlint-cli2-action.git synced 2024-12-22 04:43:32 +01:00

Add "command" input to allow invoking -fix and -config commands (fixes #7, fixes #8).

This commit is contained in:
David Anson 2022-07-21 22:24:48 -07:00
parent 4309653070
commit 0820d56e6c
7 changed files with 113 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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}'

View file

@ -0,0 +1,3 @@
{
"single-trailing-newline": false
}

32
dist/index.js vendored
View file

@ -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}`)
);
}
})();

View file

@ -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}`)
);
}

View file

@ -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"
},