Skip to content

Commit 7b76f82

Browse files
committed
feature: add after_script support
Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 85fccc7 commit 7b76f82

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ The JSON string should represent an object with the following information:
4444
"tool configuration linting",
4545
"tool specific setting overrides",
4646
"specific composer dependency to be installed prior executing command"
47+
],
48+
"after_script": [
49+
"post process tool result"
4750
]
4851
}
4952
```
@@ -127,6 +130,9 @@ The `.laminas-ci/post-run.sh` command will receive these arguments:
127130
- `$3`: the WORKDIR path
128131
- `$4`: the `$JOB` passed to the entrypoint (see above)
129132

133+
It is also possible to pass `after_script` with a list of commands via the `$JOB` variable.
134+
`$STATUS` is a variable containing the exit code of the command and can be used in the commands listed in `after_script`.
135+
130136
#### Parsing the $JOB
131137

132138
You may want to grab elements of the `$JOB` argument in order to branch logic.

entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function help {
1616
echo " - ignore_php_platform_requirement: flag to enable/disable the PHP platform requirement when executing composer \`install\` or \`update\`"
1717
echo " - additional_composer_arguments: a list of composer arguments to be added when \`install\` or \`update\` is called."
1818
echo " - before_script: a list of commands to run before the real command"
19+
echo " - after_script: a list of commands to run after the real command"
1920
echo ""
2021
}
2122

@@ -143,6 +144,10 @@ fi
143144
declare -a BEFORE_SCRIPT=()
144145
readarray -t BEFORE_SCRIPT="$(echo "${JOB}" | jq -rc '(.before_script // [])[]' )"
145146

147+
declare -a AFTER_SCRIPT=()
148+
readarray -t AFTER_SCRIPT="$(echo "${JOB}" | jq -rc '(.after_script // [])[]' )"
149+
150+
146151
echo "Marking PHP ${PHP} as configured default"
147152
update-alternatives --quiet --set php "/usr/bin/php${PHP}"
148153
update-alternatives --quiet --set php-config "/usr/bin/php-config${PHP}"
@@ -241,4 +246,9 @@ if [ -x ".laminas-ci/post-run.sh" ];then
241246
./.laminas-ci/post-run.sh "${STATUS}" testuser "${PWD}" "${JOB}"
242247
fi
243248

249+
for AFTER_SCRIPT_COMMAND in "${AFTER_SCRIPT[@]}"; do
250+
echo "Running before_script: ${AFTER_SCRIPT_COMMAND}"
251+
sudo --preserve-env --set-home -u testuser /bin/bash -c "${AFTER_SCRIPT_COMMAND}"
252+
done
253+
244254
exit ${STATUS}

0 commit comments

Comments
 (0)