oxsecurity / megalinter

🦙 MegaLinter analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.
https://megalinter.io
GNU Affero General Public License v3.0
1.81k stars 215 forks source link

devcontainer support #3485

Open robinmordasiewicz opened 2 months ago

robinmordasiewicz commented 2 months ago

We are using devcontainers and want to run megalinter from a pre-commit, but devcontainer mounts the workspace repo to a folder in the devcontainer at location "/workspace/reponame" but megalinter is not aware of this mount inside the devcontainer. Is there a way to run megalinter from a pre-commit hook within the devcontainer and pass in an environment variable with the original filesystem mount location ?

nvuillam commented 2 months ago

The .devcontainer file in MegaLinter is an inheritance from SuperLinter and i'm not sure it ever worked

It is possible to use MegaLinter as pre-commit ( @Kurt-von-Laven does it a lot ^^ ) , according to the documentation: https://megalinter.io/latest/mega-linter-runner/#pre-commit-hook

About devcontainer + pre-commit + env variable.... as i'm not a devcontainer user, I'm sorry but on my side I have no answer :(

rjaegers commented 2 months ago

I have written a bit of CMake code to run MegaLinter from within a devcontainer on code that is either mounted as a volume or bind mounted. The respective code can be found here: https://github.com/philips-software/amp-embedded-infra-lib/blob/main/cmake/emil_docker_tools.cmake. It should be fairly trivial to extract it to any type of language or scripting that you would like to use it in.

One detail: for the bind mount scenario you need to pass in an environment variable LOCAL_WORKSPACE_FOLDER in your devcontainer.json (I add this by default to all our devcontainers https://github.com/philips-software/amp-devcontainer).

"remoteEnv": {
      "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
    }
github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

nvuillam commented 1 month ago

@rjaegers would you like to update the .devcontainer of MegaLinter to see if it works ? :)

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.