xref: /aosp_15_r20/external/bazelbuild-rules_rust/docs/test_docs.sh (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1#!/bin/bash
2
3set -euo pipefail
4
5if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then
6    DOCS_WORKSPACE="${BUILD_WORKSPACE_DIRECTORY}"
7else
8    # Get the directory of the current script when not running under
9    # Bazel (as indicated by the lack of BUILD_WORKSPACE_DIRECTORY).
10    DOCS_WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
11fi
12
13pushd "${DOCS_WORKSPACE}" &> /dev/null
14# It's important to clean the workspace so we don't end up with unintended
15# docs artifacts in the new commit.
16bazel clean \
17&& bazel build //... \
18&& cp bazel-bin/*.md . \
19&& chmod 0644 *.md
20
21if [ -n "$(git status --porcelain)" ]; then
22    >&2 git status
23    >&2 echo '/docs is out of date. Please run `./docs/update_docs.sh` from the root of rules_rust and push the results' >&2
24    exit 1
25fi
26
27popd &> /dev/null
28