diff --git a/.github/workflows/linter.md b/.github/workflows/linter.md index f75aa9a..6e832b6 100644 --- a/.github/workflows/linter.md +++ b/.github/workflows/linter.md @@ -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/. @@ -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 . | | | | -| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - | -| | See . | | | | -| **`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 . | | | | -| | Leave empty to disable the check. | | | | -| **`action-files`** | List of files or directories where GitHub Actions and workflows are located. | **false** | **string** |
./action.yml
./.github/workflows/\*\*/\*.yml
./actions/\*\*/\*.yml
| -| | 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 . | | | | +| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - | +| | See . | | | | +| **`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 . | | | | +| | Leave empty to disable the check. | | | | +| **`action-files`** | List of files or directories where GitHub Actions and workflows are located. | **false** | **string** |
./action.yml
./.github/workflows/\*\*/\*.yml
./actions/\*\*/\*.yml
| +| | 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' }}` | diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b648460..2919da3 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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. @@ -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", @@ -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", @@ -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); @@ -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);