Skip to content

Commit

Permalink
Trigger an image rebuild if there are new php releases
Browse files Browse the repository at this point in the history
Similarly to what we already do, rebuilding images when
a new timezonedb version is detected, this commit adds
a new check looking for the existence of new PHP releases
using this URL: https://www.php.net/releases/?json&version=8.0-anything

Note that it may be the case of the new version already released
and the docker image still not being available, but that doesn't
matter much, because in the next execution (currently every 3 days)
it will be tried and rebuilt again.
  • Loading branch information
stronk7 committed Aug 5, 2023
1 parent a98d0f9 commit 645d482
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions .github/workflows/trigger_new_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,61 @@ jobs:
fi
echo "result=$result" >> $GITHUB_OUTPUT
# This job compares the currently used php version in the docker images
# with the latests php release available @ https://www.php.net/releases/?json&version=X.Y
# If different, a rebuilt will be triggered.
php-new-release:
# Completely avoid forks and pull requests to try this job.
if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch"]'), github.event_name)
runs-on: ubuntu-latest

outputs:
trigger_build: ${{ steps.calculate.outputs.result }}
docker_tag: ${{ steps.calculate.outputs.tag }}

steps:

- name: Configuring git vars
uses: rlespinasse/github-slug-action@v4

- name: Compare current and latest php versions
id: calculate
run: |
# Calculate current image version
# If the branch has has X.Y-xxxxx format, use it as docker tag. Else, use "dev" image (master branch).
tag=dev
if [[ "${{ env.GITHUB_REF_SLUG }}" =~ [0-9]+\.[0-9]+\-[a-z]+ ]]; then
tag=${{ env.GITHUB_REF_SLUG }}
fi
echo "LOG: docker tag: $tag"
echo "tag=$tag" >> $GITHUB_OUTPUT
# Extract the php version from the image.
current=$(docker run -t --rm moodlehq/moodle-php-apache:$tag php -r 'echo PHP_VERSION;')
echo "LOG: current: $current"
# Look for the latest version available @ https://www.php.net/releases/?json&version=X.Y-whatever
latest=$(curl -s "https://www.php.net/releases/?json&version=$tag" | jq -r '.version' || true)
echo "LOG: latest: $latest"
# Compare the versions (digits only), if current < latest, then we need to rebuild.
# (but only if it's not an alpha, beta, rc version, aka, only if it's a pure numerical version)
result='false'
if [[ ! $current =~ ^[0-9\.]+$ ]]; then
echo "LOG: current version ($current) is not stable, skipping"
elif [[ ${current//[!0-9]/} -lt ${latest//[!0-9]/} ]]; then
result='true'
echo "LOG: new php release to trigger image build"
fi
echo "result=$result" >> $GITHUB_OUTPUT
# This job gets the results of all the jobs in the workflow and,
# if any of them has ended with the "trigger_build" output set, then
# will set its own (final) trigger_build output to 'true'.
evaluate-results:
runs-on: ubuntu-latest
needs: [datetimedb-new-release]
needs: [datetimedb-new-release, php-new-release]

outputs:
trigger_build: ${{ steps.evaluate.outputs.result }}
Expand All @@ -72,7 +121,8 @@ jobs:
run: |
# Add here more conditions (ORed) when new criteria are added.
result=false
if [[ "${{ needs.datetimedb-new-release.outputs.trigger_build }}" == "true" ]]; then
if [[ "${{ needs.datetimedb-new-release.outputs.trigger_build }}" == "true" ]] ||
[[ "${{ needs.php-new-release.outputs.trigger_build }}" == "true" ]]; then
result=true
echo "LOG: Final evaluation, trigger the build"
fi
Expand Down

0 comments on commit 645d482

Please sign in to comment.