diff options
author | neoninteger | 2019-06-21 19:53:00 +0930 |
---|---|---|
committer | neoninteger | 2019-06-21 19:53:00 +0930 |
commit | cbc8cb171b9c6c1138124c474266046f242ceeff (patch) | |
tree | b5b1a7f103e199841abdce83ea778527d45b9663 | |
parent | 884ccf7086039ca94a339560c590938ae6731b2f (diff) | |
download | aur-cbc8cb171b9c6c1138124c474266046f242ceeff.tar.gz |
Implement more foolproof check() step
* The check() step has been divided into "modules" which can be run
independently of each other.
* This then allows the individual steps (create directories -> initialise
database cluster and start SQL server -> configure database and start Turtl
server -> generate configuration and run tests -> shut down Turtl server ->
shut down SQL server -> remove directories) to be run individually, with
traps set up to perform the necessary de-initialization should one step fail.
* This is important as makepkg's default behaviour is to stop as soon as a
command returns with a non-zero exit code. Trapping errors in this manner
allows us to perform the proper database and server cleanup regardless of
whether or not the tests succeeded.
* The output of commands is also no longer redirected to /dev/null, and the
log messages are bolded and coloured to look like makepkg messages.
-rw-r--r-- | .SRCINFO | 2 | ||||
-rw-r--r-- | PKGBUILD | 104 |
2 files changed, 69 insertions, 37 deletions
@@ -1,7 +1,7 @@ pkgbase = turtl-core-rs pkgdesc = Turtl's logic core, built in Rust pkgver = 0.1.2 - pkgrel = 1 + pkgrel = 2 url = https://github.com/turtl/core-rs arch = i686 arch = x86_64 @@ -1,7 +1,7 @@ # Maintainer: Callum Parsey <neoninteger@protonmail.com> pkgname=turtl-core-rs pkgver=0.1.2 -pkgrel=1 +pkgrel=2 pkgdesc="Turtl's logic core, built in Rust" arch=("i686" "x86_64") url="https://github.com/turtl/core-rs" @@ -30,44 +30,76 @@ build() { } check() { + cd "core-rs-${_commithash}" export TURTL_DB_CONNSTR="postgres://turtl:turtl@localhost:5432/turtl" export TURTL_UPLOADS_LOCAL="$PWD/turtl-uploads" - echo "- Creating PostgreSQL database cluster..." - mkdir turtl-db turtl-uploads - initdb -D turtl-db -A trust > /dev/null - - echo "- Starting PostgreSQL server..." - pg_ctl start -D turtl-db -o '-c unix_socket_directories=/tmp' > /dev/null - - echo "- Creating role/database for Turtl server..." - psql -q -h /tmp -d postgres -c "CREATE USER turtl WITH PASSWORD 'turtl'" - psql -q -h /tmp -d postgres -c "CREATE DATABASE turtl" - - echo "- Initializing Turtl server database/upload directory..." - bash -c "cd /usr/share/webapps/turtl && scripts/init-db.sh" > /dev/null - bash -c "cd /usr/share/webapps/turtl && node tools/populate-test-data.js" > /dev/null - - echo "- Starting Turtl server..." - node /usr/share/webapps/turtl/server.js > /dev/null & - sleep 2 - - echo "- Generating core-rs configuration..." - cd "core-rs-${_commithash}" - sed '/^ endpoint: /c\ endpoint: "http://localhost"' config.yaml.default > config.yaml - - echo "- Running core-rs tests..." - make test - - echo "- Shutting down Turtl server..." - cd .. - kill %1 - - echo "- Shutting down PostgreSQL server..." - pg_ctl stop -D turtl-db > /dev/null - - echo "- Cleaning up..." - rm -rf turtl-db turtl-uploads "core-rs-${_commithash}/config.yaml" + log() { + echo -e " $(tput setaf 4)$(tput bold)->$(tput sgr0) $(tput bold)$@$(tput sgr0)" + } + + init_dirs() { + mkdir turtl-db turtl-uploads + } + + init_database() { + log "Initializing PostgreSQL database cluster..." + initdb -D turtl-db -A trust + + log "Starting PostgreSQL server..." + pg_ctl start -D turtl-db -o "-c unix_socket_directories=/tmp" + } + + configure_turtl_server() { + log "Configuring database for Turtl server..." + psql -h /tmp -d postgres -c "CREATE USER turtl WITH PASSWORD 'turtl'" + psql -h /tmp -d postgres -c "CREATE DATABASE turtl" + bash -c "cd /usr/share/webapps/turtl && scripts/init-db.sh" + bash -c "cd /usr/share/webapps/turtl && node tools/populate-test-data.js" + + log "Starting Turtl server..." + node /usr/share/webapps/turtl/server.js & + sleep 2 + } + + run_tests() { + log "Running tests..." + sed '/^ endpoint: /c\ endpoint: ""' config.yaml.default > config.yaml + make test-st + } + + stop_turtl_server() { + log "Stopping Turtl server..." + kill %1 + } + + stop_database() { + log "Stopping PostgreSQL server..." + pg_ctl stop -D turtl-db + } + + remove_dirs() { + log "Cleaning up..." + rm -rf turtl-db turtl-uploads config.yaml + } + + init_dirs + + trap "remove_dirs" ERR + init_database + trap - ERR + + trap "stop_database && remove_dirs" ERR + configure_turtl_server + trap - ERR + + trap "stop_turtl_server && stop_database && remove_dirs" ERR + run_tests + trap - ERR + + stop_turtl_server + stop_database + remove_dirs } package() { |