From 645d48237b6e4a11b33ac3b0683eabfd7c12a33e Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 5 Aug 2023 14:39:32 +0200 Subject: [PATCH] Trigger an image rebuild if there are new php releases 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. --- .github/workflows/trigger_new_builds.yml | 54 +++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trigger_new_builds.yml b/.github/workflows/trigger_new_builds.yml index 42d75b4..84fb22c 100644 --- a/.github/workflows/trigger_new_builds.yml +++ b/.github/workflows/trigger_new_builds.yml @@ -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 }} @@ -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