Update common files (#4870)

- Enable a bunch of linting rules in the repo, and addressed all the linting
errors
This commit is contained in:
Martin Taillefer 2019-08-29 08:09:32 -07:00 committed by Istio Automation
parent 118eb9c1fe
commit a48f05a3e9
16 changed files with 566 additions and 739 deletions

View File

@ -66,6 +66,7 @@ RUN = docker run -t -i --sig-proxy=true -u $(UID) --rm \
-e BUILD_WITH_CONTAINER="$(BUILD_WITH_CONTAINER)" \
-v /etc/passwd:/etc/passwd:ro \
-v $(readlink /etc/localtime):/etc/localtime:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
$(CONTAINER_OPTIONS) \
--mount type=bind,source="$(PWD)",destination="/work" \
--mount type=volume,source=istio-go-mod,destination="/go/pkg/mod" \

View File

@ -23,7 +23,7 @@ clean_public:
clean: clean_public
@rm -fr resources .htmlproofer tmp
lint: clean_public gen_nominify
lint: clean_public gen_nominify lint-copyright-banner lint-python lint-yaml lint-dockerfiles
@scripts/lint_site.sh
serve: build
@ -55,8 +55,6 @@ netlify_archive:
archive:
@scripts/gen_archive_site.sh "$(baseurl)"
prow: lint
update_ref_docs:
@scripts/grab_reference_docs.sh

View File

@ -1 +1 @@
924cf1256448b0869bf55646525e1439ec11f85c
02f70e0b143bfe50002d3915e10f35571463dd65

View File

@ -1,4 +1,19 @@
#!/usr/bin/env sh
# Copyright Istio Authors
#
# 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.
set -e
mkdir -p generated/css generated/js generated/img tmp/js
@ -7,6 +22,26 @@ sass src/sass/_all.scss all.css -s compressed --no-source-map
mv all.css* generated/css
tsc
babel --source-maps --minified --no-comments --presets minify tmp/js/constants.js tmp/js/utils.js tmp/js/kbdnav.js tmp/js/themes.js tmp/js/menu.js tmp/js/header.js tmp/js/sidebar.js tmp/js/tabset.js tmp/js/prism.js tmp/js/codeBlocks.js tmp/js/links.js tmp/js/scroll.js tmp/js/overlays.js tmp/js/lang.js tmp/js/callToAction.js --out-file generated/js/all.min.js
babel --source-maps --minified --no-comments --presets minify tmp/js/themes_init.js --out-file generated/js/themes_init.min.js
babel --source-maps --minified --no-comments --presets minify \
tmp/js/constants.js \
tmp/js/utils.js \
tmp/js/kbdnav.js \
tmp/js/themes.js \
tmp/js/menu.js \
tmp/js/header.js \
tmp/js/sidebar.js \
tmp/js/tabset.js \
tmp/js/prism.js \
tmp/js/codeBlocks.js \
tmp/js/links.js \
tmp/js/scroll.js \
tmp/js/overlays.js \
tmp/js/lang.js \
tmp/js/callToAction.js \
--out-file generated/js/all.min.js
babel --source-maps --minified --no-comments --presets minify \
tmp/js/themes_init.js \
--out-file generated/js/themes_init.min.js
svgstore -o generated/img/icons.svg src/icons/**/*.svg

View File

@ -1,52 +0,0 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make updatecommon".
# Copyright 2019 Istio Authors
#
# 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.
set -e
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )"
ROOTDIR=$(dirname "${SCRIPTPATH}")
cd "${ROOTDIR}"
CD_TMPFILE=$(mktemp /tmp/check_dockerfile.XXXXXX)
HL_TMPFILE=$(mktemp /tmp/hadolint.XXXXXX)
# shellcheck disable=SC2044
for df in $(find "${ROOTDIR}" -path "${ROOTDIR}/vendor" -prune -o -name 'Dockerfile*'); do
docker run --rm -i hadolint/hadolint:v1.17.1 < "$df" > "${HL_TMPFILE}"
if [ "" != "$(cat "${HL_TMPFILE}")" ]
then
{
echo "$df:"
cut -d":" -f2- < "${HL_TMPFILE}"
echo
} >> "${CD_TMPFILE}"
fi
done
rm -f "${HL_TMPFILE}"
if [ "" != "$(cat "${CD_TMPFILE}")" ]; then
cat "${CD_TMPFILE}"
rm -f "${CD_TMPFILE}"
exit 1
fi
rm -f "${CD_TMPFILE}"

View File

