diff --git a/README.md b/README.md index 8d0f4b5..2a8768c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,9 @@ The JSON string should represent an object with the following information: "tool configuration linting", "tool specific setting overrides", "specific composer dependency to be installed prior executing command" + ], + "after_script": [ + "post process tool result" ] } ``` @@ -127,6 +130,9 @@ The `.laminas-ci/post-run.sh` command will receive these arguments: - `$3`: the WORKDIR path - `$4`: the `$JOB` passed to the entrypoint (see above) +It is also possible to pass `after_script` with a list of commands via the `$JOB` variable. +`$STATUS` is a variable containing the exit code of the command and can be used in the commands listed in `after_script`. + #### Parsing the $JOB You may want to grab elements of the `$JOB` argument in order to branch logic. diff --git a/entrypoint.sh b/entrypoint.sh index 75fc60b..405fcc0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,7 @@ function help { echo " - ignore_php_platform_requirement: flag to enable/disable the PHP platform requirement when executing composer \`install\` or \`update\`" echo " - additional_composer_arguments: a list of composer arguments to be added when \`install\` or \`update\` is called." echo " - before_script: a list of commands to run before the real command" + echo " - after_script: a list of commands to run after the real command" echo "" } @@ -143,6 +144,10 @@ fi declare -a BEFORE_SCRIPT=() readarray -t BEFORE_SCRIPT="$(echo "${JOB}" | jq -rc '(.before_script // [])[]' )" +declare -a AFTER_SCRIPT=() +readarray -t AFTER_SCRIPT="$(echo "${JOB}" | jq -rc '(.after_script // [])[]' )" + + echo "Marking PHP ${PHP} as configured default" update-alternatives --quiet --set php "/usr/bin/php${PHP}" update-alternatives --quiet --set php-config "/usr/bin/php-config${PHP}" @@ -241,4 +246,9 @@ if [ -x ".laminas-ci/post-run.sh" ];then ./.laminas-ci/post-run.sh "${STATUS}" testuser "${PWD}" "${JOB}" fi +for AFTER_SCRIPT_COMMAND in "${AFTER_SCRIPT[@]}"; do + echo "Running before_script: ${AFTER_SCRIPT_COMMAND}" + sudo --preserve-env --set-home -u testuser /bin/bash -c "${AFTER_SCRIPT_COMMAND}" +done + exit ${STATUS}