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