Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script File Linting #1584

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/generate_krew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function generate_platform {
fi

local sha
PLATFORM=`uname`
PLATFORM=$(uname)
if [ "$PLATFORM" == 'Darwin' ]; then
sha=$(curl -L https://github.com/kudobuilder/kudo/releases/download/v"${VERSION}"/kudo_"${VERSION}"_"${1}"_"${ARCH}".tar.gz | shasum -a 256 - | awk '{print $1}')
else
Expand Down
65 changes: 39 additions & 26 deletions hack/gh-md-toc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,25 @@ gh_toc_md2html() {
local gh_file_md=$1
URL=https://api.github.com/markdown/raw

if [ ! -z "$GH_TOC_TOKEN" ]; then
if [ -n "$GH_TOC_TOKEN" ]; then
TOKEN=$GH_TOC_TOKEN
else
TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
if [ -f "$TOKEN_FILE" ]; then
TOKEN="$(cat $TOKEN_FILE)"
TOKEN=$(cat "$TOKEN_FILE")
fi
fi
if [ ! -z "${TOKEN}" ]; then
if [ -n "${TOKEN}" ]; then
AUTHORIZATION="--header \"Authorization: token ${TOKEN}\""
fi

# echo $URL 1>&2
OUTPUT="$(curl -s --user-agent "$gh_user_agent" \
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
${AUTHORIZATION} \
"$AUTHORIZATION" \
$URL)"

# shellcheck disable=SC2181
if [ "$?" != "0" ]; then
echo "XXNetworkErrorXX"
fi
Expand Down Expand Up @@ -123,7 +124,8 @@ gh_toc(){
echo
fi
else
local rawhtml=$(gh_toc_md2html "$gh_src")
local rawhtml
rawhtml=$(gh_toc_md2html "$gh_src")
if [ "$rawhtml" == "XXNetworkErrorXX" ]; then
echo "Parsing local markdown file requires access to github API"
echo "Please make sure curl is installed and check your network connectivity"
Expand All @@ -136,39 +138,46 @@ gh_toc(){
echo "or place GitHub auth token here: ${TOKEN_FILE}"
exit 1
fi
local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"`
local toc
toc=$(echo "$rawhtml" | gh_toc_grab "$gh_src_copy")
echo "$toc"
if [ "$need_replace" = "yes" ]; then
if grep -Fxq "<!--ts-->" $gh_src && grep -Fxq "<!--te-->" $gh_src; then
if grep -Fxq "<!--ts-->" "$gh_src" && grep -Fxq "<!--te-->" "$gh_src"; then
echo "Found markers"
else
echo "You don't have <!--ts--> or <!--te--> in your file...exiting"
exit 1
fi
local ts="<\!--ts-->"
local te="<\!--te-->"
local dt=`date +'%F_%H%M%S'`
local ext=".orig.${dt}"
local toc_path="${gh_src}.toc.${dt}"
local toc_footer="<!-- Added by: `whoami`, at: `date` -->"
local ts
ts="<\!--ts-->"
local te
te="<\!--te-->"
local dt
dt=$(date +'%F_%H%M%S')
local ext
ext=".orig.${dt}"
local toc_path
toc_path="${gh_src}.toc.${dt}"
local toc_footer
toc_footer="<!-- Added by: $(whoami), at: $(date) -->"
# http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
# clear old TOC
sed -i${ext} "/${ts}/,/${te}/{//!d;}" "$gh_src"
sed -i"${ext}" "/${ts}/,/${te}/{//!d;}" "$gh_src"
# create toc file
echo "${toc}" > "${toc_path}"
echo -e "\n${toc_footer}\n" >> "$toc_path"
# insert toc file
if [[ "`uname`" == "Darwin" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
sed -i "" "/${ts}/r ${toc_path}" "$gh_src"
else
sed -i "/${ts}/r ${toc_path}" "$gh_src"
fi
echo
if [ $no_backup = "yes" ]; then
rm ${toc_path} ${gh_src}${ext}
if [ "$no_backup" = "yes" ]; then
rm "${toc_path}" "${gh_src}${ext}"
fi
echo "!! TOC was added into: '$gh_src'"
if [ -z $no_backup ]; then
if [ -z "$no_backup" ]; then
echo "!! Origin version of the file: '${gh_src}${ext}'"
echo "!! TOC added into a separate file: '${toc_path}'"
fi
Expand Down Expand Up @@ -218,10 +227,12 @@ gh_toc_get_filename() {
# Options handlers
#
gh_toc_app() {
local need_replace="no"
local need_replace
need_replace="no"

if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
local app_name=$(basename "$0")
local app_name
app_name=$(basename "$0")
echo "GitHub TOC generator ($app_name): $gh_toc_version"
echo ""
echo "Usage:"
Expand All @@ -236,26 +247,28 @@ gh_toc_app() {
if [ "$1" = '--version' ]; then
echo "$gh_toc_version"
echo
echo "os: `lsb_release -d | cut -f 2`"
echo "kernel: `cat /proc/version`"
echo "shell: `$SHELL --version`"
echo "os: $(lsb_release -d | cut -f 2)"
echo "kernel: $(cat /proc/version)"
echo "shell: $($SHELL --version)"
echo
for tool in curl wget grep awk sed; do
printf "%-5s: " $tool
echo `$tool --version | head -n 1`
# shellcheck disable=SC2005
echo "$($tool --version | head -n 1)"
done
return
fi

# shellcheck disable=SC2166
if [ "$1" = "-" ]; then
if [ -z "$TMPDIR" ]; then
TMPDIR="/tmp"
TMPDIR="/tmp"
elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then
mkdir -p "$TMPDIR"
fi
local gh_tmp_md
gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX)
while read input; do
while read -r input; do
echo "$input" >> "$gh_tmp_md"
done
gh_toc_md2html "$gh_tmp_md" | gh_toc_grab ""
Expand Down
6 changes: 3 additions & 3 deletions hack/update_kep_overview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ KEP_FILES="$SCRIPT_HOME/../keps/????-*"
KEP_OVERVIEW_FILE="$SCRIPT_HOME/../keps/README.md"

# Overview header
cat <<EOT > $KEP_OVERVIEW_FILE
cat <<EOT > "$KEP_OVERVIEW_FILE"
# KUDO Enhancement Proposals

*This file is autogenerated*
Expand All @@ -31,7 +31,7 @@ do

# Extract fields from header
KEP_NUMBER=$(echo "$KEP_HEADER" | sed -n -E 's/kep-number: ([0-9]+)/\1/p')
KEP_NUMBER=$(echo "$KEP_NUMBER" | sed 's/^0*//') # Strip leading zeros, or we interpret in octal
KEP_NUMBER="$((10#$KEP_NUMBER))" # Strip leading zeros, or we interpret in octal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can keep this as it was? The echo and sed makes it pretty clear what's happening, but this new way seems kind of exotic to me?

Not a blocker though, the comment says what it does, so i guess it's ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ANeumann82 I actually think what you had was easier to read or understand as well :( shellcheck failure

KEP_NUMBER=$(printf %04d "$KEP_NUMBER") # Fill up to 4 digits again

KEP_TITLE=$(echo "$KEP_HEADER" | sed -n -E 's/title: (.*)/\1/p')
Expand All @@ -56,5 +56,5 @@ do
KEP_DESC=$(echo "$KEP_HEADER" | sed -n -E 's/short-desc: (.*)/\1/p')

# Print one line for this KEP
echo "| [$KEP_NUMBER - $KEP_TITLE]($KEP_FILE) | $KEP_ICON | $KEP_STATUS | $KEP_DESC |" >> $KEP_OVERVIEW_FILE
echo "| [$KEP_NUMBER - $KEP_TITLE]($KEP_FILE) | $KEP_ICON | $KEP_STATUS | $KEP_DESC |" >> "$KEP_OVERVIEW_FILE"
done
2 changes: 1 addition & 1 deletion hack/verify-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RETVAL=$?

if [[ ${RETVAL} != 0 ]]; then
echo "Running 'make generate' produces changes to the current git status. Maybe you forgot to check-in your updated generated files?"
echo "The current diff: `git diff`"
echo "The current diff: $(git diff)"
exit 1
fi

Expand Down