Skip to content

Commit

Permalink
Add github action to run tests on pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
GMartinez-Sisti authored and jcmoraisjr committed Jul 8, 2021
1 parent d931adf commit 608e78d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Test

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

on:
pull_request:

jobs:

test:
name: Test
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Run
run: |
cd test
./run.sh
30 changes: 26 additions & 4 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ function log_entry() {

}

# ci_log_group_* functions are used to make Github Actions output cleaner
function ci_log_group_start(){
local LOG_TYPE="${1:?Needs log type}"
local LOG_MSG="${2:?Needs log message}"

if [ -n "${CI:-}" ]; then
echo "::group::${LOG_MSG}"
else
ci_log_entry "${LOG_TYPE}" "${LOG_MSG}"
fi
}

function ci_log_group_end {
if [ -n "${CI:-}" ]; then
echo "::endgroup::"
fi
}

function containers_down {

log_entry "INFO" "Terminating containers"
Expand All @@ -29,14 +47,18 @@ trap containers_down EXIT SIGHUP SIGINT SIGTERM

# Run

log_entry "INFO" "Build containers"
ci_log_group_start "INFO" "Build containers"
docker-compose -p "$PROJECT_NAME" build
ci_log_group_end

log_entry "INFO" "Starting containers"
ci_log_group_start "INFO" "Starting containers"
docker-compose -p "$PROJECT_NAME" up --force-recreate --detach haproxy
ci_log_group_end

log_entry "INFO" "Running tests"
ci_log_group_start "INFO" "Running tests"
docker-compose -p "$PROJECT_NAME" run client
ci_log_group_end

log_entry "INFO" "Showing logs"
ci_log_group_start "INFO" "Showing logs"
docker-compose -p "$PROJECT_NAME" logs modsecurity-spoa | grep -v "clients connected"
ci_log_group_end

0 comments on commit 608e78d

Please sign in to comment.