diff --git a/.github/workflows/main_ci.yaml b/.github/workflows/main_ci.yaml index 1acf5964..88cbc997 100644 --- a/.github/workflows/main_ci.yaml +++ b/.github/workflows/main_ci.yaml @@ -27,7 +27,7 @@ jobs: - name: Pipeline Service Validation env: WORKSPACE_DIR: ${{ github.workspace }} - run: bazel test //pipeline:test --test_output=all + run: bazel test //pipeline:unit_test --test_output=all - name: OpenAPI Contract Check uses: ./.github/actions/openapi-changes diff --git a/autobuild-docs/setup/bazel.md b/autobuild-docs/setup/bazel.md index 61949f72..28a371c3 100644 --- a/autobuild-docs/setup/bazel.md +++ b/autobuild-docs/setup/bazel.md @@ -37,12 +37,27 @@ AutoBuild/ ```sh # Run pipeline (Java/Maven) tests -bazel test //pipeline:test +bazel test //pipeline:unit_test # Run pipeline-ui (Node/npm) tests bazel test //pipeline-ui:unit_test ``` +## Local Development + +`bazel run //:local-dev` starts the local development server for that service. + +```sh +# Start the Spring Boot backend +bazel run //pipeline:local-dev + +# Start the UI with a Prism mock server (no backend needed) +bazel run //pipeline-ui:local-dev +``` + +The UI target uses `.env.local-with-mock` and spins up a Prism mock server driven by the +OpenAPI spec, so the full backend stack is not required for frontend development. + The `--test_env=WORKSPACE_DIR` flag is automatically applied to all `bazel test` invocations via `.bazelrc`, so no extra flags are needed as long as `WORKSPACE_DIR` is set in your shell. @@ -76,13 +91,13 @@ By default Bazel only prints output on failure. Use `--test_output` to control t `--test_output=streamed` is the most useful during development — you see Maven/npm output in real time: ```sh -bazel test //pipeline:test --test_output=streamed +bazel test //pipeline:unit_test --test_output=streamed ``` To read the log from a previous run: ```sh -cat $(bazel info bazel-testlogs)/pipeline/test/test.log +cat $(bazel info bazel-testlogs)/pipeline/unit_test/test.log ``` ## Caching @@ -91,13 +106,13 @@ Bazel caches test results based on input file changes. If no source files or `po have changed since the last run, the result is served from cache: ``` -//pipeline:test (cached) PASSED in 13.5s +//pipeline:unit_test (cached) PASSED in 13.5s ``` To force a re-run regardless of cache: ```sh -bazel test //pipeline:test --cache_test_results=no +bazel test //pipeline:unit_test --cache_test_results=no ``` ## Adding Tests for a New Service @@ -120,7 +135,7 @@ bazel test //pipeline:test --cache_test_results=no load("@rules_shell//shell:sh_test.bzl", "sh_test") sh_test( - name = "test", + name = "unit_test", srcs = ["run_tests.sh"], data = glob(["src/**", "pom.xml"], exclude = ["target/**"]), tags = ["manual", "local"], diff --git a/pipeline-ui/BUILD.bazel b/pipeline-ui/BUILD.bazel index 90640792..4b6cbc53 100644 --- a/pipeline-ui/BUILD.bazel +++ b/pipeline-ui/BUILD.bazel @@ -1,9 +1,10 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") # Inputs Bazel tracks for cache invalidation — if none of these change, # both targets below are skipped entirely (cache hit). _SRCS = glob( - ["src/**", "test/**", "*.json", "*.js", "*.ts"], + ["src/**", "test/**", "*.json", "*.js", "*.ts", "*.html"], exclude = ["src/gen/**"], ) @@ -16,4 +17,12 @@ sh_test( tags = [], ) +# Starts the UI locally with a Prism mock server (no backend needed). +# Run with: bazel run //pipeline-ui:local-dev +sh_binary( + name = "local-dev", + srcs = ["run_local_dev.sh"], + data = _SRCS + ["//apis/openapi-spec:openapi-specs"] + [".env.local-with-mock"], +) + diff --git a/pipeline-ui/run_local_dev.sh b/pipeline-ui/run_local_dev.sh new file mode 100755 index 00000000..17fc472f --- /dev/null +++ b/pipeline-ui/run_local_dev.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd pipeline-ui + +npm ci + +# Dereference symlinks so Vite can resolve modules from this directory +find . -maxdepth 5 -type l ! -path './node_modules/*' | while read -r f; do + cp -Lf "$f" "${f}.deref" && mv "${f}.deref" "$f" +done + +npm run generate:clean-client-code +npm run local-with-mock diff --git a/pipeline/BUILD.bazel b/pipeline/BUILD.bazel index 427ad06d..424e0f3e 100644 --- a/pipeline/BUILD.bazel +++ b/pipeline/BUILD.bazel @@ -1,4 +1,5 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") # Inputs Bazel tracks for cache invalidation — if none of these change, # both targets below are skipped entirely (cache hit). @@ -7,15 +8,27 @@ _SRCS = glob( exclude = ["target/**"], ) + ["//apis/protobuf:protobuf_files"] -# Runs the full Maven test suite. -# Run with: bazel test //pipeline:test +# TODO: Rename to run only unit tests (mvn test) once integration tests are separated +# (rename SecurityConfigTest.java -> SecurityConfigIT.java + add Failsafe plugin to pom.xml). +# Goal: unify with //pipeline-ui:unit_test which runs unit tests only. +# Runs the full Maven verify suite (unit + integration tests + package). +# Run with: bazel test //pipeline:unit_test sh_test( - name = "test", + name = "unit_test", srcs = ["run_tests.sh"], data = _SRCS, tags = ["local"], ) +# Starts the Spring Boot application locally. +# Run with: bazel run //pipeline:local-dev +sh_binary( + name = "local-dev", + srcs = ["run_local_dev.sh"], + data = _SRCS, + tags = ["local"], +) + # Generates the OpenAPI spec by starting the app and hitting /v3/api-docs.yaml. # Output is written to //apis/openapi-spec:pipeline-service.yaml. # Run with: bazel run //pipeline:generate-openapi diff --git a/pipeline/run_local_dev.sh b/pipeline/run_local_dev.sh new file mode 100755 index 00000000..68d24639 --- /dev/null +++ b/pipeline/run_local_dev.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "./pipeline/" +SPRING_PROFILES_ACTIVE=default,sqlite \ +SPRING_JPA_SHOW_SQL=false \ +mvn --batch-mode -s maven-settings.xml spring-boot:run