Skip to content

Commit 895fa8d

Browse files
committed
Use venv for pre-commit in CI instead of pip install
The CI creates a venv via python_venv setup step that has pre-commit installed from requirements.txt. Activate this venv instead of trying to install pre-commit via pip which creates PATH issues.
1 parent b3f3800 commit 895fa8d

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,8 @@ repos:
228228

229229
- id: regenerate-multicluster-rbac
230230
name: Regenerate multi-cluster RBAC samples
231-
entry: bash
232-
args:
233-
- -c
234-
- |
235-
cd pkg/kubectl-mongodb/common && \
236-
EXPORT_RBAC_SAMPLES=true go test ./... -run TestPrintingOutRolesServiceAccountsAndRoleBindings && \
237-
git add ../../../public/samples/multi-cluster-cli-gitops
238-
language: system
231+
entry: scripts/dev/regenerate_multicluster_rbac.sh
232+
language: script
239233
files: ^(cmd/kubectl-mongodb|pkg/kubectl-mongodb)/
240234
pass_filenames: false
241235

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -Eeou pipefail
3+
4+
# Source the environment context to get go in PATH
5+
# shellcheck disable=SC1091
6+
source scripts/dev/set_env_context.sh
7+
8+
echo "Regenerating multi-cluster RBAC samples"
9+
cd pkg/kubectl-mongodb/common
10+
EXPORT_RBAC_SAMPLES=true go test ./... -run TestPrintingOutRolesServiceAccountsAndRoleBindings
11+
git add ../../../public/samples/multi-cluster-cli-gitops

scripts/evergreen/check_precommit.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ initial_index_state=$(git diff --name-only --cached --diff-filter=AM)
66

77
export EVERGREEN_MODE=true
88

9-
# Install pre-commit if not available
10-
if ! command -v pre-commit >/dev/null 2>&1; then
11-
echo "Installing pre-commit..."
12-
pip install pre-commit
13-
# Add ~/.local/bin to PATH if it exists (pip installs scripts there)
14-
if [[ -d "${HOME}/.local/bin" ]]; then
15-
export PATH="${HOME}/.local/bin:${PATH}"
16-
fi
9+
# Source the environment context (sets up PATH for go, etc.)
10+
# This is created by clone->setup_context step in CI
11+
# shellcheck disable=SC1091
12+
source scripts/dev/set_env_context.sh
13+
14+
# Activate the venv if it exists (CI creates this via python_venv setup step)
15+
# The venv contains pre-commit installed from requirements.txt
16+
if [[ -f "${PROJECT_DIR}/venv/bin/activate" ]]; then
17+
echo "Activating venv..."
18+
# shellcheck disable=SC1091
19+
source "${PROJECT_DIR}/venv/bin/activate"
1720
fi
1821

22+
# pre-commit should now be available from the venv
1923
echo "Running pre-commit hooks..."
2024
echo "pre-commit version: $(pre-commit --version)"
2125

scripts/evergreen/lint_code.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -Eeou pipefail
33

4+
# Source the environment context to get go in PATH
5+
# shellcheck disable=SC1091
6+
source scripts/dev/set_env_context.sh
7+
48
# Set required version
59
required_version="v2.0.2"
610

0 commit comments

Comments
 (0)