Skip to content

Commit a6a2c8a

Browse files
authored
chore(devcontainer): sync standard SCORE tool launcher (#512)
<!-- ---------------------------------------------------------------------------- Copyright (c) 2026 Contributors to the Eclipse Foundation See the NOTICE file(s) distributed with this work for additional information regarding copyright ownership. This program and the accompanying materials are made available under the terms of the Apache License Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0 SPDX-License-Identifier: Apache-2.0 ----------------------------------------------------------------------------- --> ## Policy **`score-devcontainer-run-tool`** Keep the SCORE devcontainer tool launcher in sync with the version maintained by eclipse-score/devcontainer and identify its policy-managed source for consumer repositories. ## Why this repository? This repository matches this policy because `MODULE.bazel` exists and the policy value `devcontainer_version` is available because `.devcontainer/Dockerfile` contains exactly one `ghcr.io/eclipse-score/devcontainer:vX.Y.Z` FROM instruction. ## Changes - `.devcontainer/run-tool`: synchronize file - Keep the launcher current and direct local edits to its source asset. ## Tool revision Generated from [eclipse-score/tools](https://github.com/eclipse-score/tools) at commit `9025965`. --- This pull request is managed by SCORE Repository Policy Sync and may be updated by a later policy run. Please report any issues to [#score-infrastructure](https://sdvworkinggroup.slack.com/archives/C0894QGRZDM). > [!NOTE] > This pull request is generated automatically. Review the proposed changes > before merging. <!-- repo-policy-sync-policy: score-devcontainer-run-tool --> <!-- repo-policy-sync-head: a7b8b59 --> <!-- repo-policy-sync-generation: 9025965 -->
2 parents 8b162e3 + a7b8b59 commit a6a2c8a

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

‎.devcontainer/run-tool‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
# This copy is managed by repo_policy_sync in eclipse-score/tools.
17+
# Please do not edit this copy; update the score-devcontainer-run-tool policy asset.
18+
# Consumer repositories install this runner as .devcontainer/run-tool.
19+
# It runs a pinned CLI tool from PATH in a container, from local PATH on the host
20+
# when available, or through Bazel otherwise.
21+
# Use --strict to bypass local tools on the host and force execution through Bazel.
22+
# See https://github.com/eclipse-score/devcontainer/tree/main/tools.
23+
24+
set -euo pipefail
25+
26+
strict=0
27+
if [[ "${1:-}" == "--strict" ]]; then
28+
strict=1
29+
shift
30+
fi
31+
32+
if [[ "$#" -lt 1 ]]; then
33+
echo "Usage: $0 [--strict] <tool> [args...]" >&2
34+
exit 2
35+
fi
36+
37+
tool_name="$1"
38+
shift
39+
40+
# Tests can force either side of the container boundary without changing the
41+
# automatic detection behavior. Reject invalid overrides instead of silently
42+
# treating them as a host environment.
43+
container_mode="${RUN_TOOL_CONTAINER_MODE:-auto}"
44+
case "${container_mode}" in
45+
host) is_container=0 ;;
46+
container) is_container=1 ;;
47+
auto)
48+
if [[ -f /.dockerenv ]] || [[ -f /run/.containerenv ]] || [[ -d /devcontainer ]]; then
49+
is_container=1
50+
else
51+
is_container=0
52+
fi
53+
;;
54+
*)
55+
echo "Invalid RUN_TOOL_CONTAINER_MODE: ${container_mode}" >&2
56+
exit 2
57+
;;
58+
esac
59+
60+
# A container built from this catalog only ever has the pinned version on
61+
# PATH, so container execution is direct and untouched.
62+
if [[ "${is_container}" -eq 1 ]] && command -v "${tool_name}" >/dev/null 2>&1; then
63+
exec "${tool_name}" "$@"
64+
# On the host, prefer the local tool on PATH for faster execution unless --strict
65+
# is set. If local execution fails, suggest --strict to run the pinned Bazel target.
66+
elif [[ "${strict}" -eq 0 ]] && command -v "${tool_name}" >/dev/null 2>&1; then
67+
if "${tool_name}" "$@"; then
68+
exit 0
69+
else
70+
exit_code=$?
71+
echo "Execution of local '${tool_name}' failed with exit code ${exit_code}." >&2
72+
echo "Use '--strict' to bypass the local tool and run the pinned version via Bazel." >&2
73+
exit "${exit_code}"
74+
fi
75+
elif command -v bazel >/dev/null 2>&1; then
76+
# Consumer repositories expose this module as @score_devcontainer; `--`
77+
# prevents tool flags from being interpreted as Bazel flags.
78+
exec bazel run "@score_devcontainer//tools:${tool_name}" -- "$@"
79+
else
80+
echo "Could not run '${tool_name}': no container command or Bazel executable is available." >&2
81+
exit 127
82+
fi

0 commit comments

Comments
 (0)