Skip to content

Commit 6984411

Browse files
authored
Merge pull request #49 from rtCamp/add/php-build-support
Add PHP build support with customizable environment variables
2 parents 94ad89b + 516e3ce commit 6984411

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:24.04
22

33
ARG DEBIAN_FRONTEND=noninteractive
44

@@ -9,9 +9,10 @@ LABEL "com.github.actions.description"="Deploy WordPress code to a server"
99
LABEL "org.opencontainers.image.source"="https://github.com/rtCamp/action-deploy-wordpress"
1010

1111

12-
ENV PATH "/composer/vendor/bin:~/.local/bin:$PATH"
13-
ENV COMPOSER_ALLOW_SUPERUSER 1
14-
ENV COMPOSER_HOME /composer
12+
ENV PATH="/composer/vendor/bin:~/.local/bin:$PATH"
13+
ENV COMPOSER_ALLOW_SUPERUSER=1
14+
ENV COMPOSER_HOME=/composer
15+
ENV DEFAULT_PHP_VERSION=7.4
1516

1617
RUN apt update && \
1718
apt install -y \
@@ -27,7 +28,7 @@ RUN apt update && \
2728
add-apt-repository ppa:ondrej/php && \
2829
apt update && \
2930
apt-get install -y php7.4-cli php7.4-curl php7.4-json php7.4-mbstring php7.4-xml php7.4-iconv php7.4-yaml && \
30-
pip3 install shyaml && \
31+
pip3 install shyaml --break-system-packages && \
3132
rm -rf /var/lib/apt/lists/*
3233

3334
# Setup wp-cli

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,49 @@ This GitHub action's behavior can be customized using following environment vari
8585
| `NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend. |
8686
| `NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment. |
8787
| `NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation. |
88+
| `PHP_BUILD_DIRECTORY` | null | Path to valid directory | Directory to run PHP build commands/scripts in. |
89+
| `PHP_BUILD_COMMAND` | null | Any shell command | Command to run for building PHP dependencies or other PHP build steps. |
90+
| `PHP_BUILD_SCRIPT` | null | Path to valid shell script | Custom or predefined script to run for PHP build steps. |
8891

89-
All node related variables are completely optional. You can use them if your site needs to have node dependencies built.
92+
All node and php related variables are completely optional. You can use them if your site needs to have such dependencies built.
93+
94+
### PHP Build Support
95+
96+
You can now run custom PHP build steps before deployment by setting the following environment variables in your workflow:
97+
98+
```yaml
99+
env:
100+
PHP_VERSION: "8.1"
101+
PHP_BUILD_DIRECTORY: "./"
102+
PHP_BUILD_COMMAND: "composer install --no-dev"
103+
PHP_BUILD_SCRIPT: "./scripts/php-build.sh"
104+
```
105+
106+
- `PHP_VERSION`: Installs the specified PHP version before running build steps.
107+
- `PHP_BUILD_DIRECTORY`: Directory to change into before running build commands/scripts.
108+
- `PHP_BUILD_COMMAND`: Shell command to run for PHP build (e.g., `composer install`).
109+
- `PHP_BUILD_SCRIPT`: Path to a shell script to execute for PHP build steps.
110+
111+
### Node Build Support
112+
113+
You can also run custom Node.js build steps before deployment by setting the following environment variables in your workflow:
114+
115+
```yaml
116+
env:
117+
NODE_VERSION: "20"
118+
NPM_VERSION: "10"
119+
NODE_BUILD_DIRECTORY: "./frontend"
120+
NODE_BUILD_COMMAND: "npm run build"
121+
NODE_BUILD_SCRIPT: "./scripts/node-build.sh"
122+
```
123+
124+
- `NODE_VERSION`: Installs the specified Node.js version before running build steps.
125+
- `NPM_VERSION`: Installs the specified npm version (defaults to latest if not set).
126+
- `NODE_BUILD_DIRECTORY`: Directory to change into before running build commands/scripts.
127+
- `NODE_BUILD_COMMAND`: Shell command to run for Node.js build (e.g., `npm run build`).
128+
- `NODE_BUILD_SCRIPT`: Path to a shell script to execute for Node.js build steps.
129+
130+
These steps will be executed before PHP build steps.
90131

91132
## Server Setup
92133

main.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,42 @@ function maybe_run_node_build() {
203203
fi
204204
}
205205

206+
function maybe_install_php_dep() {
207+
208+
VALID_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
209+
if [[ -z "$PHP_VERSION" ]]; then
210+
echo "No PHP version specified. Skipping PHP setup."
211+
return
212+
fi
213+
214+
if [[ ! " ${VALID_PHP_VERSIONS[@]} " =~ " ${PHP_VERSION} " ]]; then
215+
echo "Invalid PHP version specified: $PHP_VERSION"
216+
echo "Valid versions are: ${VALID_PHP_VERSIONS[*]}"
217+
exit 1
218+
fi
219+
220+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
221+
apt install -y software-properties-common && \
222+
add-apt-repository ppa:ondrej/php && \
223+
apt update && \
224+
apt-get install -y php"$PHP_VERSION"-cli php"$PHP_VERSION"-curl php"$PHP_VERSION"-mbstring php"$PHP_VERSION"-xml php"$PHP_VERSION"-iconv php"$PHP_VERSION"-yaml
225+
226+
update-alternatives --set php /usr/bin/php${PHP_VERSION}
227+
}
228+
229+
function maybe_run_php_build() {
230+
231+
[[ -n "$PHP_BUILD_DIRECTORY" ]] && cd "$PHP_BUILD_DIRECTORY"
232+
[[ -n "$PHP_BUILD_COMMAND" ]] && eval "$PHP_BUILD_COMMAND"
233+
234+
if [[ -n "$PHP_BUILD_SCRIPT" ]]; then
235+
chmod +x "$PHP_BUILD_SCRIPT"
236+
./"$PHP_BUILD_SCRIPT"
237+
fi
238+
239+
update-alternatives --set php /usr/bin/php${DEFAULT_PHP_VERSION}
240+
}
241+
206242
function setup_wordpress_files() {
207243

208244
mkdir -p "$HTDOCS"
@@ -332,9 +368,11 @@ function main() {
332368
setup_hosts_file
333369
check_branch_in_hosts_file
334370
setup_ssh_access
371+
maybe_install_submodules
335372
maybe_install_node_dep
336373
maybe_run_node_build
337-
maybe_install_submodules
374+
maybe_install_php_dep
375+
maybe_run_php_build
338376
setup_wordpress_files
339377
block_emails
340378
deploy

0 commit comments

Comments
 (0)