tests: move static checks and dependencies from tests

Move static checks scripts and dependencies from tests to
kata-containers repo.

Fixes #8187

Signed-off-by: Amulyam24 <amulmek1@in.ibm.com>
Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
Signed-off-by: Bin Liu <bin@hyper.sh>
Signed-off-by: Carlos Venegas <jos.c.venegas.munoz@intel.com>
Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
Signed-off-by: Dan Middleton <dan.middleton@intel.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Derek Lee <derlee@redhat.com>
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Signed-off-by: Eric Ernst <eric_ernst@apple.com>
Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
Signed-off-by: Gabriela Cervantes <gabriela.cervantes.tellez@intel.com>
Signed-off-by: Ganesh Maharaj Mahalingam <ganesh.mahalingam@intel.com>
Signed-off-by: Graham Whaley <graham.whaley@intel.com>
Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
Signed-off-by: Jon Olson <jonolson@google.com>
Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
Signed-off-by: Julio Montes <julio.montes@intel.com>
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
Signed-off-by: Marco Vedovati <mvedovati@suse.com>
Signed-off-by: Nitesh Konkar <niteshkonkar@in.ibm.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Salvador Fuentes <salvador.fuentes@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: Xu Wang <xu@hyper.sh>
Signed-off-by: Yang Bo <bo@hyper.sh>
Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
Chelsea Mafrica 2023-11-21 17:41:49 -08:00
parent 891f488ee3
commit eaa6b1b274
5 changed files with 1625 additions and 0 deletions

2
tests/.gitignore vendored
View File

@ -1 +1,3 @@
cmd/check-markdown/kata-check-markdown
cmd/github-labels/kata-github-labels
integration/kubernetes/runtimeclass_workloads_work/

33
tests/.golangci.yml Normal file
View File

@ -0,0 +1,33 @@
# Copyright (c) 2017 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
run:
concurrency: 4
deadline: 600s
skip-dirs:
- vendor
# Ignore auto-generated protobuf code.
skip-files:
- ".*\\.pb\\.go$"
linters:
disable-all: true
enable:
- gocyclo
- gofmt
- gosimple
- govet
- ineffassign
- misspell
- staticcheck
- typecheck
- unused
linters-settings:
gocyclo:
min_complexity: 15
unused:
check-exported: true
govet:
enable:

27
tests/go.mod Normal file
View File

