Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions .github/workflows/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ jobs:
# See https://github.com/super-linter/super-linter.
linter-env: ""

# Lint toolchain to use for Super-Linter frontend validators.
# Lint toolchain to use for Super-Linter JavaScript and frontend validators.
# Supported values: biome, eslint-prettier.
#
# Default: `biome`
linter-toolchain: biome
javascript-linter-toolchain: biome

# Lint toolchain to use for Super-Linter Python format validators.
# Supported values: black, ruff-format.
#
# Default: `ruff-format`
python-linter-toolchain: ruff-format

# JSON array of languages to analyze with CodeQL.
# See https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/.
Expand Down Expand Up @@ -126,21 +132,23 @@ jobs:

### Workflow Call Inputs

| **Input** | **Description** | **Required** | **Type** | **Default** |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - |
| | See <https://github.com/super-linter/super-linter>. | | | |
| **`linter-toolchain`** | Lint toolchain to use for Super-Linter frontend validators. | **false** | **string** | `biome` |
| | Supported values: biome, eslint-prettier. | | | |
| **`codeql-languages`** | JSON array of languages to analyze with CodeQL. | **false** | **string** | `["actions"]` |
| | See <https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/>. | | | |
| | Leave empty to disable the check. | | | |
| **`action-files`** | List of files or directories where GitHub Actions and workflows are located. | **false** | **string** | <!-- textlint-disable --><pre lang="text">./action.yml&#13;./.github/workflows/\*\*/\*.yml&#13;./actions/\*\*/\*.yml</pre><!-- textlint-enable --> |
| | Supports glob patterns. | | | |
| | Leave empty to disable the check. | | | |
| **`lint-all`** | Run checks on all files, not just the changed ones. | **false** | **boolean** | `${{ github.event_name != 'pull_request' }}` |
| **Input** | **Description** | **Required** | **Type** | **Default** |
| --------------------------------- | ----------------------------------------------------------------------------------------- | ------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - |
| | See <https://github.com/super-linter/super-linter>. | | | |
| **`javascript-linter-toolchain`** | Lint toolchain to use for Super-Linter JavaScript and frontend validators. | **false** | **string** | `biome` |
| | Supported values: biome, eslint-prettier. | | | |
| **`python-linter-toolchain`** | Lint toolchain to use for Super-Linter Python format validators. | **false** | **string** | `ruff-format` |
| | Supported values: black, ruff-format. | | | |
| **`codeql-languages`** | JSON array of languages to analyze with CodeQL. | **false** | **string** | `["actions"]` |
| | See <https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/>. | | | |
| | Leave empty to disable the check. | | | |
| **`action-files`** | List of files or directories where GitHub Actions and workflows are located. | **false** | **string** | <!-- textlint-disable --><pre lang="text">./action.yml&#13;./.github/workflows/\*\*/\*.yml&#13;./actions/\*\*/\*.yml</pre><!-- textlint-enable --> |
| | Supports glob patterns. | | | |
| | Leave empty to disable the check. | | | |
| **`lint-all`** | Run checks on all files, not just the changed ones. | **false** | **boolean** | `${{ github.event_name != 'pull_request' }}` |

<!-- inputs:end -->

Expand Down
64 changes: 57 additions & 7 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ on:
See https://github.com/super-linter/super-linter.
type: string
required: false
linter-toolchain:
javascript-linter-toolchain:
description: |
Lint toolchain to use for Super-Linter frontend validators.
Lint toolchain to use for Super-Linter JavaScript and frontend validators.
Supported values: biome, eslint-prettier.
type: string
required: false
default: biome
python-linter-toolchain:
description: |
Lint toolchain to use for Super-Linter Python format validators.
Supported values: black, ruff-format.
type: string
required: false
default: ruff-format
codeql-languages:
description: |
JSON array of languages to analyze with CodeQL.
Expand Down Expand Up @@ -79,10 +86,11 @@ jobs:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
LINTER_ENV: ${{ inputs.linter-env }}
LINTER_TOOLCHAIN: ${{ inputs.linter-toolchain }}
JAVASCRIPT_LINTER_TOOLCHAIN: ${{ inputs.javascript-linter-toolchain }}
PYTHON_LINTER_TOOLCHAIN: ${{ inputs.python-linter-toolchain }}
with:
script: |
const toolchainVariables = {
const javascriptToolchainVariables = {
biome: {
VALIDATE_CSS: "false",
VALIDATE_CSS_PRETTIER: "false",
Expand All @@ -108,6 +116,15 @@ jobs:
},
};

const pythonToolchainVariables = {
black: {
VALIDATE_PYTHON_RUFF_FORMAT: "false",
},
"ruff-format": {
VALIDATE_PYTHON_BLACK: "false",
},
};

const defaultLinterVariables = {
KUBERNETES_KUBECONFORM_OPTIONS:
"-schema-location default -schema-location https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json",
Expand Down Expand Up @@ -139,15 +156,27 @@ jobs:
return environment;
}

function getToolchainEnvironment(toolchain) {
function getToolchainEnvironment(toolchain, toolchainVariables, variableName) {
if (toolchain === "") {
return {};
}

const environment = toolchainVariables[toolchain];
if (!environment) {
throw new Error(`Unsupported lint toolchain: ${toolchain}`);
throw new Error(`Unsupported ${variableName}: ${toolchain}`);
}

return environment;
}

function resolveToolchain(customEnvironment, variableName, defaultValue) {
if (customEnvironment.has(variableName)) {
return customEnvironment.get(variableName) ?? "";
}

return defaultValue;
}

function mergeEnvironment(customEnvironment, defaultEnvironment) {
const mergedEnvironment = new Map(customEnvironment);

Expand All @@ -161,9 +190,30 @@ jobs:
}

const customEnvironment = parseEnvironmentLines(process.env.LINTER_ENV ?? "");
const javascriptToolchain = resolveToolchain(
customEnvironment,
"VALIDATE_JAVASCRIPT_TOOLCHAIN",
process.env.JAVASCRIPT_LINTER_TOOLCHAIN ?? "",
);
const pythonToolchain = resolveToolchain(
customEnvironment,
"VALIDATE_PYTHON_TOOLCHAIN",
process.env.PYTHON_LINTER_TOOLCHAIN ?? "",
);
const defaultEnvironment = {
...defaultLinterVariables,
...getToolchainEnvironment(process.env.LINTER_TOOLCHAIN),
VALIDATE_JAVASCRIPT_TOOLCHAIN: javascriptToolchain,
VALIDATE_PYTHON_TOOLCHAIN: pythonToolchain,
...getToolchainEnvironment(
javascriptToolchain,
javascriptToolchainVariables,
"VALIDATE_JAVASCRIPT_TOOLCHAIN",
),
...getToolchainEnvironment(
pythonToolchain,
pythonToolchainVariables,
"VALIDATE_PYTHON_TOOLCHAIN",
),
};
const mergedEnvironment = mergeEnvironment(customEnvironment, defaultEnvironment);

Expand Down
Loading