Code from github.com/anakrish/rego-rs

Authored by anakrish and mingweishih

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-02-09 10:56:54 -08:00
parent 8f67aeecb0
commit cb0b3a1790
85 changed files with 11144 additions and 0 deletions

49
scripts/coverage Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
if ! command -v grcov > /dev/null; then
cargo install grcov
fi
if ! command -v llvm-profdata > /dev/null; then
rustup component add llvm-tools-preview
fi
#export LLVM_PROFILE_FILE='target/cargo-test-%p-%m.profraw'
#export CARGO_INCREMENTAL=1
#export RUSTFLAGS='-Cinstrument-coverage'
echo "Building with instrumentation"
cargo build --all-targets
if [ "$1" == "--no-run" ]; then
exit 0
fi
# Remove existing coverage information.
rm -f target/*.profraw
rm -rf target/coverage
mkdir -p target/coverage
echo "Running tests"
cargo test
# Generate html
grcov target/ --binary-path ./target/x86_64-unknown-linux-musl/debug/deps -s src/ -t html \
--branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html
if [ "$1" == "--show" ]; then
echo "Opening report in browser"
xdg-open target/coverage/html/src/index.html 2>/dev/null
echo "Done"
fi
# Generate markdown
grcov target/ --binary-path ./target/x86_64-unknown-linux-musl/debug/deps -s src/ -t markdown \
--branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/markdown
cat target/coverage/markdown
#TODO: Maybe use coveralls format (json) and query data to lockdown code coverage.

15
scripts/make-docs Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
git stash
cargo doc --no-deps
git checkout docs
rm -rf docs
cp -r target/x86_64-unknown-linux-musl/doc ./docs
echo "<meta http-equiv=\"refresh\" content=\"0; url=rego_rs/index.html\">" > docs/index.html
git add docs
git commit -s
git push
git checkout -
git stash pop

25
scripts/pre-commit Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -eo pipefail
if [ -f Cargo.toml ]; then
# Ensure that all targets can be built.
scripts/coverage --no-run
#Ensure that code is correctly formatted.
cargo fmt --check || (echo "Run cargo fmt to fix formatting" && exit 1)
# Ensure that clippy warnings are addressed.
cargo clippy --all-targets --no-deps -- -Dwarnings
# Ensure that all modifications are included.
# TODO refine status checking.
if git status -s | grep -e "MM " -e "??" -e "AM " -e " M " > /dev/null; then
printf "\nUnstaged changes found:\n"
git status -s | grep -e "MM " -e "??" -e "AM " -e " M "
echo "Stage them and try again"
exit 1
fi
fi

15
scripts/pre-push Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -eo pipefail
if [ -f Cargo.toml ]; then
# Run precommit checks
dir=$(dirname "${BASH_SOURCE[0]}")
"$dir/pre-commit"
# Ensure that all tests pass
# Also generate coverage information.
scripts/coverage
fi

13
scripts/rego-eval Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
rego=$(realpath -e $1)
if [ ! -z "$2" ]; then
input=$(realpath -e $2)
cargo test interpreter::one_file -- --include-ignored --nocapture "$rego" "$input"
else
cargo test interpreter::one_file -- --include-ignored --nocapture "$rego"
fi

27
scripts/rego-lex Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
usage="usage: rego-lex <policy.rego> [-v]"
if [ -z "$1" ]; then
echo "$usage"
exit 1
fi
rego=$(realpath -e $1)
case "$2" in
"-v")
verbose="verbose"
;;
*)
if [ ! -z "$2" ]; then
echo "$usage"
exit 1
fi
esac
eval "cargo test lexer::one_file -- --include-ignored --nocapture $rego $verbose"

8
scripts/rego-parse Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
rego=$(realpath -e $1)
cargo test parser::one_file -- --include-ignored --nocapture "$rego"

8
scripts/yaml-test-eval Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
yaml=$(realpath -e $1)
RUST_BACKTRACE=1 cargo test interpreter::one_yaml -- --include-ignored --nocapture "$yaml"

8
scripts/yaml-test-parse Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
set -e
yaml=$(realpath -e $1)
RUST_BACKTRACE=1 cargo test parser::one_yaml -- --include-ignored --nocapture "$yaml"