2023-12-11 16:35:20 -05:00
# Run super-linter outside GitHub Actions
2020-07-21 13:08:05 -04:00
2023-12-11 16:35:20 -05:00
If you want to run super-linter outside GitHub Actions, you need a container
runtime engine to run the super-linter container image.
2020-07-21 13:08:05 -04:00
2023-12-11 16:35:20 -05:00
## Run super-linter Locally
2023-11-30 03:42:05 -05:00
2024-09-13 08:37:48 -04:00
You can run the container locally with the following configuration options to
run your code:
2023-11-30 03:42:05 -05:00
```bash
docker run \
2024-02-20 12:27:06 -05:00
-e LOG_LEVEL=DEBUG \
2023-11-30 03:42:05 -05:00
-e RUN_LOCAL=true \
-v /path/to/local/codebase:/tmp/lint \
2023-12-11 16:35:20 -05:00
--rm \
2023-11-30 03:42:05 -05:00
ghcr.io/super-linter/super-linter:latest
```
2024-09-13 08:37:48 -04:00
This example uses the `latest` container image version. If you're trying to
reproduce an issue, or running super-linter as part of your CI pipeline, we
recommend that you **refer to a specific version instead** .
2020-05-14 10:24:23 -04:00
2023-11-30 03:42:05 -05:00
Notes:
2020-07-21 13:08:05 -04:00
2024-09-13 08:37:48 -04:00
- To run against a single file you can use:
`docker run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true -v /path/to/local/codebase/file:/tmp/lint/file ghcr.io/super-linter/super-linter`
- You need to pass the `RUN_LOCAL` option to bypass some of the GitHub Actions
checks, as well as the mapping of your local codebase to `/tmp/lint` .
- If you want to override the `/tmp/lint` folder, you can set the
`DEFAULT_WORKSPACE` environment variable to point to the folder you'd prefer
to scan.
- You can add as many configuration options as needed. Configuration options are
documented in the [readme ](../README.md#configure-super-linter ).
2020-01-09 10:48:46 -05:00
2023-12-11 16:35:20 -05:00
### GitLab
2022-09-27 13:05:38 -04:00
2024-05-23 20:52:33 -04:00
To run Super-linter in your GitLab CI/CD pipeline, You can use the following
snippet:
```yaml
super-linter:
# More info at https://github.com/super-linter/super-linter
stage: Super-linter
# Use a specific Super-linter version instead of latest for more reproducible builds
image: super-linter/super-linter:latest
2024-08-15 04:21:26 -04:00
script: ["true"]
2024-05-23 20:52:33 -04:00
variables:
RUN_LOCAL: "true"
DEFAULT_WORKSPACE: $CI_PROJECT_DIR
```
Note that this is a high-level example that you should customize for your needs.
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
### Run on Codespaces and Visual Studio Code
2022-09-27 13:05:38 -04:00
2024-09-13 08:37:48 -04:00
This repository provides a DevContainer for
[remote development ](https://code.visualstudio.com/docs/remote/containers ).
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
## Share Environment variables between environments
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
To avoid duplication if you run super-linter both locally and in other
environements, such as CI, you can define configuration options once, and load
them accordingly:
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
1. Create a configuration file for super-linter `super-linter.env` . For example:
2022-09-27 13:05:38 -04:00
2024-08-15 04:21:26 -04:00
```bash
VALIDATE_ALL_CODEBASE=true
```
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
1. Load the super-linter configuration file when running outside GitHub Actions:
2022-09-27 13:05:38 -04:00
2024-08-15 04:21:26 -04:00
```bash
docker run --rm \
-e RUN_LOCAL=true \
--env-file ".github/super-linter.env" \
-v "$(pwd)":/tmp/lint \
ghcr.io/super-linter/super-linter:latest
```
2022-09-27 13:05:38 -04:00
2023-12-11 16:35:20 -05:00
1. Load the super-linter configuration file when running in GitHub Actions by
2024-08-15 04:21:26 -04:00
adding the following step to the GitHub Actions workflow that runs
super-linter, after checking out your repository and before running
super-linter:
2022-09-27 13:05:38 -04:00
2024-08-15 04:21:26 -04:00
```yaml
- name: Load super-linter configuration
2024-08-30 06:03:08 -04:00
# Use grep inverse matching to exclude eventual comments in the .env file
# because the GitHub Actions command to set environment variables doesn't
# support comments.
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
run: grep -v '^#' .github/super-linter.env >> "$GITHUB_ENV"
2024-08-15 04:21:26 -04:00
```
2022-09-27 13:05:38 -04:00
2023-10-19 17:03:14 -04:00
## Build the container image and run the test suite locally
2024-06-19 04:23:21 -04:00
To run the build and test process locally, in the top-level super-linter
directory, do the following:
2023-10-19 17:03:14 -04:00
2023-12-12 13:53:48 -05:00
1. [Create a fine-grained GitHub personal access token ](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token ).
2024-08-15 04:21:26 -04:00
The token only needs to have public/read-only access.
2024-06-19 04:23:21 -04:00
1. Store the generated personal access token in a file in the top-level
2024-08-15 04:21:26 -04:00
directory (This file is ignored by Git).
2023-12-12 13:53:48 -05:00
2024-08-15 04:21:26 -04:00
```bash
echo "github_pat_XXXXXX_XXXXXX" > .github-personal-access-token
```
2023-12-12 13:53:48 -05:00
1. Run the build process:
2024-08-15 04:21:26 -04:00
```bash
. ./scripts/build-metadata.sh & & make
```
2023-12-12 13:53:48 -05:00
2024-08-13 06:10:31 -04:00
To avoid invalidating the build cache because of changing values of build
arguments, you can set build arguments to arbitrary values before running
`make` , instead of sourcing `scripts/build-metadata.sh` :
2023-12-12 13:53:48 -05:00
```bash
BUILD_DATE=2023-12-12T09:32:05Z \
BUILD_REVISION=83c16f63caa9d432df4519efb4c58a56e2190bd6 \
BUILD_VERSION=83c16f63caa9d432df4519efb4c58a56e2190bd6 \
2023-10-19 17:03:14 -04:00
make
```
### Run the test suite against an arbitrary super-linter container image
You can run the test suite against an arbitrary super-linter container image.
2024-09-13 08:37:48 -04:00
Here is an example that runs the test suite against the `v5.4.3` container image
version.
2023-10-19 17:03:14 -04:00
```shell
CONTAINER_IMAGE_ID="ghcr.io/super-linter/super-linter:v5.4.3" \
2023-12-12 13:53:48 -05:00
BUILD_DATE="2023-10-17T17:00:53Z" \
2023-12-07 09:18:47 -05:00
BUILD_REVISION=b0d1acee1f8050d1684a28ddbf8315f81d084fe9 \
BUILD_VERSION=b0d1acee1f8050d1684a28ddbf8315f81d084fe9 \
2023-10-19 17:03:14 -04:00
make docker-pull test
```
2023-12-07 09:18:47 -05:00
Initialize the `BUILD_DATE` , `BUILD_REVISION` , and `BUILD_VERSION` variables
with the values for that specific container image version. You can get these
values from the build log for that version.
2023-12-11 16:35:20 -05:00
### Get the list of available build targets
2020-01-09 10:48:46 -05:00
2023-12-11 16:35:20 -05:00
To get the list of the available `Make` targets, run the following command:
2020-07-21 13:08:05 -04:00
2023-12-11 16:35:20 -05:00
```shell
make help
```
2024-08-07 09:36:16 -04:00
### Automatically fix formatting and linting issues
To automatically fix linting and formatting issues when supported, run the
following command:
```shell
make fix-codebase
```