Skip to content

Commit d002850

Browse files
committed
feat(linter): add support for handling python linter conflicts
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 0002cd0 commit d002850

2 files changed

Lines changed: 82 additions & 24 deletions

File tree

.github/workflows/linter.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,17 @@ jobs:
8787
# See https://github.com/super-linter/super-linter.
8888
linter-env: ""
8989

90-
# Lint toolchain to use for Super-Linter frontend validators.
90+
# Lint toolchain to use for Super-Linter JavaScript and frontend validators.
9191
# Supported values: biome, eslint-prettier.
9292
#
9393
# Default: `biome`
94-
linter-toolchain: biome
94+
javascript-linter-toolchain: biome
95+
96+
# Lint toolchain to use for Super-Linter Python format validators.
97+
# Supported values: black, ruff-format.
98+
#
99+
# Default: `ruff-format`
100+
python-linter-toolchain: ruff-format
95101

96102
# JSON array of languages to analyze with CodeQL.
97103
# See https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/.
@@ -126,21 +132,23 @@ jobs:
126132
127133
### Workflow Call Inputs
128134
129-
| **Input** | **Description** | **Required** | **Type** | **Default** |
130-
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
131-
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
132-
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
133-
| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - |
134-
| | See <https://github.com/super-linter/super-linter>. | | | |
135-
| **`linter-toolchain`** | Lint toolchain to use for Super-Linter frontend validators. | **false** | **string** | `biome` |
136-
| | Supported values: biome, eslint-prettier. | | | |
137-
| **`codeql-languages`** | JSON array of languages to analyze with CodeQL. | **false** | **string** | `["actions"]` |
138-
| | See <https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/>. | | | |
139-
| | Leave empty to disable the check. | | | |
140-
| **`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 --> |
141-
| | Supports glob patterns. | | | |
142-
| | Leave empty to disable the check. | | | |
143-
| **`lint-all`** | Run checks on all files, not just the changed ones. | **false** | **boolean** | `${{ github.event_name != 'pull_request' }}` |
135+
| **Input** | **Description** | **Required** | **Type** | **Default** |
136+
| --------------------------------- | ----------------------------------------------------------------------------------------- | ------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
137+
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
138+
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
139+
| **`linter-env`** | Environment variables in multilines format "key=value" to pass to the linter. | **false** | **string** | - |
140+
| | See <https://github.com/super-linter/super-linter>. | | | |
141+
| **`javascript-linter-toolchain`** | Lint toolchain to use for Super-Linter JavaScript and frontend validators. | **false** | **string** | `biome` |
142+
| | Supported values: biome, eslint-prettier. | | | |
143+
| **`python-linter-toolchain`** | Lint toolchain to use for Super-Linter Python format validators. | **false** | **string** | `ruff-format` |
144+
| | Supported values: black, ruff-format. | | | |
145+
| **`codeql-languages`** | JSON array of languages to analyze with CodeQL. | **false** | **string** | `["actions"]` |
146+
| | See <https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/>. | | | |
147+
| | Leave empty to disable the check. | | | |
148+
| **`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 --> |
149+
| | Supports glob patterns. | | | |
150+
| | Leave empty to disable the check. | | | |
151+
| **`lint-all`** | Run checks on all files, not just the changed ones. | **false** | **boolean** | `${{ github.event_name != 'pull_request' }}` |
144152

145153
<!-- inputs:end -->
146154

