.prepare_docs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 fetch origin 'refs/heads/gh-pages:refs/heads/gh-pages'
  22. git checkout gh-pages -- docs
  23. # Create the docs bundle for our ref. This will be the redoc bundle + a
  24. # snapshot of the OpenAPI spec
  25. mkdir -p "${branch_docs_dir}"
  26. cp "${API_SPEC_FILE}" "${branch_docs_dir}"
  27. cp "${redoc_bundle_file}" "${branch_docs_dir}/index.html"
  28. # Create a JSON file containing a list of all branches with docs (we'll
  29. # have an index page that renders the list).
  30. ls "${BRANCHES_DIR}" | jq -Rc '.' | jq -sc '.' > "${DIST_DIR}/branches.json"