Skip to content

Commit b5b1d4f

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.
1 parent b2294dc commit b5b1d4f

5 files changed

Lines changed: 26 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
"rustfmt"
3838
]
3939
},
40+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
41+
"version": "4.5.1"
42+
},
4043
"./s-core-local": {}
4144
},
4245
"overrideFeatureInstallOrder": [
@@ -45,10 +48,10 @@
4548
"ghcr.io/devcontainers/features/common-utils",
4649
"ghcr.io/devcontainers-community/features/llvm",
4750
"ghcr.io/devcontainers/features/rust",
51+
"ghcr.io/devcontainers-extra/features/pre-commit",
4852
"./s-core-local"
4953
],
5054
"remoteUser": "vscode",
51-
5255
"customizations": {
5356
"vscode": {
5457
"extensions": [

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// The repos in S-CORE may use different Bazel versions. This ensures that the required version is installed.
99
// Should be removed once we provide versions of the devcontainer.
1010
"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"
11+
"Setup persistent bash history": "bash /devcontainer/features/s-core-local/setup_command_history.sh",
12+
"Enable pre-commit hooks": "bash /devcontainer/features/s-core-local/enable_pre_commit_hooks.sh"
1213
},
1314
"mounts": [
1415
{
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/test-project/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ check "validate cargo clippy is working and has the correct version" bash -c "ca
1919
check "validate rustfmt is working and has the correct version" bash -c "rustfmt --version | grep '1.8.0-stable'"
2020
check "validate rust-analyzer is working and has the correct version" bash -c "rust-analyzer --version | grep '1.83.0'"
2121

22+
# pre-commit, it is available via $PATH in login shells, but not in non-login shells
23+
check "validate pre-commit is working and has the correct version" bash -c "$PIPX_BIN_DIR/pre-commit --version | grep '4.5.1'"
24+
2225
# Tests from the local s-core-local feature
2326
source /devcontainer/features/s-core-local/tests/test_default.sh
2427

0 commit comments

Comments
 (0)