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

Presubmit script #539

Merged
merged 6 commits into from
Dec 13, 2022
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
4 changes: 3 additions & 1 deletion bin/gencode
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ if [[ -n $check ]]; then
bin/gencode_docs_examples check
fi

venv/bin/pip3 freeze > $tmpfile
venv_pip3=$(bin/which_venv_pip3)

$venv_pip3 freeze > $tmpfile
if ! diff etc/requirements.txt $tmpfile; then
echo etc/requirements.txt differences found
echo please run bin/setup_base
Expand Down
77 changes: 77 additions & 0 deletions bin/presubmit
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash -e

function banner() {
echo
echo
echo ===========================
echo "$*"
echo ===========================
}

function needs_covg_update() {
local project="$1"
local output=$(find "${project}/src" -name "*.java" -newer "${project}/build/reports/jacoco/test/jacocoTestReport.xml")
test -n "${output}" # 0=needs, 1=does not need
}

function needs_gencode_update() {
bin/gencode check
}

function needs_gencode_seq_update() {
return 0 # needs
}

function reset_needs() {
needs="0"
}

function add_needs() {
needs=$["${needs}"+1]
}

function genscript() {
echo running: "$@"
local rc="$?"
"$@"
echo exit status: $rc
return $rc
}

#
# Main
#

ROOT_DIR=$(realpath $(dirname $0)/..)
cd $ROOT_DIR

# Generate code coverage
banner "Code Coverage"
reset_needs
for project in pubber validator; do
needs_covg_update "${project}" && add_needs
done

if [[ ${needs} -gt 0 ]]; then
genscript $ROOT_DIR/bin/gencovg
fi

# Generate code from schemas
banner "Gencode from schemas"
reset_needs
needs_gencode_update && add_needs

if [[ ${needs} -gt 0 ]]; then
genscript $ROOT_DIR/bin/gencode
fi

# Generate code for sequencer.md
banner "Gencode for sequencer.md"
reset_needs
needs_gencode_seq_update && add_needs

if [[ ${needs} -gt 0 ]]; then
genscript $ROOT_DIR/bin/gencode_seq
fi

# Done
3 changes: 2 additions & 1 deletion bin/setup_base
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sudo apt-get install -y hxtools moreutils expect mosquitto mosquitto-clients
python3 --version
python3 -m venv venv

venv/bin/pip3 install -r etc/requirements.txt
venv_pip3=$($(dirname $0)/which_venv_pip3)
${venv_pip3} install -r etc/requirements.txt
10 changes: 10 additions & 0 deletions bin/which_venv_pip3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -e
for f in venv/bin/pip3 $HOME/venv/bin/pip3; do
if [[ -x "$f" ]]; then
echo "$f"
exit 0
fi
done

>&2 echo Cannot find venv
false