Skip to content

Commit 31ff8ee

Browse files
authored
add dependabot, devcontainer and make cr-checker usable via pre-commit hooks (#117)
1 parent bdff50c commit 31ff8ee

9 files changed

Lines changed: 194 additions & 3 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
# Use Dockerfile to get dependabot version bumps after new image is released
15+
FROM ghcr.io/eclipse-score/devcontainer:v1.2.0

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "eclipse-s-core",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"detachhead.basedpyright",
10+
"github.vscode-github-actions",
11+
"streetsidesoftware.code-spell-checker"
12+
]
13+
}
14+
}
15+
}

.github/dependabot.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
version: 2
14+
updates:
15+
- package-ecosystem: github-actions
16+
directory: /
17+
schedule:
18+
interval: daily
19+
groups:
20+
all-in-one:
21+
patterns:
22+
- "*"
23+
update-types:
24+
- "minor"
25+
- "patch"
26+
- package-ecosystem: pip
27+
directory: /
28+
schedule:
29+
interval: daily
30+
groups:
31+
all-in-one:
32+
patterns:
33+
- "*"
34+
update-types:
35+
- "minor"
36+
- "patch"
37+
- package-ecosystem: docker
38+
directory: /.devcontainer
39+
schedule:
40+
interval: daily
41+
groups:
42+
all-in-one:
43+
patterns:
44+
- "*"
45+
update-types:
46+
- "minor"
47+
- "patch"
48+
- package-ecosystem: bazel
49+
directory: /
50+
schedule:
51+
interval: daily
52+
groups:
53+
all-in-one:
54+
patterns:
55+
- "*"
56+
update-types:
57+
- "minor"
58+
- "patch"

.pre-commit-config.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # v6.0.0
16+
hooks:
17+
- id: check-yaml
18+
- id: end-of-file-fixer
19+
exclude: requirements_lock.txt
20+
- id: trailing-whitespace
21+
- id: check-shebang-scripts-are-executable
22+
- id: check-executables-have-shebangs
23+
- id: check-added-large-files
24+
args: [--maxkb=50, --enforce-all] # increase or add git lfs if too strict
25+
- repo: https://github.com/google/yamlfmt
26+
rev: 21ca5323a9c87ee37a434e0ca908efc0a89daa07 # v0.21.0
27+
hooks:
28+
- id: yamlfmt
29+
- repo: https://codeberg.org/fsfe/reuse-tool
30+
rev: a1bb792acda6fd0724936b4ebbdbc8eceb9c0459 # v6.2.0
31+
hooks:
32+
- id: reuse-lint-file
33+
- repo: local
34+
hooks:
35+
- id: copyright
36+
name: Check and fix copyright headers with cr_checker
37+
entry: cr_checker/tool/pre-commit_wrapper --extensions h hpp c cpp rs rst py sh bzl ini yml yaml BUILD bazel --fix
38+
# this would be the better language implementation, but struggle with python tooling
39+
# language: python
40+
language: unsupported_script
41+
minimum_pre_commit_version: 3.2.0
42+
types_or: [python, yaml, ini, rst, sh, shell, bash, bazel, c, c++, rust]

.pre-commit-hooks.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
- id: copyright
14+
name: Check and fix copyright headers with cr_checker
15+
entry: cr_checker/tool/pre-commit_wrapper --extensions h hpp c cpp rs rst py sh bzl ini yml yaml BUILD bazel --fix
16+
# this would be the better language implementation, but struggle with python tooling
17+
# language: python
18+
language: unsupported_script
19+
minimum_pre_commit_version: 3.2.0
20+
types_or: [python, yaml, ini, rst, sh, shell, bash, bazel, c, c++, rust]

cr_checker/resources/templates.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* SPDX-License-Identifier: Apache-2.0
2525
********************************************************************************/
26-
[py,sh,bzl,ini,yml,BUILD,bazel]
26+
[py,sh,bzl,ini,yml,yaml,BUILD,bazel]
2727
# *******************************************************************************
2828
# Copyright (c) {year} {author}
2929
#
@@ -52,7 +52,7 @@
5252
# *******************************************************************************
5353
[rs]
5454
// *******************************************************************************
55-
// Copyright (c) {year} Contributors to the Eclipse Foundation
55+
// Copyright (c) {year} {author}
5656
//
5757
// See the NOTICE file(s) distributed with this work for additional
5858
// information regarding copyright ownership.

cr_checker/tests/test_cr_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_detect_shebang_offset_counts_trailing_newlines(tmp_path):
7373
"bzl",
7474
"ini",
7575
"yml",
76+
"yaml",
7677
"BUILD",
7778
"bazel",
7879
"rs",
@@ -103,6 +104,7 @@ def prepare_test_with_header(request: SubRequest, tmp_path: PosixPath) -> tuple:
103104
"bzl",
104105
"ini",
105106
"yml",
107+
"yaml",
106108
"BUILD",
107109
"bazel",
108110
"rs",

cr_checker/tool/cr_checker.py

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
# *******************************************************************************
24
# Copyright (c) 2024 Contributors to the Eclipse Foundation
35
#
@@ -504,7 +506,9 @@ def fix_copyright(path, copyright_text, encoding, offset, config=None) -> bool:
504506
byte_array = len(first_line.encode(encoding))
505507

506508
if offset > 0 and offset != byte_array:
507-
LOGGER.error("Invalid offset value: %d, expected: %d", offset, byte_array)
509+
LOGGER.error(
510+
"%s: Invalid offset value: %d, expected: %d", path, offset, byte_array
511+
)
508512
return False
509513

510514
with open(path, "w", encoding=encoding) as handle:

cr_checker/tool/pre-commit_wrapper

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
# *******************************************************************************
4+
# Copyright (c) 2024 Contributors to the Eclipse Foundation
5+
#
6+
# See the NOTICE file(s) distributed with this work for additional
7+
# information regarding copyright ownership.
8+
#
9+
# This program and the accompanying materials are made available under the
10+
# terms of the Apache License Version 2.0 which is available at
11+
# https://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
# *******************************************************************************
15+
"""The tool for checking if artifacts have proper copyright."""
16+
17+
import cr_checker
18+
import os
19+
import sys
20+
21+
if __name__ == "__main__":
22+
# --template-file and --config-file cannot be set via .pre-commit-config.yaml
23+
script_dir = os.path.dirname(os.path.abspath(__file__))
24+
sys.argv.insert(1, '--template-file')
25+
sys.argv.insert(
26+
2,
27+
os.path.normpath(os.path.join(script_dir, '..', 'resources', 'templates.ini')),
28+
)
29+
sys.argv.insert(3, '--config-file')
30+
sys.argv.insert(
31+
4,
32+
os.path.normpath(os.path.join(script_dir, '..', 'resources', 'config.json')),
33+
)
34+
35+
sys.exit(cr_checker.main(sys.argv[1:]))

0 commit comments

Comments
 (0)