Skip to content

Commit 880d1ae

Browse files
committed
chore(ci): modernize pre-commit hooks, bump Python to 3.11
1 parent 28814b9 commit 880d1ae

10 files changed

Lines changed: 108 additions & 18 deletions

File tree

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ updates:
1616
prefix: "deps/gha"
1717
target-branch: "dev"
1818

19+
# npm (Prettier tooling)
20+
- package-ecosystem: "npm"
21+
directory: "/"
22+
schedule:
23+
interval: "daily"
24+
time: "09:00"
25+
timezone: "Europe/Paris"
26+
assignees:
27+
- "TheophileDiot"
28+
reviewers:
29+
- "TheophileDiot"
30+
commit-message:
31+
prefix: "deps/npm"
32+
target-branch: "dev"
33+
1934
# Coraza
2035
- package-ecosystem: "docker"
2136
directory: "/coraza/api"

.github/workflows/tests.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Set up Python
5454
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
5555
with:
56-
python-version: "3.9"
56+
python-version: "3.11"
5757
- name: Install pre-commit
5858
run: pip install pre-commit
5959
- name: Install Lua toolchain
@@ -62,6 +62,15 @@ jobs:
6262
run: |
6363
sudo apt-get update
6464
sudo apt-get install -y lua5.4 liblua5.4-dev luarocks
65+
- name: Set up Node
66+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
67+
with:
68+
node-version: "22"
69+
cache: "npm"
70+
- name: Install Prettier
71+
# The prettier hook is language:system and resolves prettier from the
72+
# repo's pinned package-lock.json via npx.
73+
run: npm ci
6574
- name: Run pre-commit
6675
run: pre-commit run --all-files
6776

@@ -95,7 +104,7 @@ jobs:
95104
if: matrix.lang == 'python'
96105
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
97106
with:
98-
python-version: "3.9"
107+
python-version: "3.11"
99108
- name: Run Python unit tests
100109
if: matrix.lang == 'python'
101110
run: |

.pre-commit-config.yaml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3-
exclude: (^coraza/api/coreruleset|(^LICENSE.md|.svg)$)
3+
exclude: (^coraza/api/coreruleset|^package-lock\.json$|(^LICENSE.md|.svg)$)
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
6+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
77
hooks:
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
1010
- id: check-yaml
1111
args: ["--allow-multiple-documents"]
1212
- id: check-case-conflict
1313

14-
- repo: https://github.com/ambv/black
15-
rev: 3702ba224ecffbcec30af640c149f231d90aebdb # frozen: 24.4.2
14+
- repo: https://github.com/psf/black
15+
rev: 87928e6d6761a4a6d22250e1fee5601b3998086e # frozen: 26.5.1
1616
hooks:
1717
- id: black
1818
name: Black Python Formatter
19-
language_version: python3.9
19+
language_version: python3.11
2020

21-
- repo: https://github.com/pre-commit/mirrors-prettier
22-
rev: ffb6a759a979008c0e6dff86e39f4745a2d9eac4 # frozen: v3.1.0
21+
- repo: local
2322
hooks:
2423
- id: prettier
2524
name: Prettier Code Formatter
25+
# Uses the pinned prettier from the repo's package.json / package-lock.json
26+
# (installed via `npm ci`); npx resolves the local node_modules/.bin binary.
27+
entry: npx prettier --write
28+
language: system
29+
types: [text]
30+
files: \.(js|ts|jsx|tsx|css|less|html|json|markdown|md|yaml|yml)$
2631

2732
- repo: https://github.com/JohnnyMorganz/StyLua
28-
rev: 84c370104d6a8d1eef00c80a3ebd42f7033aaaad # frozen: v0.20.0
33+
rev: a6433cd8ed974a1dd769d41a46b5008858e58e94 # frozen: v2.5.2
2934
hooks:
3035
- id: stylua-github
3136

@@ -36,14 +41,22 @@ repos:
3641
args: ["--std", "min", "--codes", "--ranges", "--no-cache"]
3742

