sourcegraph/doc/cli/references/generate_doc_test.sh
Jean-Hadrien Chabran 588463afbb
bzl: bazelify docsite and doc/cli/reference generation (#54538)
This PR is on top of #54517 

---

This PR rework how we handle the docsite and some of its related tasks: 

- While we _could_ avoid committing the generated files to disk, the way
that docsite currently works, requires to have all files available in
git, so the docsite can serve various versions.
- `bazel run //doc/cli/references:write_doc_files` handles this (and
it's umbreall `//dev:write_all_generated`.
- Its generation is now handled by `//doc/cli/references:generate_doc`
and its associated test.
- `sg run docsite` now calls `bazel run //doc:serve`, we don't need to
install the docsite directly anymore (but it's available under `bazel
run //dev/tools:docsite` if needed).

As a byproduct, we can now run `src-cli` with `bazel run
//dev/tools:src-cli` which will pick the correct binary for your machine
transparently.

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

Locally tested + CI
2023-07-03 16:12:44 +02:00

39 lines
1011 B
Bash
Executable File

#!/usr/bin/env bash
set -e
src_bin="$1"
# Array of paths for each of the outputs from the :generate_doc target.
# shellcheck disable=SC2124
got_files="${@:2}"
# Manually run src-cli doc again, so have a list of all the files
# we expect the :generate_doc target to output.
#
# We put them in the ./expected folder.
USER=nobody HOME=. "$src_bin" doc -o=expected/
while IFS= read -r -d '' file
do
want="${file##expected}"
found="false"
# Loop over all files we got.
# shellcheck disable=SC2068
for got in ${got_files[@]}; do
# Trim the path from the "monitoring/output" prefix
# and test it against the expected file we're currently iterating with.
if [[ "${got##doc/cli/references}" == "$want" ]]; then
found="true"
break
fi
done
# If we didn't find it, return an error.
if [[ $found == "false" ]]; then
echo "Couldn't find expected output $want, perhaps it's missing from the 'srcs' attribute?"
exit 1
fi
done < <(find expected -name "*.md" -print0)