Skip to content

Allow PHP Versions to Update #17

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 7 commits into from
Apr 28, 2024
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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Fast builds for repositories using php-actions.
# Fast builds for repositories using php-actions

v1 of this repository used a totally different architecture and had different goals to the current version. Previously, a customised Dockerfile was used as the base for all php-actions repositories, but now php-actions workflows run as [composite run steps][composite], building a customised docker image per-application, based off the official PHP script.

Expand All @@ -25,7 +25,7 @@ Choosing the PHP version

The `ACTION_PHP_VERSION` environment variable must be passed to the composite run step. This string must match any of the [officially supported PHP version numbers][tag-list] (version number only, with no derivative text, e.g. `8.0.1` or `8` rather than `8-cli`).

The official Alpine CLI build of the requested version will be used as the image's base.
The official Alpine CLI build of the requested version will be used as the image's base.

Enabling/disabling extensions
-----------------------------
Expand All @@ -46,7 +46,7 @@ Version caching php-build

This repo, `php-build` shouldn't change very regularly, but when it does, the entire build pipeline of dependent repositories will need refreshing. This is done by adding the version of `php-build` to the end of build package names. When a new release is made that affects php-build functionality, the variable at the top of `php-build.bash` can be updated to invalidate any caches.

Within other repositories that use `php-build`, they can refer to the specific version of the script by addressing its git commit hash. For example: https://raw.githubusercontent.com/php-actions/php-build/27be075494ae8a9bc0d10deb408e37b197986b8a/php-build.bash
Within other repositories that use `php-build`, they can refer to the specific version of the script by addressing its git commit hash. For example: <https://raw.githubusercontent.com/php-actions/php-build/27be075494ae8a9bc0d10deb408e37b197986b8a/php-build.bash>

***

Expand All @@ -57,5 +57,4 @@ If you found this repository helpful, please consider [sponsoring the developer]
[tag-list]: https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links
[mlocati]: https://github.com/mlocati/docker-php-extension-installer
[mlocati-readme]: https://github.com/mlocati/docker-php-extension-installer#supported-php-extensions
[issues]: https://github.com/php-actions/php-build/issues
[sponsor]: https://github.com/sponsors/g105b
24 changes: 20 additions & 4 deletions php-build.bash
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

php_build_version="build2.1.1"
php_build_version="build2.2.1"

# Check for required variables:
if [ "$#" -lt 1 ]; then
Expand Down Expand Up @@ -88,8 +88,8 @@ dockerfile_unique="${dockerfile_unique,,}"
repo_without_org=$(echo "$GITHUB_REPOSITORY" | sed "s/[^\/]*\///")

# This tag will be used to identify the built dockerfile. Once it is built,
# it should not need to be built again, so after the first Github Actions run
# the build should be very quick.
# it should not need to be built again unless there is a PHP update, so after
# the first Github Actions run the build should be very quick.
# Note: The GITHUB_REPOSITORY is the repo where the action is running, nothing
# to do with the php-actions organisation. This means that the image is pushed
# onto a user's Github profile (currently not shared between other users).
Expand All @@ -104,7 +104,23 @@ echo "Pulling $docker_tag" >> output.log 2>&1
# No need to continue building the image if the pull was successful.
if docker pull "$docker_tag" >> output.log 2>&1;
then
exit
# Unless the PHP version has an update...

# Pull latest PHP Docker image so we can check its version.
echo "Pulling $base_image" >> output.log 2>&1
docker pull "$base_image" >> output.log 2>&1

# Check PHP versions of the latest PHP tag and our tag.
base_image_php_version=$(docker run -i "$base_image" php -r "echo PHP_VERSION;")
cached_image_php_version=$(docker run -i "$docker_tag" php -r "echo PHP_VERSION;")

echo "Comparing $cached_image_php_version (cached) to $base_image_php_version (latest)." >> output.log 2>&1

# No need to continue building if our image already exists and PHP is up-to-date.
if [ $cached_image_php_version == $base_image_php_version ];
then
exit
fi
fi

echo "Building PHP $ACTION_PHP_VERSION with extensions: $ACTION_PHP_EXTENSIONS ..."
Expand Down