2015-07-16 02:46:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-10-16 18:30:00 +00:00
|
|
|
# Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-07-16 02:46:04 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2015-10-19 23:40:13 +00:00
|
|
|
# Generates updated api-reference docs from the latest swagger spec.
|
|
|
|
# Usage: ./update-api-reference-docs.sh <absolute output path>
|
|
|
|
|
2015-10-16 18:30:00 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
2015-07-16 02:46:04 +00:00
|
|
|
|
2015-10-19 23:40:13 +00:00
|
|
|
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
2015-10-27 20:57:42 +00:00
|
|
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
|
|
|
kube::golang::setup_env
|
|
|
|
|
2015-11-07 00:58:15 +00:00
|
|
|
DEFAULT_OUTPUT="${KUBE_ROOT}/docs/api-reference"
|
|
|
|
OUTPUT=${1:-${DEFAULT_OUTPUT}}
|
|
|
|
# Use REPO_DIR if provided so we can set it to the host-resolvable path
|
|
|
|
# to the repo root if we are running this script from a container with
|
|
|
|
# docker mounted in as a volume.
|
|
|
|
# We pass the host output dir as the source dir to `docker run -v`, but use
|
|
|
|
# the regular one to compute diff (they will be the same if running this
|
|
|
|
# test on the host, potentially different if running in a container).
|
2015-10-27 20:57:42 +00:00
|
|
|
REPO_DIR=${REPO_DIR:-"${KUBE_ROOT}"}
|
2015-11-07 00:58:15 +00:00
|
|
|
TMP_SUBPATH="_output/generated_html"
|
|
|
|
OUTPUT_TMP_IN_HOST="${REPO_DIR}/${TMP_SUBPATH}"
|
|
|
|
OUTPUT_TMP="${KUBE_ROOT}/${TMP_SUBPATH}"
|
|
|
|
|
|
|
|
echo "Generating api reference docs at ${OUTPUT_TMP}"
|
|
|
|
|
|
|
|
V1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/v1/"
|
|
|
|
V1_TMP="${OUTPUT_TMP}/v1/"
|
|
|
|
mkdir -p ${V1_TMP}
|
|
|
|
V1BETA1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/extensions/v1beta1/"
|
|
|
|
V1BETA1_TMP="${OUTPUT_TMP}/extensions/v1beta1/"
|
|
|
|
mkdir -p ${V1BETA1_TMP}
|
2015-10-26 17:51:32 +00:00
|
|
|
SWAGGER_PATH="${REPO_DIR}/api/swagger-spec/"
|
2015-10-19 23:40:13 +00:00
|
|
|
|
|
|
|
echo "Reading swagger spec from: ${SWAGGER_PATH}"
|
|
|
|
|
2015-11-07 00:58:15 +00:00
|
|
|
docker run -u $(id -u) --rm -v $V1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \
|
2015-10-16 18:30:00 +00:00
|
|
|
v1 \
|
|
|
|
https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/api/v1/register.go
|
|
|
|
|
2015-11-07 00:58:15 +00:00
|
|
|
docker run -u $(id -u) --rm -v $V1BETA1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \
|
2015-10-16 18:30:00 +00:00
|
|
|
v1beta1 \
|
|
|
|
https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/apis/extensions/v1beta1/register.go
|
2015-10-19 23:40:13 +00:00
|
|
|
|
2015-10-27 20:57:42 +00:00
|
|
|
# Check if we actually changed anything
|
2015-11-07 00:58:15 +00:00
|
|
|
pushd "${OUTPUT_TMP}" > /dev/null
|
2015-10-27 20:57:42 +00:00
|
|
|
touch .generated_html
|
|
|
|
find . -type f | cut -sd / -f 2- | LC_ALL=C sort > .generated_html
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
while read file; do
|
2015-11-07 00:58:15 +00:00
|
|
|
if [[ -e "${OUTPUT}/${file}" && -e "${OUTPUT_TMP}/${file}" ]]; then
|
|
|
|
echo "comparing ${OUTPUT}/${file} with ${OUTPUT_TMP}/${file}"
|
2015-10-27 20:57:42 +00:00
|
|
|
# Filter all munges from original content.
|
|
|
|
original=$(cat "${OUTPUT}/${file}")
|
2015-11-07 00:58:15 +00:00
|
|
|
generated=$(cat "${OUTPUT_TMP}/${file}")
|
2015-10-27 20:57:42 +00:00
|
|
|
|
|
|
|
# Filter out meaningless lines with timestamps
|
|
|
|
original=$(echo "${original}" | grep -v "Last updated" || :)
|
|
|
|
generated=$(echo "${generated}" | grep -v "Last updated" || :)
|
|
|
|
|
|
|
|
# By now, the contents should be normalized and stripped of any
|
|
|
|
# auto-managed content.
|
|
|
|
if diff -Bw >/dev/null <(echo "${original}") <(echo "${generated}"); then
|
|
|
|
# actual contents same, overwrite generated with original.
|
2015-11-07 00:58:15 +00:00
|
|
|
cp "${OUTPUT}/${file}" "${OUTPUT_TMP}/${file}"
|
2015-10-27 20:57:42 +00:00
|
|
|
fi
|
|
|
|
fi
|
2015-11-07 00:58:15 +00:00
|
|
|
done <"${OUTPUT_TMP}/.generated_html"
|
|
|
|
|
|
|
|
echo "Moving api reference docs from ${OUT_TMP} to ${OUTPUT}"
|
2015-10-27 20:57:42 +00:00
|
|
|
|
2015-11-07 00:58:15 +00:00
|
|
|
cp -af "${OUTPUT_TMP}"/* "${OUTPUT}"
|
|
|
|
rm -r ${OUTPUT_TMP}
|
2015-10-27 20:57:42 +00:00
|
|
|
|
2015-10-19 23:40:13 +00:00
|
|
|
# ex: ts=2 sw=2 et filetype=sh
|