Skip to content

Commit b0ec723

Browse files
committed
Add pre-commit feature to devcontainer
It supports to spot easy to detect issues before committing code and reduce the number of failed CI runs and review cycles. Ensure the S-CORE depends on the pre-commit feature so that it is always because it installs scripts using it.
1 parent b2294dc commit b0ec723

5 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎src/s-core-devcontainer/.devcontainer/devcontainer-lock.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"resolved": "ghcr.io/devcontainers-community/features/llvm@sha256:4f464ab97a59439286a55490b55ba9851616f6f76ac3025e134127ac08ad79e2",
66
"integrity": "sha256:4f464ab97a59439286a55490b55ba9851616f6f76ac3025e134127ac08ad79e2"
77
},
8+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
9+
"version": "2.0.18",
10+
"resolved": "ghcr.io/devcontainers-extra/features/pre-commit@sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e",
11+
"integrity": "sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e"
12+
},
813
"ghcr.io/devcontainers/features/common-utils": {
914
"version": "2.5.4",
1015
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:00fd45550f578d9d515044d9e2226e908dbc3d7aa6fcb9dee4d8bdb60be114cf",

‎src/s-core-devcontainer/.devcontainer/devcontainer.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"./s-core-local"
4949
],
5050
"remoteUser": "vscode",
51-
5251
"customizations": {
5352
"vscode": {
5453
"extensions": [

‎src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
"id": "s-core-local",
44
"version": "1.0.0",
55
"description": "Tools which are not available as already existing development container feature",
6+
"dependsOn": {
7+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
8+
"version": "4.5.1"
9+
}
10+
},
611
"onCreateCommand": "/devcontainer/features/s-core-local/on_create_command.sh",
712
"postCreateCommand": {
813
// The repos in S-CORE may use different Bazel versions. This ensures that the required version is installed.
914
// Should be removed once we provide versions of the devcontainer.
1015
"Install matching Bazel version": "bash /devcontainer/features/s-core-local/install_matching_bazel_version.sh",
11-
"Setup persistent bash history": "bash /devcontainer/features/s-core-local/setup_command_history.sh"
16+
"Setup persistent bash history": "bash /devcontainer/features/s-core-local/setup_command_history.sh",
17+
"Enable pre-commit hooks": "bash /devcontainer/features/s-core-local/enable_pre_commit_hooks.sh"
1218
},
1319
"mounts": [
1420
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
PRE_COMMIT_CONFIG_FILE=".pre-commit-config.yaml"
4+
5+
if [[ -f "${PRE_COMMIT_CONFIG_FILE}" ]]
6+
then
7+
echo "Pre-commit configuration found (${PRE_COMMIT_CONFIG_FILE})"
8+
$PIPX_BIN_DIR/pre-commit install
9+
else
10+
echo "No pre-commit configuration found (${PRE_COMMIT_CONFIG_FILE})"
11+
echo "Skipping pre-commit hook's installation"
12+
fi

‎src/s-core-devcontainer/.devcontainer/s-core-local/tests/test_default.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -euo pipefail
44
# Read tool versions + metadata into environment variables
55
. /devcontainer/features/s-core-local/versions.sh
66

7+
# pre-commit, it is available via $PATH in login shells, but not in non-login shells
8+
check "validate pre-commit is working and has the correct version" bash -c "$PIPX_BIN_DIR/pre-commit --version | grep '4.5.1'"
9+
710
# Common tooling
811
# For an unknown reason, dot -V reports on Ubuntu Noble a version 2.43.0, while the package has a different version.
912
# Hence, we have to work around that.

0 commit comments

Comments
 (0)