.github/workflows/linter.yml

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ on:
2222
See https://github.com/super-linter/super-linter.
2323
type: string
2424
required: false
25-
linter-toolchain:
25+
javascript-linter-toolchain:
2626
description: |
27-
Lint toolchain to use for Super-Linter frontend validators.
27+
Lint toolchain to use for Super-Linter JavaScript and frontend validators.
2828
Supported values: biome, eslint-prettier.
2929
type: string
3030
required: false
3131
default: biome
32+
python-linter-toolchain:
33+
description: |
34+
Lint toolchain to use for Super-Linter Python format validators.
35+
Supported values: black, ruff-format.
36+
type: string
37+
required: false
38+
default: ruff-format
3239
codeql-languages:
3340
description: |
3441
JSON array of languages to analyze with CodeQL.
@@ -79,10 +86,11 @@ jobs:
7986
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
8087
env:
8188
LINTER_ENV: ${{ inputs.linter-env }}
82-
LINTER_TOOLCHAIN: ${{ inputs.linter-toolchain }}
89+
JAVASCRIPT_LINTER_TOOLCHAIN: ${{ inputs.javascript-linter-toolchain }}
90+
PYTHON_LINTER_TOOLCHAIN: ${{ inputs.python-linter-toolchain }}
8391
with:
8492
script: |
85-
const toolchainVariables = {
93+
const javascriptToolchainVariables = {
8694
biome: {
8795
VALIDATE_CSS: "false",
8896
VALIDATE_CSS_PRETTIER: "false",
@@ -108,6 +116,15 @@ jobs:
108116
},
109117
};
110118
119+
const pythonToolchainVariables = {
120+
black: {
121+
VALIDATE_PYTHON_RUFF_FORMAT: "false",
122+
},
123+
"ruff-format": {
124+
VALIDATE_PYTHON_BLACK: "false",
125+
},
126+
};
127+
111128
const defaultLinterVariables = {
112129
KUBERNETES_KUBECONFORM_OPTIONS:
113130
"-schema-location default -schema-location https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json",
@@ -139,15 +156,27 @@ jobs:
139156
return environment;
140157
}
141158
142-
function getToolchainEnvironment(toolchain) {
159+
function getToolchainEnvironment(toolchain, toolchainVariables, variableName) {
160+
if (toolchain === "") {
161+
return {};
162+
}
163+
143164
const environment = toolchainVariables[toolchain];
144165
if (!environment) {
145-
throw new Error(`Unsupported lint toolchain: ${toolchain}`);
166+
throw new Error(`Unsupported ${variableName}: ${toolchain}`);
146167
}
147168
148169
return environment;
149170
}
150171
172+
function resolveToolchain(customEnvironment, variableName, defaultValue) {
173+
if (customEnvironment.has(variableName)) {
174+
return customEnvironment.get(variableName) ?? "";
175+
}
176+
177+
return defaultValue;
178+
}
179+
151180
function mergeEnvironment(customEnvironment, defaultEnvironment) {
152181
const mergedEnvironment = new Map(customEnvironment);
153182
@@ -161,9 +190,30 @@ jobs:
161190
}
162191
163192
const customEnvironment = parseEnvironmentLines(process.env.LINTER_ENV ?? "");
193+
const javascriptToolchain = resolveToolchain(
194+
customEnvironment,
195+
"VALIDATE_JAVASCRIPT_TOOLCHAIN",
196+
process.env.JAVASCRIPT_LINTER_TOOLCHAIN ?? "",
197+
);
198+
const pythonToolchain = resolveToolchain(
199+
customEnvironment,
200+
"VALIDATE_PYTHON_TOOLCHAIN",
201+
process.env.PYTHON_LINTER_TOOLCHAIN ?? "",
202+
);
164203
const defaultEnvironment = {
165204
...defaultLinterVariables,
166-
...getToolchainEnvironment(process.env.LINTER_TOOLCHAIN),
205+
VALIDATE_JAVASCRIPT_TOOLCHAIN: javascriptToolchain,
206+
VALIDATE_PYTHON_TOOLCHAIN: pythonToolchain,
207+
...getToolchainEnvironment(
208+
javascriptToolchain,
209+
javascriptToolchainVariables,
210+
"VALIDATE_JAVASCRIPT_TOOLCHAIN",
211+
),
212+
...getToolchainEnvironment(
213+
pythonToolchain,
214+
pythonToolchainVariables,
215+
"VALIDATE_PYTHON_TOOLCHAIN",
216+
),
167217
};
168218
const mergedEnvironment = mergeEnvironment(customEnvironment, defaultEnvironment);
169219

0 commit comments

Comments
 (0)