blockerbugs/run
Jaroslav Groman 3d54a63596
Some checks failed
Run tests and linters / test (pull_request) Successful in 2m58s
Run tests and linters / lint (pull_request) Failing after 2s
Add ruff configuration and docs
Co-authored-by: Kamil Paral <kparal@redhat.com>
Related: #306
2026-06-08 15:56:11 +02:00

172 lines
4.8 KiB
Bash
Executable file

#!/bin/bash
# Copyright Red Hat
# License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+>
# See the LICENSE file for more details on Licensing
# This is the main entrypoint for running commands as a developer. Use --help to show available
# commands.
set -o errexit -o nounset -o pipefail
# This makes sure the development config gets loaded for all operations.
# TODO: Investigate whether we can make the dev config the default and avoid setting this variable.
export DEV=true
function print_usage_and_exit {
cat << EOF
Usage: $0 [app|cli|test|coverage|lint|docs|setup|archive|clean|help] [COMMAND ARGUMENTS...]
Run a developer-related command. Note that some commands require the database to
be already running, and most require the virtualenv to be active.
Available commands:
app: Start the web-based blockerbugs app.
cli: Execute the blockerbugs CLI runner (the same one as is accessible as
'blockerbugs' command when installed). Use '$0 cli --help' for help.
test: Execute the test suite.
coverage: Execute the test suite and measure test coverage. Create a report in
build/coverage/.
lint: Run supported linters.
docs: Build the documentation, placed into build/docs/.
setup: Perform an initial DB setup and configure current release, milestones
and bug trackers. Can be re-executed when there is a new release.
archive: Create a git archive from the current commit, placed into
build/archive/.
clean: Delete all build artifacts, also including archives, docs, coverage
reports, etc.
help: Show this usage message.
EOF
exit 1
}
# Run the main program loop
function main {
if [ $# -eq 0 ]; then
print_usage_and_exit
fi
case "$1" in
app)
run_app;;
cli)
# Forward any cmdline arguments
shift
run_cli "$@";;
test)
run_test;;
coverage)
run_coverage;;
lint)
run_lint;;
docs)
run_docs;;
setup)
run_setup;;
archive)
run_archive;;
clean)
run_clean;;
help | --help | -h)
print_usage_and_exit;;
*)
print_usage_and_exit;;
esac
}
function run_app {
local cmd='python scripts/runapp.py'
echo "Executing command: $cmd"
exec $cmd
}
function run_cli {
local cmd_array=(python blockerbugs/cli.py "$@")
echo "Executing command:" "${cmd_array[@]}"
"${cmd_array[@]}"
}
function run_test {
local cmd='pytest'
echo "Executing command: $cmd"
exec $cmd
}
function run_coverage {
local cmd='pytest --cov'
echo "Executing command: $cmd"
exec $cmd
}
function run_lint {
local cmd='mypy'
local mypy_rc=0
echo "Executing command: $cmd"
echo "********************** mypy **********************"
$cmd && mypy_rc=$? || mypy_rc=$?
echo
cmd='ruff check'
local ruff_check_rc=0
echo "Executing command: $cmd"
echo "********************** ruff check **********************"
$cmd && ruff_check_rc=$? || ruff_check_rc=$?
echo
cmd='ruff format --check'
local ruff_format_rc=0
echo "Executing command: $cmd"
echo "********************** ruff format **********************"
$cmd && ruff_format_rc=$? || ruff_format_rc=$?
# If one of them returned non-zero, return a global non-zero
if [ "$mypy_rc" -eq 0 ] && [ "$ruff_check_rc" -eq 0 ] && [ "$ruff_format_rc" -eq 0 ]; then
exit 0
else
exit 1
fi
}
function run_docs {
local cmd='sphinx-build -W -b html docs/source build/docs/html'
echo "Executing command: $cmd"
$cmd
cmd='cp docs/source/*.md build/docs/html/'
echo "Executing command: $cmd"
exec $cmd
}
function run_setup {
# init_db is non-destructive, doesn't wipe existing data (but performs db upgrades)
run_cli init_db
run_cli add_release -r 40
run_cli add_milestone -r 40 -m beta -b 2187792 -a 2187793
run_cli add_milestone -r 40 -m final -b 2187794 -a 2187795
}
function run_archive {
if ! git diff --quiet; then
echo "WARNING: Local repo is dirty. The archive won't include uncommitted files!"
fi
local version
version="$(git describe)"
if echo $version | grep -E -q -- '-[0-9]+-g'; then
echo "WARNING: The current commit doesn't have an annotated tag, the app version will be "\
"'unknown'!"
fi
mkdir -p build/archive
# TODO: Consider using `setup.py sdist` instead of `git archive`. Works better with versioneer.
local cmd_array=(git archive HEAD "--prefix=blockerbugs-${version}/" --format tar.gz
-o "build/archive/blockerbugs-${version}.tar.gz")
echo "Executing command:" "${cmd_array[@]}"
exec "${cmd_array[@]}"
}
function run_clean {
cmd='rm -rf blockerbugs.egg-info/ build/'
echo "Executing command: $cmd"
exec $cmd
}
# Run the main program loop
main "$@"