Skip to content

Commit c912093

Browse files
chore: provide bazel-tools from devcontainer (#511)
1 parent 290bb1e commit c912093

5 files changed

Lines changed: 85 additions & 14 deletions

File tree

.pre-commit-config.yaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,26 @@ repos:
3535
language: system
3636
pass_filenames: false
3737
files: '(^|/)(MODULE\.bazel|.*\.bzl|BUILD(\.bazel)?)$'
38-
39-
- repo: https://github.com/rhysd/actionlint
40-
rev: v1.7.11
41-
hooks:
4238
- id: actionlint
43-
args:
44-
# Disable shellcheck and pyflakes for now, to enforce consistent behavior.
45-
- -shellcheck=
46-
- -pyflakes=
47-
48-
- repo: https://github.com/astral-sh/ruff-pre-commit
49-
rev: v0.15.9
50-
hooks:
39+
name: actionlint
40+
# Disable shellcheck and pyflakes for now, to enforce consistent behavior.
41+
entry: tools/run_tool.sh actionlint -shellcheck= -pyflakes=
42+
language: system
43+
require_serial: true
44+
types: [yaml]
45+
files: ^\.github/workflows/
5146
- id: ruff-check
52-
args: [ --fix ]
47+
name: ruff-check
48+
entry: tools/run_tool.sh ruff check --fix
49+
language: system
50+
require_serial: true
51+
types: [python]
5352
- id: ruff-format
53+
name: ruff-format
54+
entry: tools/run_tool.sh ruff format
55+
language: system
56+
require_serial: true
57+
types: [python]
5458

5559
# Note: this is super slow, therefore it is last
5660
- repo: local

BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ docs(
2626
],
2727
source_dir = "docs",
2828
)
29+
30+
# bazel run //:shellcheck
31+
alias(
32+
name = "shellcheck",
33+
actual = "@score_devcontainer//tools:shellcheck",
34+
)
35+
36+
# bazel run //:actionlint
37+
alias(
38+
name = "actionlint",
39+
actual = "@score_devcontainer//tools:actionlint",
40+
)

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ http_file(
7070
)
7171

7272
bazel_dep(name = "score_process", version = "1.5.4")
73+
74+
# Provide the tools from the devcontainer to Bazel
75+
bazel_dep(name = "score_devcontainer", version = "1.5.0")

MODULE.bazel.lock

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/run_tool.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# *******************************************************************************
4+
# Copyright (c) 2026 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+
16+
# Unified entry point for running a CLI tool by name.
17+
# Inside a container the tool is expected on PATH; outside, it is resolved via Bazel.
18+
# See https://github.com/eclipse-score/devcontainer/tree/main/tools for further information.
19+
20+
set -euo pipefail
21+
22+
if [[ "$#" -lt 1 ]]; then
23+
echo "Usage: $0 <tool> [args...]" >&2
24+
exit 2
25+
fi
26+
27+
tool_name="$1"
28+
shift
29+
30+
if { [[ -f /.dockerenv ]] || [[ -f /run/.containerenv ]] || [[ -d /devcontainer ]]; } &&
31+
command -v "${tool_name}" >/dev/null 2>&1; then
32+
exec "${tool_name}" "$@"
33+
elif command -v bazel >/dev/null 2>&1; then
34+
exec bazel run "@score_devcontainer//tools:${tool_name}" -- "$@"
35+
else
36+
echo "Could not run '${tool_name}': not available on PATH in a container, and bazel was not found." >&2
37+
exit 127
38+
fi

0 commit comments

Comments
 (0)