Skip to content
Snippets Groups Projects
Commit 09c94ab2 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat(acceptance): add hook scripts support

parent f8f0c17e
No related branches found
No related tags found
No related merge requests found
......@@ -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 %}
......@@ -492,14 +492,18 @@ stages:
done
}
function exec_hook() {
if [[ ! -x "$1" ]] && ! chmod +x "$1"
function maybe_exec_hook() {
if [[ -f "$1" ]]
then
log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
# fallback technique
sh "$1"
else
"$1"
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)"
# fallback technique
sh "$1"
else
"$1"
fi
fi
}
{% if cookiecutter.template_type == 'build' %}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment