xref: /aosp_15_r20/external/bazelbuild-rules_rust/docs/update_docs.sh (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan#!/usr/bin/env bash
2*d4726bddSHONG Yifan
3*d4726bddSHONG Yifanset -euo pipefail
4*d4726bddSHONG Yifan
5*d4726bddSHONG Yifanif [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then
6*d4726bddSHONG Yifan    DOCS_WORKSPACE="${BUILD_WORKSPACE_DIRECTORY}"
7*d4726bddSHONG Yifanelse
8*d4726bddSHONG Yifan    # https://stackoverflow.com/a/246128/7768383
9*d4726bddSHONG Yifan    DOCS_WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
10*d4726bddSHONG Yifanfi
11*d4726bddSHONG Yifan
12*d4726bddSHONG Yifanpushd "${DOCS_WORKSPACE}" &> /dev/null
13*d4726bddSHONG Yifan# It's important to clean the workspace so we don't end up with unintended
14*d4726bddSHONG Yifan# docs artifacts in the new commit.
15*d4726bddSHONG Yifanbazel clean \
16*d4726bddSHONG Yifan&& bazel build //... \
17*d4726bddSHONG Yifan&& cp bazel-bin/*.md . \
18*d4726bddSHONG Yifan&& chmod 0644 *.md
19*d4726bddSHONG Yifan
20*d4726bddSHONG Yifanif [[ -z "${SKIP_COMMIT:-}" ]]; then
21*d4726bddSHONG Yifan    git add *.md && git commit -m "Regenerate documentation"
22*d4726bddSHONG Yifanfi
23*d4726bddSHONG Yifan
24*d4726bddSHONG Yifanpopd &> /dev/null
25