Skip to content

Introduce before_script which will be executed prior the command #102

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 4 commits 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ The JSON string should represent an object with the following information:
"command": "command to run to perform the check (empty in case you dont want to excecute any command)",
"additional_composer_arguments": [
"arguments which will be passed to `composer install` or `composer update`, passed as a list or as a list; e.g. --no-scripts"
],
"before_script": [
"tool configuration linting",
"tool specific setting overrides",
"specific composer dependency to be installed prior executing command"
]
}
```
Expand Down Expand Up @@ -113,6 +118,8 @@ The `.laminas-ci/pre-run.sh` command runs immediately prior to the QA command, a
- `$2`: the WORKDIR path
- `$3`: the `$JOB` passed to the entrypoint (see above)

It is also possible to pass `before_script` with a list of commands via the `$JOB` variable.

The `.laminas-ci/post-run.sh` command will receive these arguments:

- `$1`: the exit status of the QA command
Expand Down Expand Up @@ -219,6 +226,7 @@ The container the action provides and consumes builds off the ubuntu:focal image
- 7.3
- 7.4
- 8.0
- 8.1

Each provides the following extensions by default:

Expand Down
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

set -e
set -o pipefail

function help {
echo "$0 <JSON>"
Expand All @@ -14,6 +15,7 @@ function help {
echo " - dependencies: the dependency set to run against (lowest, latest, locked)"
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 ""
}

Expand Down Expand Up @@ -138,6 +140,9 @@ if [[ "${PHP}" == "" ]];then
exit 1
fi

declare -a BEFORE_SCRIPT=()
readarray -t BEFORE_SCRIPT="$(echo "${JOB}" | jq -rc '(.before_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 @@ -216,6 +221,11 @@ if [ -x ".laminas-ci/pre-run.sh" ];then
./.laminas-ci/pre-run.sh testuser "${PWD}" "${JOB}"
fi

for BEFORE_SCRIPT_COMMAND in "${BEFORE_SCRIPT[@]}"; do
echo "Running before_script: ${BEFORE_SCRIPT_COMMAND}"
sudo --preserve-env --set-home -u testuser /bin/bash -c "${BEFORE_SCRIPT_COMMAND}"
done

# Disable exit-on-non-zero flag so we can run post-commands
set +e

Expand Down