Commit 09c94ab2 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat(acceptance): add hook scripts support

parent f8f0c17e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -508,4 +508,11 @@ or through a basic `environment_url.txt` file, then the {{cookiecutter.template_

:warning: all our deployment templates implement this design. Therefore even purely dynamic environments (such as review
environments) will automatically be propagated to your {{cookiecutter.template_name}} tests.

### Hook scripts

The {{cookiecutter.template_name}} template supports _optional_ **hook scripts** from your project, located in the `${{cookiecutter.template_PREFIX}}_PROJECT_DIR` directory to perform additional project-specific logic:

* `pre-{{cookiecutter.project_slug}}.sh` is executed **before** running {{cookiecutter.template_name}},
* `post-{{cookiecutter.project_slug}}.sh` is executed **after** running {{cookiecutter.template_name}} (whichever the tests status).
{%- endif %}
+19 −8
Original line number Diff line number Diff line
@@ -492,7 +492,10 @@ stages:
    done
  }

  function exec_hook() {
  function maybe_exec_hook() {
    if [[ -f "$1" ]]
    then
      log_info "\\e[33;1m$1\\e[0m hook found: execute"
      if [[ ! -x "$1" ]] && ! chmod +x "$1"
      then
        log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
@@ -501,6 +504,7 @@ stages:
      else
        "$1"
      fi
    fi
  }
{% if cookiecutter.template_type == 'build' %}
  function output_coverage() {
@@ -936,7 +940,14 @@ stages:
    # TODO: run {{ cookiecutter.cli_tool }} tests
    # TODO (if possible): $TRACE set enables debug logs on the tool
    - mkdir -p -m 777 reports
    - {{ cookiecutter.cli_tool }} run ${TRACE+--verbose} --env BASE_URL=${{ cookiecutter.template_PREFIX }}_BASE_URL --junit --output=reports/{{ cookiecutter.project_slug }}.xunit.xml ${{ cookiecutter.template_PREFIX }}_EXTRA_ARGS
    # maybe execute pre hook
    - maybe_exec_hook "./pre-{{ cookiecutter.project_slug }}.sh"
    # run tests
    - {{ cookiecutter.cli_tool }} run ${TRACE+--verbose} --env BASE_URL=${{ cookiecutter.template_PREFIX }}_BASE_URL --junit --output=reports/{{ cookiecutter.project_slug }}.xunit.xml ${{ cookiecutter.template_PREFIX }}_EXTRA_ARGS || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-{{ cookiecutter.project_slug }}.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always