Skip to content

Introduce after_script which will be executed after the command #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
```
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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}