Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
load("@bazel_env.bzl", "bazel_env")
load("@bazelrc-preset.bzl", "bazelrc_preset")
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("@tbhb_rules//format:defs.bzl", "format", "format_test")
load(
"@tbhb_rules//lint:defs.bzl",
Expand Down Expand Up @@ -336,6 +337,64 @@ format_test(
formatters = FORMATTERS,
)

# Match the CLI binary to the platform running the development tools.
config_setting(
name = "temporal_linux_amd64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "temporal_linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
)

config_setting(
name = "temporal_darwin_arm64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
)

config_setting(
name = "temporal_windows_amd64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
)

alias(
name = "temporal",
actual = select({
":temporal_darwin_arm64": "@temporal_cli_darwin_arm64//:temporal",
":temporal_linux_amd64": "@temporal_cli_linux_amd64//:temporal",
":temporal_linux_arm64": "@temporal_cli_linux_arm64//:temporal",
":temporal_windows_amd64": "@temporal_cli_windows_amd64//:temporal.exe",
}),
)

sh_test(
name = "temporal_dev_server_test",
size = "medium",
srcs = ["tests/temporal_dev_server_test.sh"],
args = ["$(rootpath :temporal)"],
data = [
"tests/lib/temporal_dev_server.sh",
":temporal",
],
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

# `bazel run //:bazel_env` puts shims for the Bazel-pinned tools in
# .bazel_env/bin, which mise adds to PATH. Git hooks call them directly, so
# a commit never waits on the Bazel server. bazel_env.bzl builds its bin
Expand All @@ -359,6 +418,7 @@ bazel_env(
"ryl": "@tbhb_rules_ryl//:ryl",
"shellcheck": "@tbhb_rules_shellcheck//:shellcheck",
"shfmt": "@tbhb_rules_shfmt//:shfmt",
"temporal": ":temporal",
"tombi": "@tbhb_rules_tombi//:tombi",
"vale": "@tbhb_rules_vale//:vale",
"zizmor": "@tbhb_rules_zizmor//:zizmor",
Expand Down
39 changes: 39 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,50 @@ use_repo(
# Dev dependencies: tooling that only this workspace needs.
bazel_dep(name = "buildifier_prebuilt", version = "10.1.0", dev_dependency = True)
bazel_dep(name = "bazelrc-preset.bzl", version = "1.10.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "1.1.0", dev_dependency = True)
bazel_dep(name = "rules_shell", version = "0.6.1", dev_dependency = True)

# Stable paths and PATH shims (.bazel_env/bin) for the Bazel-pinned tools,
# which git hooks and editors call without starting Bazel.
bazel_dep(name = "bazel_env.bzl", version = "0.10.0", dev_dependency = True)

# Temporal CLI for local development and the dev-server smoke test.
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_TEMPORAL_RELEASE = "https://github.com/temporalio/cli/releases/download/v1.10.0/"

http_archive(
name = "temporal_cli_linux_amd64",
build_file_content = 'exports_files(["temporal"])',
dev_dependency = True,
sha256 = "521f461f3d108902763bb71e85cd0fd382dc9357b59604ae03da6ae734d16890",
url = _TEMPORAL_RELEASE + "temporal_cli_1.10.0_linux_amd64.tar.gz",
)

http_archive(
name = "temporal_cli_linux_arm64",
build_file_content = 'exports_files(["temporal"])',
dev_dependency = True,
sha256 = "6e526d2f089bf5acead2129f1f63e303b848410d5d9d86b9255359dcea6eaaa8",
url = _TEMPORAL_RELEASE + "temporal_cli_1.10.0_linux_arm64.tar.gz",
)

http_archive(
name = "temporal_cli_darwin_arm64",
build_file_content = 'exports_files(["temporal"])',
dev_dependency = True,
sha256 = "40a76ef7d525e6195b083e4cd50b184cc3bb242fea7f8dda2b9a8698ecbb7379",
url = _TEMPORAL_RELEASE + "temporal_cli_1.10.0_darwin_arm64.tar.gz",
)

http_archive(
name = "temporal_cli_windows_amd64",
build_file_content = 'exports_files(["temporal.exe"])',
dev_dependency = True,
sha256 = "b95695d08a564621b02322592bbb525a924f76cc892084fc3dd7d2e90f42b8bd",
url = _TEMPORAL_RELEASE + "temporal_cli_1.10.0_windows_amd64.zip",
)

# Pinned copies of the SchemaStore schemas that pyproject.toml's embedded
# tombi schema refers to by URL, so //:tombi_test validates offline. Pinned
# to a SchemaStore commit, because www.schemastore.org serves whatever is
Expand Down
62 changes: 62 additions & 0 deletions tests/lib/temporal_dev_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright Tony Burns

set -euo pipefail

temporal_dev_server_start() {
local port attempt
TEMPORAL_SERVER_PID=
for ((port = 17233; port < 17333; port++)); do
if ! (echo >"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then
break
fi
done
if ((port == 17333)); then
echo "No free Temporal port found" >&2
return 1
fi

"$TEMPORAL" server start-dev --headless --port "$port" >"$TEST_TMPDIR/temporal-server.log" 2>&1 &
TEMPORAL_SERVER_PID=$!
echo "Started Temporal dev server (PID $TEMPORAL_SERVER_PID, port $port)"
for ((attempt = 0; attempt < 30; attempt++)); do
if ! kill -0 "$TEMPORAL_SERVER_PID" 2>/dev/null; then
echo "Temporal dev server exited before becoming healthy" >&2
cat "$TEST_TMPDIR/temporal-server.log" >&2
return 1
fi
if "$TEMPORAL" operator cluster health --address "127.0.0.1:$port" --command-timeout 1s >"$TEST_TMPDIR/temporal-health.log" 2>&1; then
echo "Temporal dev server is healthy"
cat "$TEST_TMPDIR/temporal-health.log"
return 0
fi
sleep 1
done
echo "Timed out waiting for Temporal dev server health" >&2
cat "$TEST_TMPDIR/temporal-server.log" "$TEST_TMPDIR/temporal-health.log" >&2
return 1
}

temporal_dev_server_stop() {
local attempt leaked=0
if [[ -z ${TEMPORAL_SERVER_PID:-} ]]; then
return 0
fi
kill "$TEMPORAL_SERVER_PID" 2>/dev/null || true
for ((attempt = 0; attempt < 10; attempt++)); do
if ! kill -0 "$TEMPORAL_SERVER_PID" 2>/dev/null; then
break
fi
sleep 1
done
if kill -0 "$TEMPORAL_SERVER_PID" 2>/dev/null; then
echo "Temporal dev server leaked after shutdown; killing it" >&2
kill -KILL "$TEMPORAL_SERVER_PID"
leaked=1
fi
wait "$TEMPORAL_SERVER_PID" || true
echo "Stopped and reaped Temporal dev server (PID $TEMPORAL_SERVER_PID)"
TEMPORAL_SERVER_PID=
return "$leaked"
}
12 changes: 12 additions & 0 deletions tests/temporal_dev_server_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright Tony Burns

set -euo pipefail

TEMPORAL="$PWD/$1"
# shellcheck source=tests/lib/temporal_dev_server.sh
source "$TEST_SRCDIR/$TEST_WORKSPACE/tests/lib/temporal_dev_server.sh"
trap 'temporal_dev_server_stop || exit 1' EXIT

temporal_dev_server_start
Loading