3843
- repo: https://github.com/pycqa/flake8
39-
rev: 1978e2b0de6efa0cb2a2b6f3f7986aa6569dd2be # frozen: 7.1.0
44+
rev: d93590f5be797aabb60e3b09f2f52dddb02f349f # frozen: 7.3.0
4045
hooks:
4146
- id: flake8
4247
name: Flake8 Python Linter
43-
args: ["--max-line-length=250", "--ignore=E266,E402,E722,W503"]
48+
args: ["--max-line-length=160", "--ignore=E266,E402,E501,E722,W503"]
49+
50+
- repo: https://github.com/dosisod/refurb
51+
rev: 0dbb127465ca9398b6c89c32a7fd86d78ca755c4 # frozen: v2.3.1
52+
hooks:
53+
- id: refurb
54+
name: Refurb Python Refactoring Tool
55+
exclude: ^tests/
56+
additional_dependencies: ["mypy<1.20"]
4457

4558
- repo: https://github.com/codespell-project/codespell
46-
rev: 193cd7d27cd571f79358af09a8fb8997e54f8fff # frozen: v2.3.0
59+
rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2
4760
hooks:
4861
- id: codespell
4962
name: Codespell Spell Checker
@@ -52,11 +65,11 @@ repos:
5265
types: [text]
5366

5467
- repo: https://github.com/gitleaks/gitleaks
55-
rev: 77c3c6a34b2577d71083442326c60b8fd58926ec # frozen: v8.18.4
68+
rev: 2ca41cc1372d1e939a6a879f18cdc19fc1cac1ce # frozen: v8.30.0
5669
hooks:
5770
- id: gitleaks
5871

5972
- repo: https://github.com/koalaman/shellcheck-precommit
60-
rev: 2491238703a5d3415bb2b7ff11388bf775372f29 # frozen: v0.10.0
73+
rev: 99470f5e12208ff0fb17ab81c3c494f7620a1d8d # frozen: v0.11.0
6174
hooks:
6275
- id: shellcheck

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
package-lock.json
3+
LICENSE.md
4+
coraza/api/coreruleset/

.tests/build-push.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC1091
34
. .tests/utils.sh
45

56
echo "ℹ️ Build bunkerweb-coraza ..."

.tests/cloudflare/cf-api-mock/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ def sign_csr(csr_pem: str) -> str:
6464
builder = builder.add_extension(san.value, critical=False)
6565
except x509.ExtensionNotFound:
6666
pass
67-
cert = builder.sign(_ca_key, hashes.SHA256())
68-
return cert.public_bytes(serialization.Encoding.PEM).decode()
67+
return builder.sign(_ca_key, hashes.SHA256()).public_bytes(serialization.Encoding.PEM).decode()
6968

7069

7170
def envelope(result):

.tests/misc/json2md.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def stream_support(support) -> str:
4444
if len(core_plugin["settings"]) > 0:
4545
core_settings[core_plugin["name"]] = core_plugin
4646

47-
for name, data in dict(sorted(core_settings.items())).items():
47+
for data in dict(sorted(core_settings.items())).values():
4848
print(f"### {data['name']}\n", file=doc)
4949
print(f"{stream_support(data['stream'])}\n", file=doc)
5050
print(f"{data['description']}\n", file=doc)

package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "bunkerweb-plugins",
3+
"version": "1.0.0",
4+
"description": "Tooling dependencies (code formatting) for the BunkerWeb external plugins repository",
5+
"private": true,
6+
"scripts": {
7+
"format": "prettier --write .",
8+
"format:check": "prettier --check ."
9+
},
10+
"devDependencies": {
11+
"prettier": "3.8.4"
12+
}
13+
}

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ exclude = '''
1414
| env
1515
)/
1616
'''
17+
18+
[tool.refurb]
19+
# FURB124 rewrites `a == "yes" and b == "yes"` into a chained `a == "yes" == b`,
20+
# which reads as "a and b equal each other" and hurts clarity in the CF env-gate logic.
21+
ignore = ["FURB124"]

0 commit comments

Comments
 (0)