Skip to content

Commit

Permalink
Add new docs generating function
Browse files Browse the repository at this point in the history
Signed-off-by: jonasrosland <jrosland@vmware.com>
  • Loading branch information
jonasrosland committed Apr 15, 2020
1 parent dc3b977 commit 779c2f2
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 7 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ clean:
rm -rf public resources

prepare:
git submodule update --init --remote --merge
cp -rf harbor/docs content
rm -rf content/docs/*.md content/docs/prepare-swagger.sh content/docs/{adopters,security} content/docs/**/README.md
$(CURDIR)/load-docs.sh

serve:
hugo server \
Expand Down
5 changes: 4 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ logo_repo = "https://branding.cncf.io/projects/harbor"
youtube_video_id = "hG1YSlfVTqY"
alpine_js_version = "2.1.2"

versions = ["1.10"]
[[params.versions]]
harborversion = "1.10"
helmversion = "1.3"
branchname = "release-1.10-doc"

[params.info]
what_is = "Harbor is an open source container image registry that secures images with role-based access control, scans images for vulnerabilities, and signs images as trusted. As a CNCF Incubating project, Harbor delivers compliance, performance, and interoperability to help you consistently and securely manage images across cloud native compute platforms like Kubernetes and Docker."
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
</p>

<div class="navbar-dropdown is-right">
{{ range $versions }}
{{ range site.Params.versions }}
{{ $isLatest := eq . $latest }}
<div class="navbar-item">
<div class="columns">
<div class="column">
<a class="has-text-black" href="/docs/{{ . }}">
<a class="has-text-black" href="/docs/{{ .harborversion }}">
<span>
{{ . }}
{{ .harborversion }}
</span>
&nbsp;&nbsp;
{{ if $isLatest }}
Expand Down
153 changes: 153 additions & 0 deletions load-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash
# Original file from the Open Policy Agent project: https://github.com/open-policy-agent/opa/blob/master/docs/website/scripts/load-docs.sh

set -xe

ORIGINAL_COMMIT=$(git symbolic-ref -q --short HEAD || git name-rev --name-only HEAD)
# If no name can be found "git name-rev" returns
# "undefined", in which case we'll just use the
# current commit ID.
if [[ "${ORIGINAL_COMMIT}" == "undefined" ]]; then
ORIGINAL_COMMIT=$(git rev-parse HEAD)
fi

ROOT_DIR=$(git rev-parse --show-toplevel)
#RELEASES_YAML_FILE=${ROOT_DIR}/data/releases.yaml
GIT_VERSION=$(git --version)

# Look at the git tags and generate a list of releases
# that we want to show docs for.
if [[ -z ${OFFLINE} ]]; then
git fetch ${REPOSITORY_URL:-https://github.com/goharbor/harbor.git}
fi
ALL_RELEASES=$(git ls-remote https://github.com/goharbor/harbor | grep release | awk -F/ '{print $3}' | sort -r -V)
RELEASES=()
PREV_MAJOR_VER="-1"
PREV_MINOR_VER="-1"

for release in ${ALL_RELEASES}; do
CUR_SEM_VER=${release#"release-"}

# ignore any release candidate versions, for now if they
# are the "latest" they'll be documented under "edge"
if [[ "${CUR_SEM_VER}" == *"rc"* ]]; then
continue
fi
# this is just a dirty fix to not use the 1.10.0 branch
if [[ "${CUR_SEM_VER}" == *"1.10.0"* ]]; then
continue
fi

SEMVER_REGEX='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
CUR_MAJOR_VER=$(echo ${CUR_SEM_VER} | sed -e "s#${SEMVER_REGEX}#\1#")
CUR_MINOR_VER=$(echo ${CUR_SEM_VER} | sed -e "s#${SEMVER_REGEX}#\2#")
CUR_PATCH_VER=$(echo ${CUR_SEM_VER} | sed -e "s#${SEMVER_REGEX}#\3#")

# ignore versions from before we used this static site generator
if [[ (${CUR_MAJOR_VER} -lt 1) || \
(${CUR_MAJOR_VER} -le 1 && ${CUR_MINOR_VER} -lt 10) ]]; then
continue
fi

# The releases are sorted in order by semver from newest to oldest, and we only want
# the latest point release for each minor version
if [[ "${CUR_MAJOR_VER}" != "${PREV_MAJOR_VER}" || \
("${CUR_MAJOR_VER}" = "${PREV_MAJOR_VER}" && \
"${CUR_MINOR_VER}" != "${PREV_MINOR_VER}") ]]; then
RELEASES+=(${release})
fi

PREV_MAJOR_VER=${CUR_MAJOR_VER}
PREV_MINOR_VER=${CUR_MINOR_VER}
done

echo "Git version: ${GIT_VERSION}"

echo "Saving current workspace state"
STASH_TOKEN=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
git stash push --include-untracked -m "${STASH_TOKEN}"

function restore_tree {
echo "Returning to commit ${ORIGINAL_COMMIT}"
git checkout ${ORIGINAL_COMMIT}

# Only pop from the stash if we had stashed something earlier
if [[ -n "$(git stash list | head -1 | grep ${STASH_TOKEN} || echo '')" ]]; then
git stash pop
fi
}

function cleanup {
EXIT_CODE=$?

if [[ "${EXIT_CODE}" != "0" ]]; then
# on errors attempt to restore the starting tree state
restore_tree

echo "Error loading docs"
exit ${EXIT_CODE}
fi

echo "Docs loading complete"
}

trap cleanup EXIT

echo "Cleaning generated folder"
rm -rf ${ROOT_DIR}/generated/*

#echo "Removing data/releases.yaml file"
#rm -f ${RELEASES_YAML_FILE}

#mkdir -p $(dirname ${RELEASES_YAML_FILE})

#echo 'Adding "latest" version to releases.yaml'
#echo "- latest" > ${RELEASES_YAML_FILE}

for release in "${RELEASES[@]}"; do

echo "Checking out release ${release}"

# Don't error if the checkout fails
set +e
git fetch https://github.com/goharbor/harbor.git ${release}:${release}
git checkout ${release}
errc=$?
set -e

# only add the version to the releases.yaml data file
# if we were able to check out the version, otherwise skip it..
# if [[ "${errc}" == "0" ]]; then
# echo "Adding ${release} to releases.yaml"
# echo "- ${release}" >> ${RELEASES_YAML_FILE}
# else
# echo "WARNING: Failed to check out version ${version}!!"
# fi

release=$(echo $release | awk -F- '{print $2}')
version_docs_dir=${ROOT_DIR}/generated/docs/${release}

mkdir -p ${version_docs_dir}

echo "Copying doc content from tag ${release}"
cp -r ${ROOT_DIR}/docs/* ${version_docs_dir}/

done

# Move generated content to the right place
mkdir -p content/docs
mv generated/docs/* content/docs

# Go back to the original tree state
restore_tree

# Create the "edge" version from current working tree
#echo 'Adding "edge" to releases.yaml'
#echo "- edge" >> ${RELEASES_YAML_FILE}

# Link instead of copy so we don't need to re-generate each time.
# Use a relative link so it works in a container more easily.
#ln -s ../../../content ${ROOT_DIR}/docs/website/generated/docs/edge

# Create a "latest" version from the latest semver found
#ln -s ${ROOT_DIR}/docs/website/generated/docs/${RELEASES[0]} ${ROOT_DIR}/docs/website/generated/docs/latest

0 comments on commit 779c2f2

Please sign in to comment.