@ -0,0 +1,27 @@
module github.com/kata-containers/tests
go 1.19
require (
github.com/BurntSushi/toml v0.3.1
github.com/montanaflynn/stats v0.0.0-20151014174947-eeaced052adb
github.com/olekukonko/tablewriter v0.0.6-0.20210304033056-74c60be0ef68
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.1
github.com/urfave/cli v1.22.0
gopkg.in/russross/blackfriday.v2 v2.0.0-00010101000000-000000000000
gopkg.in/yaml.v2 v2.4.0
)
require (
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday v1.6.0 // indirect
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
replace gopkg.in/russross/blackfriday.v2 => github.com/russross/blackfriday/v2 v2.1.0

229
tests/kata-doc-to-script.sh Executable file
View File

@ -0,0 +1,229 @@
#!/bin/bash
license="
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
"
set -e
[ -n "$DEBUG" ] && set -x
script_name="${0##*/}"
typeset -r warning="WARNING: Do *NOT* run the generated script without reviewing it carefully first!"
# github markdown markers used to surround a code block. All text within the
# markers is rendered in a fixed font.
typeset -r bash_block_open="\`\`\`bash"
typeset -r block_open="\`\`\`"
typeset -r block_close="\`\`\`"
# GitHub issue templates have a special metadata section at the top delimited
# by this string. See:
#
# https://raw.githubusercontent.com/kata-containers/.github/master/.github/ISSUE_TEMPLATE/bug_report.md
typeset -r metadata_block='---'
# Used to delimit inline code blocks
typeset -r backtick="\`"
# convention used in all documentation to represent a non-privileged users
# shell prompt. All lines starting with this value inside a code block are
# commands the user should run.
typeset -r code_prompt="\$ "
# files are expected to match this regular expression
typeset -r extension_regex="\.md$"
strict="no"
require_commands="no"
check_only="no"
invert="no"
verbose="no"
usage()
{
cat <<EOF
Usage: ${script_name} [options] <markdown-file> [<script-file> [<description>]]
This script will convert a github-flavoured markdown document file into a
bash(1) script to stdout by extracting the bash code blocks.
Options:
-c : check the file but don't create the script (sets exit code).
-h : show this usage.
-i : invert output (remove code blocks and inline code, displaying the
remaining parts of the document). Incompatible with '-c'.
-r : require atleast one command block to be found.
-s : strict mode - perform extra checks.
-v : verbose mode.
Example usage:
$ ${script_name} foo.md foo.md.sh
Notes:
- If a description is specified, it will be added to the script as a
comment.
- <script-file> may be specified as '-' meaning send output to stdout.
Limitations:
- The script is unable to handle embedded code blocks like this:
\`\`\`
\`\`\`bash
\$ echo code in an embedded set of backticks
\`\`\`
\`\`\`
To overcome this issue, ensure that the outer set of backticks are replaced
with an HTML PRE tag:
<pre>
\`\`\`bash
\$ echo code in an embedded set of backticks
\`\`\`
</pre>
This will both render correctly on GitHub and allow this script to remove
the code block.
Note: this solves one problem but introduces another - this script will not
remove the HTML tags.
${warning}
EOF
exit 0
}
die()
{
local msg="$*"
echo "ERROR: $msg" >&2
exit 1
}
script_header()
{
local -r description="$1"
cat <<-EOF
#!/bin/bash
${license}
#----------------------------------------------
# WARNING: Script auto-generated from '$file'.
#
# ${warning}
#----------------------------------------------
#----------------------------------------------
# Description: $description
#----------------------------------------------
# fail the entire script if any simple command fails
set -e
EOF
}
# Convert the specified github-flavoured markdown format file
# into a bash script by extracting the bash blocks.
doc_to_script()
{
file="$1"
outfile="$2"
description="$3"
invert="$4"
[ -n "$file" ] || die "need file"
[ "${check_only}" = "no" ] && [ -z "$outfile" ] && die "need output file"
[ "$outfile" = '-' ] && outfile="/dev/stdout"
if [ "$invert" = "yes" ]
then
# First, remove code blocks.
# Next, remove inline code in backticks.
# Finally, remove a metadata block as used in GitHub issue
# templates.
cat "$file" |\
sed -e "/^[ \>]*${block_open}/,/^[ \>]*${block_close}/d" \
-e "s/${backtick}[^${backtick}]*${backtick}//g" \
-e "/^${metadata_block}$/,/^${metadata_block}$/d" \
> "$outfile"
return
fi
all=$(mktemp)
body=$(mktemp)
cat "$file" |\
sed -n "/^ *${bash_block_open}/,/^ *${block_close}/ p" |\
sed -e "/^ *${block_close}/ d" \
-e "s/^ *${code_prompt}//g" \
-e 's/^ *//g' > "$body"
[ "$require_commands" = "yes" ] && [ ! -s "$body" ] && die "no commands found in file '$file'"
script_header "$description" > "$all"
cat "$body" >> "$all"
# sanity check
[ "$check_only" = "yes" ] && redirect="1>/dev/null 2>/dev/null"
{ local ret; eval bash -n "$all" $redirect; ret=$?; } || true
[ "$ret" -ne 0 ] && die "shell code in file '$file' is not valid"
# create output file
[ "$check_only" = "no" ] && cp "$all" "$outfile"
# clean up
rm -f "$body" "$all"
}
main()
{
while getopts "chirsv" opt
do
case $opt in
c) check_only="yes" ;;
h) usage ;;
i) invert="yes" ;;
r) require_commands="yes" ;;
s) strict="yes" ;;
v) verbose="yes" ;;
esac
done
shift $(($OPTIND - 1))
file="$1"
outfile="$2"
description="$3"
[ -n "$file" ] || die "need file"
[ "$verbose" = "yes" ] && echo "INFO: processing file '$file'"
if [ "$strict" = "yes" ]
then
echo "$file"|grep -q "$extension_regex" ||\
die "file '$file' doesn't match pattern '$extension_regex'"
fi
doc_to_script "$file" "$outfile" "$description" "$invert"
}
main "$@"

1334
tests/static-checks.sh Executable file

File diff suppressed because it is too large Load Diff