@ -1,83 +0,0 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make updatecommon".
# Copyright 2018 Istio Authors
#
# 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.
set -e
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOTDIR=$(dirname "${SCRIPTPATH}")
cd "${ROOTDIR}"
ADD_LICENSE=$1
THISYEAR=$(date +"%Y")
if [[ $ADD_LICENSE == true ]]; then
echo "Check License script is running in ADD_LICENSE mode. It will automatically add any missing licenses for you."
fi
ret=0
for fn in $(find "${ROOTDIR}" -type f \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' \) | grep -v vendor | grep -v testdata); do
if [[ $fn == *.pb.go ]];then
continue
fi
if head -20 "$fn" | grep "auto\\-generated" > /dev/null; then
continue
fi
if head -20 "$fn" | grep "DO NOT EDIT" > /dev/null; then
continue
fi
if head -20 "$fn" | grep "Code generated by go-bindata" > /dev/null; then
continue
fi
if ! head -20 "$fn" | grep "Apache License, Version 2" > /dev/null; then
if [[ $ADD_LICENSE == true ]]; then
echo "// Copyright ${THISYEAR} Istio Authors
//
// 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.
$(cat "${fn}")" > "${fn}"
else
echo "${fn} missing license"
ret=$((ret+1))
fi
fi
if ! head -20 "$fn" | grep Copyright > /dev/null; then
echo "${fn} missing Copyright"
ret=$((ret+1))
fi
done
exit $ret

View File

@ -1,7 +1,22 @@
#! /bin/bash
# Copyright Istio Authors
#
# 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.
# Build the archive site
#
set -e
BASEURL="$1"
@ -22,51 +37,45 @@ TOBUILD_JEKYLL=(
v0.1:release-0.1
)
# Prereqs
npm install sass sass-lint typescript tslint @babel/cli @babel/core svgstore-cli html-minifier --save-dev
npm install babel-preset-minify --save-dev
# Prepare
TMP=$(mktemp -d)
mkdir ${TMP}/archive
mkdir "${TMP}/archive"
GITDIR=istio.io
rm -fr ${GITDIR}
git clone https://github.com/istio/istio.io.git
cd ${GITDIR}
for rel in "${TOBUILD[@]}"
do
NAME=$(echo $rel | cut -d : -f 1)
TAG=$(echo $rel | cut -d : -f 2)
URL=$(echo ${BASEURL}/${NAME})
for rel in "${TOBUILD[@]}"; do
NAME=$(echo "$rel" | cut -d : -f 1)
TAG=$(echo "$rel" | cut -d : -f 2)
URL=${BASEURL}/${NAME}
echo "### Building '${NAME}' from ${TAG} for ${URL}"
git checkout ${TAG}
git checkout "${TAG}"
scripts/gen_site.sh ${URL}
scripts/gen_site.sh "${URL}"
mv public ${TMP}/archive/${NAME}
echo "- name: \"${NAME}\"" >> ${TMP}/archives.yml
mv public "${TMP}/archive/${NAME}"
echo "- name: \"${NAME}\"" >> "${TMP}/archives.yml"
git clean -f
done
for rel in "${TOBUILD_JEKYLL[@]}"
do
NAME=$(echo $rel | cut -d : -f 1)
TAG=$(echo $rel | cut -d : -f 2)
URL=$(echo ${BASEURL}/${NAME})
for rel in "${TOBUILD_JEKYLL[@]}"; do
NAME=$(echo "$rel" | cut -d : -f 1)
TAG=$(echo "$rel" | cut -d : -f 2)
URL=${BASEURL}/${NAME}
echo "### Building '${NAME}' from ${TAG} for ${URL}"
git checkout ${TAG}
git checkout "${TAG}"
echo "baseurl: ${URL}" > config_override.yml
bundle install
bundle exec jekyll build --config _config.yml,config_override.yml
mv _site ${TMP}/archive/${NAME}
echo "- name: \"${NAME}\"" >> ${TMP}/archives.yml
mv _site "${TMP}/archive/${NAME}"
echo "- name: \"${NAME}\"" >> "${TMP}/archives.yml"
git clean -f
done
@ -81,14 +90,14 @@ sed -i 's/preliminary: true/preliminary: false/g' data/args.yml
sed -i 's/archive_landing: false/archive_landing: true/g' data/args.yml
# Grab the state
cp ${TMP}/archives.yml data
cp "${TMP}/archives.yml" data
scripts/build_site.sh
scripts/gen_site.sh "$1"
mv public/* ${TMP}/archive
rm -fr ${GITDIR} public
mv ${TMP}/archive public
rm -fr ${TMP}
mv public/* "${TMP}/archive"
rm -fr "${GITDIR}" public
mv "${TMP}/archive" public
rm -fr "${TMP}"
echo "All done!"

View File

@ -1,10 +1,24 @@
#! /bin/bash
# Copyright Istio Authors
#
# 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.
set -e
hugo version
if [[ "$2" == "-no_minify" ]]
then
if [[ "$2" == "-no_minify" ]]; then
hugo --baseURL "$1"
else
hugo --minify --baseURL "$1"

View File

@ -1,13 +1,27 @@
#!/bin/bash
# Copyright Istio Authors
#
# 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.
# This script copies generated .pb.html files, which contain reference docs for protos, and installs
# them in their targeted location within the content/docs/reference tree of this repo. Each .pb.html file contains a
# them in their targeted location within the content/en/docs/reference tree of this repo. Each .pb.html file contains a
# line that indicates the target directory location. The line is of the form:
#
# location: https://istio.io/docs/reference/...
#
# Additionally, this script also builds Istio components and runs them to extract their command-line docs which it
# copies to content/docs/reference/commands.
# copies to content/en/docs/reference/commands.
# The repos to mine for docs, just add new entries here to pull in more repos.
REPOS=(
@ -46,14 +60,6 @@ echo "WORK_DIR =" "${WORK_DIR}"
#####################
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd > /dev/null
}
# Given the name of a .pb.html file, extracts the $location marker and then proceeds to
# copy the file to the corresponding content/en/docs/ hierarchy.
locate_file() {
@ -82,8 +88,8 @@ locate_file() {
REPOX=${REPO_URL/.git/}
REPOX=${REPOX//\//\\\/}
sed -i -e 's/title: /WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL SOURCE IN THE '${REPOX}' REPO\'$'\n''title: /g' "${ROOTDIR}/content/en/docs${PP}/${FN}/index.html"
sed -i -e 's/title: /source_repo: '${REPOX}'\'$'\n''title: /g' "${ROOTDIR}/content/en/docs${PP}/${FN}/index.html"
sed -i -e 's/title: /WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL SOURCE IN THE '"${REPOX}"' REPO\'$'\n''title: /g' "${ROOTDIR}/content/en/docs${PP}/${FN}/index.html"
sed -i -e 's/title: /source_repo: '"${REPOX}"'\'$'\n''title: /g' "${ROOTDIR}/content/en/docs${PP}/${FN}/index.html"
}
handle_doc_scraping() {
@ -94,13 +100,13 @@ handle_doc_scraping() {
echo " INPUT REPO: ${REPO_URL}@${REPO_BRANCH}"
git clone --depth=1 -q -b ${REPO_BRANCH} ${REPO_URL} ${DEST_DIR}
git clone --depth=1 -q -b "${REPO_BRANCH}" "${REPO_URL}" "${DEST_DIR}"
# delete the vendor directory so we don't get .pb.html out of there
rm -fr "${DEST_DIR}/vendor"
for f in `find "${DEST_DIR}" -type f -name '*.pb.html'`; do
locate_file ${f}
for f in $(find "${DEST_DIR}" -type f -name '*.pb.html'); do
locate_file "${f}"
done
rm -fr "${DEST_DIR}"
@ -119,8 +125,8 @@ handle_components() {
git clone --depth=1 -q -b "${REPO_BRANCH}" "${REPO_URL}"
pushd "${REPO_NAME}" || exit
pushd "${COMP_PATH}" || exit
pushd "${REPO_NAME}" >dev/null || exit
pushd "${COMP_PATH}" >dev/null || exit
go build -o "${COMP_NAME}"
mkdir -p "${COMP_OUTPUT_DIR}/${COMP_NAME}"
@ -131,8 +137,8 @@ handle_components() {
sed -i -e 's/title: /WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL SOURCE IN THE https:\/\/github.com\/istio\/istio REPO\'$'\n''title: /g' "${COMP_OUTPUT_DIR}/${COMP_NAME}/index.html"
sed -i -e 's/title: /source_repo: https:\/\/github.com\/istio\/istio\'$'\n''title: /g' "${COMP_OUTPUT_DIR}/${COMP_NAME}/index.html"
popd || exit
popd || exit
popd >dev/null || exit
popd >dev/null || exit
rm -fr "${REPO_NAME}"
done
@ -143,7 +149,7 @@ find "${ROOTDIR}/content/en/docs/reference" -name '*.html' -type f -print0 | xar
# Prepare the work directory
mkdir -p "${WORK_DIR}"
pushd "${WORK_DIR}" || exit
pushd "${WORK_DIR}" >dev/null || exit
#echo "Handling doc scraping"
handle_doc_scraping

View File

@ -1,5 +1,21 @@
#!/bin/bash
# Copyright Istio Authors
#
# 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.
set -e
FAILED=0
echo -ne "mdspell "
@ -22,72 +38,58 @@ check_content() {
TMP=$(mktemp -d)
# make the tmp dir
mkdir -p ${TMP}
mkdir -p "${TMP}"
# create a throwaway copy of the content
cp -R ${DIR} ${TMP}
cp .spelling ${TMP}
cp mdl_style.rb ${TMP}
cp -R "${DIR}" "${TMP}"
cp .spelling "${TMP}"
cp mdl_style.rb "${TMP}"
# replace the {{< text >}} shortcodes with ```plain
find ${TMP} -type f -name \*.md -exec sed -E -i "s/\\{\\{< text .*>\}\}/\`\`\`plain/g" {} ";"
find "${TMP}" -type f -name \*.md -exec sed -E -i "s/\\{\\{< text .*>\}\}/\`\`\`plain/g" {} ";"
# replace the {{< /text >}} shortcodes with ```
find ${TMP} -type f -name \*.md -exec sed -E -i "s/\\{\\{< \/text .*>\}\}/\`\`\`/g" {} ";"
find "${TMP}" -type f -name \*.md -exec sed -E -i "s/\\{\\{< \/text .*>\}\}/\`\`\`/g" {} ";"
# elide url="*"
find ${TMP} -type f -name \*.md -exec sed -E -i "s/url=\".*\"/URL/g" {} ";"
find "${TMP}" -type f -name \*.md -exec sed -E -i "s/url=\".*\"/URL/g" {} ";"
# elide link="*"
find ${TMP} -type f -name \*.md -exec sed -E -i "s/link=\".*\"/LINK/g" {} ";"
find "${TMP}" -type f -name \*.md -exec sed -E -i "s/link=\".*\"/LINK/g" {} ";"
# switch to the temp dir
pushd ${TMP} >/dev/null
pushd "${TMP}" >/dev/null
mdspell ${LANG} --ignore-acronyms --ignore-numbers --no-suggestions --report `find content/en -type f -name '*.md'`
if [[ "$?" != "0" ]]
then
if ! mdspell "${LANG}" --ignore-acronyms --ignore-numbers --no-suggestions --report $(find content/en -type f -name '*.md'); then
echo "To learn how to address spelling errors, please see https://istio.io/about/contribute/creating-and-editing-pages/#linting"
FAILED=1
fi
mdl --ignore-front-matter --style mdl_style.rb .
if [[ "$?" != "0" ]]
then
if ! mdl --ignore-front-matter --style mdl_style.rb .; then
FAILED=1
fi
grep -nr -e "(https://istio.io" .
if [[ "$?" == "0" ]]
then
if grep -nr -e "(https://istio.io" .; then
echo "Ensure markdown content uses relative references to istio.io"
FAILED=1
fi
grep -nr -e "(https://preliminary.istio.io" .
if [[ "$?" == "0" ]]
then
if grep -nr -e "(https://preliminary.istio.io" .; then
echo "Ensure markdown content doesn't contain references to preliminary.istio.io"
FAILED=1
fi
grep -nr -e "https://github.com/istio/istio/blob/" .
if [[ "$?" == "0" ]]
then
if grep -nr -e https://github.com/istio/istio/blob/ .; then
echo "Ensure markdown content uses {{< github_blob >}}"
FAILED=1
fi
grep -nr -e "https://github.com/istio/istio/tree/" .
if [[ "$?" == "0" ]]
then
if grep -nr -e https://github.com/istio/istio/tree/ .; then
echo "Ensure markdown content uses {{< github_tree >}}"
FAILED=1
fi
grep -nr -e "https://raw.githubusercontent.com/istio/istio/" .
if [[ "$?" == "0" ]]
then
if grep -nr -e https://raw.githubusercontent.com/istio/istio/ .; then
echo "Ensure markdown content uses {{< github_file >}}"
FAILED=1
fi
@ -96,49 +98,39 @@ check_content() {
popd >/dev/null
# cleanup
rm -fr ${TMP}
rm -fr "${TMP}"
}
check_content content --en-us
for f in `find ./content/en -type f \( -name '*.html' -o -name '*.md' \)`
do
grep -H -n -e "“" ${f}
if [[ "$?" == "0" ]]
then
for f in $(find ./content/en -type f \( -name '*.html' -o -name '*.md' \)); do
# shellcheck disable=SC1111
if grep -H -n -e '“' "${f}"; then
echo "Ensure content only uses standard quotation marks and not “"
FAILED=1
fi
done
for f in `find ./public -type f -name '*.html'`
do
grep -H -n -i -e "blockquote" ${f}
if [[ "$?" == "0" ]]
then
for f in $(find ./public -type f -name '*.html'); do
if grep -H -n -i -e blockquote "${f}"; then
echo "Ensure content only uses {{< tip >}}, {{< warning >}}, {{< idea >}}, and {{< quote >}} instead of block quotes"
FAILED=1
fi
grep -H -n -e "\"https://github.*#L[0-9]*\"" ${f}
if [[ "$?" == "0" ]]
then
if grep -H -n -e "\"https://github.*#L[0-9]*\"" "${f}"; then
echo "Ensure content doesn't use links to specific lines in GitHub files as those are too brittle"
FAILED=1
fi
done
sass-lint -c sass-lint.yml --verbose 'src/sass/**/*.scss'
sass-lint -c sass-lint.yml --verbose src/sass/**/*.scss
tslint src/ts/*.ts
htmlproofer ./public --assume-extension --check-html --check-external-hash --check-opengraph --timeframe 2d --storage-dir .htmlproofer --url-ignore "/localhost/,/github.com/istio/istio.io/edit/,/github.com/istio/istio/issues/new/choose/,/groups.google.com/forum/,/www.trulia.com/,/apporbit.com/"
if [[ "$?" != "0" ]]
then
if ! htmlproofer ./public --assume-extension --check-html --check-external-hash --check-opengraph --timeframe 2d --storage-dir .htmlproofer --url-ignore "/localhost/,/github.com/istio/istio.io/edit/,/github.com/istio/istio/issues/new/choose/,/groups.google.com/forum/,/www.trulia.com/,/apporbit.com/"; then
FAILED=1
fi
if [[ ${FAILED} -eq 1 ]]
then
if [[ ${FAILED} -eq 1 ]]; then
echo "LINTING FAILED"
exit 1
fi

View File

@ -1,8 +1,25 @@
#!/usr/bin/env sh
# Copyright Istio Authors
#
# 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.
# Optimize site assets
set -e
svgo --version
npx svgo -r -f content/en
npx svgo -r -f content/zh
npx svgo -r -f src/icons
svgo -r -f content/en
svgo -r -f content/zh
svgo -r -f src/icons

View File

@ -1,31 +0,0 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make updatecommon".
# Copyright 2018 Istio Authors
#
# 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.
set -e
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOTDIR=$(dirname "${SCRIPTPATH}")
img=gcr.io/istio-testing/build-tools:2019-08-18T16-45-52
docker run -i --sig-proxy=true --rm --entrypoint go-bindata --user "$(id -u)" -v /etc/passwd:/etc/passwd:ro -v "${ROOTDIR}:${ROOTDIR}" -w "$(pwd)" ${img} "$@"

View File

@ -1,56 +0,0 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make updatecommon".
# Copyright 2018 Istio Authors
#
# 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.
# Applies requisite code formatters to the source tree
set -e
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOTDIR=$(dirname "${SCRIPTPATH}")
cd "${ROOTDIR}"
# Go format tool to use
# While 'goimports' is preferred we temporarily use 'gofmt' until https://github.com/golang/go/issues/28200 is resolved
GO_FMT_TOOL=goimportsdocker
PKGS=${PKGS:-"."}
if [[ -z ${GO_FILES} ]];then
GO_FILES=$(find "${PKGS}" -type f -name '*.go' ! -name '*.gen.go' ! -name '*.pb.go' ! -name '*mock*.go' | grep -v ./vendor)
fi
# need to pin goimports to align with golangci-lint. SHA is from x/tools repo
if [ $GO_FMT_TOOL = "goimportsdocker" ]; then
GO_IMPORTS_DOCKER="gcr.io/istio-testing/goimports:379209517ffe"
tool="docker run -i --rm -v ${ROOTDIR}:${ROOTDIR} -w ${ROOTDIR} ${GO_IMPORTS_DOCKER} /goimports"
fmt_args="-w -local istio.io"
fi
if [ $GO_FMT_TOOL = "gofmt" ]; then
tool=gofmt
fmt_args="-w"
fi
echo "Formatting the source files"
# shellcheck disable=SC2086
$tool ${fmt_args} ${GO_FILES}
exit $?

View File

@ -1,40 +0,0 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make updatecommon".
# Copyright 2019 Istio Authors
#
# 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.
set -e
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOTDIR=$(dirname "${SCRIPTPATH}")
cd "${ROOTDIR}"
if [[ "$1" == "--fix" ]]
then
FIX="--fix"
fi
# if you want to update this version, also change the version number in .golangci.yml
GOLANGCI_VERSION="v1.16.0"
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$GOPATH"/bin "$GOLANGCI_VERSION"
golangci-lint --version
# For tuning and when switching versions PLEASE REFERENCE: https://github.com/istio/istio/issues/14888
env GOGC=25 golangci-lint run ${FIX} -j 8 -v ./...

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright 2017,2018 Istio Authors. All Rights Reserved.
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ VALUES_YAML = "values.yaml"
ISTIO_IO_DIR = os.path.abspath(__file__ + "/../../")
CONFIG_INDEX_DIR = "content/en/docs/reference/config/installation-options/index.md"
def endOfTheList(context, lineNum, lastLineNum, totalNum):
flag = 0
valueList = []
@ -65,7 +66,7 @@ def endOfTheList(context, lineNum, lastLineNum, totalNum):
elif len(nextLine.lstrip()) != 0 and '#' != nextLine.lstrip()[0] and ':' not in nextLine and len(nextLine.strip()) != 0:
value = nextLine.replace(' ', '')
valueList.append(value.lstrip('-').strip())
flag += 1;
flag += 1
nextLineNum += 1
if lastLineNum == totalNum - 1 and len(currentLine.lstrip()) != 0 and '#' != currentLine.lstrip()[0]:
@ -73,8 +74,10 @@ def endOfTheList(context, lineNum, lastLineNum, totalNum):
return True, valueList
prdict = collections.defaultdict(list)
def decode_helm_yaml(s):
ret_val = ''
#
@ -100,6 +103,7 @@ def decode_helm_yaml(s):
return ret_val
def process_helm_yaml(values_yaml, option):
ret_val = ''
storekey = ''
@ -137,15 +141,15 @@ def process_helm_yaml(values_yaml, option):
key = key.rstrip(string.ascii_letters[::-1] + string.digits + '_' + '-' + '/').rstrip('.')
whitespaces += 1
else:
while (whitespaces < periods) :
while (whitespaces < periods):
key = key.rstrip(string.ascii_letters[::-1] + string.digits + '_' + '-' + '/').rstrip('.')
whitespaces += 1
flag = 0
key = key + '.' + context[lineNum].split(':', 1)[0].strip()
isEnd, ValueList = endOfTheList(context, lineNum, lastLineNum, totalNum)
if isEnd == True:
flag = 1;
if isEnd:
flag = 1
storekey = key
sk = storekey.split('.', 2)
@ -180,7 +184,7 @@ def process_helm_yaml(values_yaml, option):
# the values.yaml under the subcharts directory, it will not be in the newConfigList.
# subcharts directory), then go ahead and process the parameters for this option.
#
if option == '' and prdict.get(storekey) != None and (storekey in newConfigList):
if option == '' and prdict.get(storekey) is not None and (storekey in newConfigList):
pass
#
# This second condition checks if this is the values.yaml file under istio directory, and
@ -189,7 +193,7 @@ def process_helm_yaml(values_yaml, option):
# then add this configuration option to the newConfigList to mark it as an option that
# needs to be processed.
#
elif option == '' and prdict.get(storekey) == None:
elif option == '' and prdict.get(storekey) is None:
newConfigList.append(storekey)
#
# This third condition checks if this is the values.yaml file under istio directory,
@ -198,13 +202,13 @@ def process_helm_yaml(values_yaml, option):
# processed the corresponding values.yaml under the subcharts directory), then ignore
# this configuration option and do not process the values in this file.
#
elif option == '' and prdict.get(storekey) != None:
elif option == '' and prdict.get(storekey) is not None:
continue
if len(context[lastLineNum].lstrip()) != 0 and '#' != context[lastLineNum].lstrip()[0]:
isEnd, ValueList = endOfTheList(context, lineNum, lastLineNum, totalNum)
if (isEnd == True):
if (isEnd):
flag = 1
keysplit = key.split('.')
for kv in keysplit:
@ -214,7 +218,7 @@ def process_helm_yaml(values_yaml, option):
newkey = newkey.lstrip('.')
# Filling Description Fields
if ( "." in newkey):
if ("." in newkey):
plist = newkey.split('.')
da = None
for item in plist:
@ -247,8 +251,8 @@ def process_helm_yaml(values_yaml, option):
ValueStr = (' ').join(ValueList)
if ValueStr:
if (desc in ValueStr):
ValueStr= ValueStr.replace("#"+desc, "")
desc = desc.replace('`','')
ValueStr = ValueStr.replace("#" + desc, "")
desc = desc.replace('`', '')
desc = sanitizeValueStr(desc)
if desc.strip():
desc = '`' + desc.strip() + '`'
@ -261,6 +265,7 @@ def process_helm_yaml(values_yaml, option):
lineNum += 1
return ret_val
def processComments(comments):
description = ''
for c in comments:
@ -280,20 +285,20 @@ def processComments(comments):
# We do not want the commented out key-value pairs (minAvailable,maxUnavailable, secretName)
# to be included as part of the description for 'sessionAffinityEnabled'
#
pattern = re.compile("#\s[-\s]*[\S]+:(?:\s(?!\S+:)\S+)*" )
pattern = re.compile(r"#\s[-\s]*[\S]+:(?:\s(?!\S+:)\S+)*")
groups = pattern.match(comment.value)
if groups:
description=''
description = ''
break
if comment.value.endswith('\n\n'):
description=''
description = ''
else:
if comment.value.rstrip() == '#':
continue
else:
description = description + comment.value.replace('`','').replace("#",'').rstrip()
description = description + comment.value.replace('`', '').replace("#", '').rstrip()
elif isinstance(c, yaml.Token):
description = description + c.value.rstrip().replace("#",'')
description = description + c.value.rstrip().replace("#", '')
return description
@ -309,9 +314,9 @@ def sanitizeValueStr(value):
# was interpreting it as:
# | `global.tracer.lightstep.secure` | `true # example: true |false` | |
#
regex = re.compile("\|")
if value != None and regex.search(value) != None:
value = value.replace("|", "\|");
regex = re.compile(r"\|")
if value is not None and regex.search(value) is not None:
value = value.replace("|", r"\|")
return value
@ -334,16 +339,15 @@ with open(os.path.join(ISTIO_IO_DIR, CONFIG_INDEX_DIR), 'r') as f:
# Print encoded string dictionary
for k, v in od.items():
print ("## `%s` options\n" % k)
print("## `%s` options\n" % k)
print '| Key | Default Value | Description |'
print '| --- | --- | --- |'
for value in v:
print ('%s' % (value))
print ('')
print('%s' % (value))
print('')
for d in data:
if "<!-- AUTO-GENERATED-END -->" in d:
endReached = True
if endReached:
print d

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright 2017,2018 Istio Authors. All Rights Reserved.
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -48,6 +48,7 @@ CONFIG_INDEX_DIR = "content/docs/reference/config/installation-options/index.md"
CONFIG_INDEX_DIFF_DIR = "content/docs/reference/config/installation-options-changes/index.md"
CONFIG_IGNORE_LIST = ["global.hub"]
def endOfTheList(context, lineNum, lastLineNum, totalNum):
flag = 0
valueList = []
@ -71,7 +72,7 @@ def endOfTheList(context, lineNum, lastLineNum, totalNum):
elif len(nextLine.lstrip()) != 0 and '#' != nextLine.lstrip()[0] and ':' not in nextLine and len(nextLine.strip()) != 0:
value = nextLine.replace(' ', '')
valueList.append(value.lstrip('-').strip())
flag += 1;
flag += 1
nextLineNum += 1
if lastLineNum == totalNum - 1 and len(currentLine.lstrip()) != 0 and '#' != currentLine.lstrip()[0]:
@ -79,6 +80,7 @@ def endOfTheList(context, lineNum, lastLineNum, totalNum):
return True, valueList
# ordered dictionary to store the configuration options for the subcomponents of Istio. This
# will be used to populate a new index.md
prdict = collections.defaultdict(list)
@ -89,6 +91,7 @@ od_diff_new = collections.defaultdict(list)
od_diff_removed = collections.defaultdict(list)
od_diff_unchanged = collections.defaultdict(list)
def decode_helm_yaml(s):
ret_val = ''
#
@ -114,6 +117,7 @@ def decode_helm_yaml(s):
return ret_val
def process_helm_yaml(values_yaml, option):
ret_val = ''
storekey = ''
@ -151,15 +155,15 @@ def process_helm_yaml(values_yaml, option):
key = key.rstrip(string.ascii_letters[::-1] + string.digits + '_' + '-' + '/').rstrip('.')
whitespaces += 1
else:
while (whitespaces < periods) :
while (whitespaces < periods):
key = key.rstrip(string.ascii_letters[::-1] + string.digits + '_' + '-' + '/').rstrip('.')
whitespaces += 1
flag = 0
key = key + '.' + context[lineNum].split(':', 1)[0].strip()
isEnd, ValueList = endOfTheList(context, lineNum, lastLineNum, totalNum)
if isEnd == True:
flag = 1;
if isEnd:
flag = 1
storekey = key
sk = storekey.split('.', 2)
@ -194,7 +198,7 @@ def process_helm_yaml(values_yaml, option):
# the values.yaml under the subcharts directory, it will not be in the newConfigList.
# subcharts directory), then go ahead and process the parameters for this option.
#
if option == '' and prdict.get(storekey) != None and (storekey in newConfigList):
if option == '' and prdict.get(storekey) is not None and (storekey in newConfigList):
pass
#
# This second condition checks if this is the values.yaml file under istio directory, and
@ -203,7 +207,7 @@ def process_helm_yaml(values_yaml, option):
# then add this configuration option to the newConfigList to mark it as an option that
# needs to be processed.
#
elif option == '' and prdict.get(storekey) == None:
elif option == '' and prdict.get(storekey) is None:
newConfigList.append(storekey)
#
# This third condition checks if this is the values.yaml file under istio directory,
@ -212,13 +216,13 @@ def process_helm_yaml(values_yaml, option):
# processed the corresponding values.yaml under the subcharts directory), then ignore
# this configuration option and do not process the values in this file.
#
elif option == '' and prdict.get(storekey) != None:
elif option == '' and prdict.get(storekey) is not None:
continue
if len(context[lastLineNum].lstrip()) != 0 and '#' != context[lastLineNum].lstrip()[0]:
isEnd, ValueList = endOfTheList(context, lineNum, lastLineNum, totalNum)
if (isEnd == True):
if (isEnd):
flag = 1
keysplit = key.split('.')
for kv in keysplit:
@ -228,7 +232,7 @@ def process_helm_yaml(values_yaml, option):
newkey = newkey.lstrip('.')
# Filling Description Fields
if ( "." in newkey):
if ("." in newkey):
plist = newkey.split('.')
da = None
for item in plist:
@ -261,8 +265,8 @@ def process_helm_yaml(values_yaml, option):
ValueStr = (' ').join(ValueList)
if ValueStr:
if (desc in ValueStr):
ValueStr= ValueStr.replace("#"+desc, "")
desc = desc.replace('`','')
ValueStr = ValueStr.replace("#" + desc, "")
desc = desc.replace('`', '')
desc = sanitizeValueStr(desc)
if desc.strip():
desc = '`' + desc.strip() + '`'
@ -275,6 +279,7 @@ def process_helm_yaml(values_yaml, option):
lineNum += 1
return ret_val
def processComments(comments):
description = ''
for c in comments:
@ -294,20 +299,20 @@ def processComments(comments):
# We do not want the commented out key-value pairs (minAvailable,maxUnavailable, secretName)
# to be included as part of the description for 'sessionAffinityEnabled'
#
pattern = re.compile("#\s[-\s]*[\S]+:(?:\s(?!\S+:)\S+)*" )
pattern = re.compile(r"#\s[-\s]*[\S]+:(?:\s(?!\S+:)\S+)*")
groups = pattern.match(comment.value)
if groups:
description=''
description = ''
break
if comment.value.endswith('\n\n'):
description=''
description = ''
else:
if comment.value.rstrip() == '#':
continue
else:
description = description + comment.value.replace('`','').replace("#",'').rstrip()
description = description + comment.value.replace('`', '').replace("#", '').rstrip()
elif isinstance(c, yaml.Token):
description = description + c.value.rstrip().replace("#",'')
description = description + c.value.rstrip().replace("#", '')
return description
@ -323,9 +328,9 @@ def sanitizeValueStr(value):
# was interpreting it as:
# | `global.tracer.lightstep.secure` | `true # example: true |false` | |
#
regex = re.compile("\|")
if value != None and regex.search(value) != None:
value = value.replace("|", "\|");
regex = re.compile(r"\|")
if value is not None and regex.search(value) is not None:
value = value.replace("|", r"\|")
return value
# Compares the configuration option value from the newly discovered set of values (stored
@ -351,6 +356,8 @@ def sanitizeValueStr(value):
# k - istio component name for which these configuration options are being processed. This is
# used to populate the contents of 'od_diff' dictionary.
#
def compareValues(oValue, nValue, k):
# oValue and nVAlue contains configuration option in the format:
# '| `<Key>` | `<Value>` | `<Description>` |
@ -366,7 +373,7 @@ def compareValues(oValue, nValue, k):
key = None
if nValue is not None:
groups = re.search("\| \`(.*)\` \| \`(.*)\` \| (.*) |", nValue.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \| (.*) |", nValue.strip())
if groups:
newKey = groups.group(1)
newValue = groups.group(2)
@ -381,7 +388,7 @@ def compareValues(oValue, nValue, k):
oValue.remove(item)
od_diff_unchanged[k].append("| `%s` | `%s` | %s |" % (newKey, newValue.rstrip(), newDesc))
else:
groups = re.search("\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
if groups:
oldKey = groups.group(1)
oldValue = groups.group(2)
@ -399,7 +406,7 @@ def compareValues(oValue, nValue, k):
newValue = 'n/a'
if oldDesc.strip() != newDesc.strip():
if (newDesc == None or newDesc == '') and (oldDesc is None or oldDesc == ''):
if (newDesc is None or newDesc == '') and (oldDesc is None or oldDesc == ''):
pass
if oldDesc is None:
oldDesc = 'n/a'
@ -423,7 +430,7 @@ def compareValues(oValue, nValue, k):
foundItem = 'true'
break
else:
groups = re.search("\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
if groups:
oldKey = groups.group(1)
oldValue = groups.group(2)
@ -444,7 +451,7 @@ def compareValues(oValue, nValue, k):
od_diff_new[k].append("| `%s` | `%s` | %s |" % (newKey, newValue.rstrip(), newDesc))
elif nValue is None:
for item in oValue:
groups = re.search("\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \|\s*(.*)\s*\|", item.strip())
if groups:
oldKey = groups.group(1)
oldValue = groups.group(2)
@ -459,6 +466,8 @@ def compareValues(oValue, nValue, k):
# Get the previous release number so that we can retrieve the index.md for that
# release. The release branches are tagged in the following format: release-<number>
#
def getPreviousRelease():
req = requests.get("https://api.github.com/repos/istio/istio/branches")
jsonData = req.json()
@ -475,8 +484,10 @@ def getPreviousRelease():
#
# Get the index.md for the previous release.
#
def getContentFromPreviousRelease(releaseName):
istio_url = 'https://raw.githubusercontent.com/istio/istio.io/release-' + releaseName +'/content/docs/reference/config/installation-options/index.md'
istio_url = 'https://raw.githubusercontent.com/istio/istio.io/release-' + releaseName + '/content/docs/reference/config/installation-options/index.md'
req = requests.get(istio_url)
content = req.text
indexMap = collections.defaultdict(list)
@ -487,7 +498,7 @@ def getContentFromPreviousRelease(releaseName):
data = content.split('\n')
for d in data:
if d.rstrip() != '' and d != '| Key | Default Value | Description |' and d != '| --- | --- | --- |' and d[0:1] == '|' and d[-1] == '|':
groups = re.search("\| \`(.*)\` \| \`(.*)\` \| (.*) |", d.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \| (.*) |", d.strip())
if groups:
key = groups.group(1)
if key in indexMap:
@ -497,6 +508,7 @@ def getContentFromPreviousRelease(releaseName):
indexMap[key].append(d.strip())
return indexMap
def writeVersionDiffs(index_diff_file):
meta = ""
@ -557,6 +569,7 @@ def writeVersionDiffs(index_diff_file):
index_diff_file.write("\n<!-- AUTO-GENERATED-END -->\n")
index_diff_file.truncate()
with open(os.path.join(ISTIO_IO_DIR, CONFIG_INDEX_DIR), 'r') as f:
endReached = False
key = ''
@ -579,7 +592,7 @@ with open(os.path.join(ISTIO_IO_DIR, CONFIG_INDEX_DIR), 'r') as f:
for value in v:
# Compare configuration option values from the latest version
# with the older version.
groups = re.search("\| \`(.*)\` \| \`(.*)\` \| (.*) |", value.strip())
groups = re.search(r"\| \`(.*)\` \| \`(.*)\` \| (.*) |", value.strip())
if groups:
key = groups.group(1)
indexValue = indexMap.get(key)