-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Replace the v5 megalinter hook with a v6 megalinter-incremental hook that only runs on the modified files, skipping all linters that run in project mode. Replace the v5 megalinter-all hook with a v6 megalinter-full hook that runs only on the modified files when supported, but also runs linters that run in project mode. This brings MegaLinter's pre-commit hooks more in line with typical hooks, which run on the files passed by pre-commit rather than running git diff themselves. Leverage new v6 features to automatically clean up the Docker container and megalinter-reports directory, and give a meaningful name to the Docker container rather than one randomly generated by Docker. Update documentation to reflect that the report directory was renamed megalinter-reports in v6. Remove FAIL_IF_UPDATED_SOURCES=true since pre-commit hooks already fail when the hook modifies files, and this setting causes MegaLinter to fail whenever there are unstaged changes. Stop limiting the hooks to specific stages. The ability to run MegaLinter on specific files while still running all project linters is a significant performance improvement over running all linters on all files, so some users may wish to run the new megalinter-full hook pre-commit, not just pre-push. Conversely, some users may find the performance of megalinter-full prohibitive to run locally and prefer to only run megalinter-incremental pre-push.
- Loading branch information
1 parent
b4f03aa
commit 23633be
Showing
3 changed files
with
38 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,55 @@ | ||
- id: megalinter | ||
name: Run MegaLinter on files modified relative to DEFAULT_BRANCH | ||
- id: megalinter-incremental | ||
name: Run MegaLinter (skipping linters that run in project mode) | ||
entry: npx -- | ||
language: system | ||
pass_filenames: false | ||
args: | ||
- mega-linter-runner | ||
- --containername "megalinter-$(basename "$PWD")" | ||
- --remove-container | ||
- --fix | ||
- --env | ||
- "'APPLY_FIXES=all'" | ||
- --env | ||
- "'FAIL_IF_UPDATED_SOURCES=true'" | ||
- "'CLEAR_REPORT_FOLDER=true'" | ||
- --env | ||
- "'LOG_LEVEL=warning'" | ||
- --env | ||
- "'VALIDATE_ALL_CODEBASE=false'" | ||
- --env | ||
- "'DISABLE_LINTERS=COPYPASTE_JSCPD'" | ||
stages: | ||
- commit | ||
- --filesonly | ||
description: > | ||
See https://oxsecurity.github.io/megalinter/latest/mega-linter-runner/#usage and | ||
https://oxsecurity.github.io/megalinter/latest/configuration/ if you wish to override | ||
the default arguments. mega-linter-runner is specified as an argument so | ||
that you may override the version (e.g., mega-linter-runner@vx.y.z). Depends | ||
on npx, which ships with npm 7+, and Docker. Unlike most pre-commit hooks, | ||
MegaLinter itself computes the files to run on. Runs very slowly when the | ||
pertinent Docker image isn't already cached (c.f., | ||
https://github.com/marketplace/actions/docker-cache/). If you encounter | ||
permission errors, try running Docker in rootless mode (c.f., | ||
See https://oxsecurity.github.io/megalinter/latest/mega-linter-runner/#usage | ||
and https://oxsecurity.github.io/megalinter/latest/configuration/ if you | ||
wish to override the default arguments. mega-linter-runner is specified as | ||
an argument so that you may override the version (e.g., | ||
mega-linter-runner@vx.y.z). Depends on npx, which ships with npm 7+, and | ||
Docker. Runs very slowly when the pertinent Docker image isn't already | ||
cached (c.f., https://github.com/marketplace/actions/docker-cache/). If you | ||
encounter permission errors, try running Docker in rootless mode (c.f., | ||
https://github.com/marketplace/actions/rootless-docker/). Linter results are | ||
logged to the report directory, so you should make sure to list it in your | ||
.gitignore and wipe it between runs. Skip jscpd since duplicate detection | ||
fundamentally requires scanning the entire repository and hence can't be | ||
performed incrementally. | ||
logged to the megalinter-reports directory, so list it in your .gitignore. | ||
Skip linters that run in project mode since they don't run incrementally. | ||
- id: megalinter-all | ||
name: Run MegaLinter on all files | ||
- id: megalinter-full | ||
name: Run MegaLinter | ||
entry: npx -- | ||
language: system | ||
pass_filenames: false | ||
args: | ||
- mega-linter-runner | ||
- --containername "megalinter-all-$(basename "$PWD")" | ||
- --remove-container | ||
- --fix | ||
- --env | ||
- "'APPLY_FIXES=all'" | ||
- --env | ||
- "'FAIL_IF_UPDATED_SOURCES=true'" | ||
- "'CLEAR_REPORT_FOLDER=true'" | ||
- --env | ||
- "'LOG_LEVEL=warning'" | ||
- --env | ||
- "'VALIDATE_ALL_CODEBASE=true'" | ||
stages: | ||
- push | ||
description: > | ||
See https://oxsecurity.github.io/megalinter/latest/mega-linter-runner/#usage and | ||
https://oxsecurity.github.io/megalinter/latest/configuration/ if you wish to override | ||
the default arguments. mega-linter-runner is specified as an argument so | ||
that you may override the version (e.g., mega-linter-runner@vx.y.z). Depends | ||
on npx, which ships with npm 7+, and Docker. Runs very slowly when the | ||
pertinent Docker image isn't already cached (c.f., | ||
https://github.com/marketplace/actions/docker-cache/). If you encounter | ||
permission errors, try running Docker in rootless mode (c.f., | ||
See https://oxsecurity.github.io/megalinter/latest/mega-linter-runner/#usage | ||
and https://oxsecurity.github.io/megalinter/latest/configuration/ if you | ||
wish to override the default arguments. mega-linter-runner is specified as | ||
an argument so that you may override the version (e.g., | ||
mega-linter-runner@vx.y.z). Depends on npx, which ships with npm 7+, and | ||
Docker. Runs very slowly when the pertinent Docker image isn't already | ||
cached (c.f., https://github.com/marketplace/actions/docker-cache/). If you | ||
encounter permission errors, try running Docker in rootless mode (c.f., | ||
https://github.com/marketplace/actions/rootless-docker/). Linter results are | ||
logged to the report directory, so you should make sure to list it in your | ||
.gitignore and wipe it between runs. | ||
logged to the megalinter-reports directory, so list it in your .gitignore. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters