.prepare_docs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. prepare_docs_log() {
  4. echo "[prepare docs release] -- $@"
  5. }
  6. # Only run for tagged commits
  7. if [ -z "$(git tag -l --points-at HEAD)" ]; then
  8. prepare_docs_log "Skipping non-tagged commit."
  9. exit 0
  10. fi
  11. DOCS_DIR="./docs"
  12. DIST_DIR="./dist/docs"
  13. BRANCHES_DIR="${DIST_DIR}/branches"
  14. API_SPEC_FILE="${DOCS_DIR}/openapi.yaml"
  15. redoc_bundle_file=$(mktemp)
  16. git_ref_version=$(git describe --always)
  17. branch_docs_dir="${BRANCHES_DIR}/${git_ref_version}"
  18. # Build Redoc bundle (a single HTML file)
  19. redoc-cli bundle ${API_SPEC_FILE} -o ${redoc_bundle_file}
  20. # Check out current stuff from gh-pages (we'll append to it)
  21. git checkout gh-pages -- docs
  22. # Create the docs bundle for our ref. This will be the redoc bundle + a
  23. # snapshot of the OpenAPI spec
  24. mkdir -p "${branch_docs_dir}"
  25. cp "${API_SPEC_FILE}" "${branch_docs_dir}"
  26. cp "${redoc_bundle_file}" "${branch_docs_dir}/index.html"
  27. # Create a JSON file containing a list of all branches with docs (we'll
  28. # have an index page that renders the list).
  29. ls "${BRANCHES_DIR}" | jq -R | jq -sc > "${DIST_DIR}/branches.json"