Skip to content

Commit 645d482

Browse files
committed
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.
1 parent a98d0f9 commit 645d482

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

.github/workflows/trigger_new_builds.yml

+52-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,61 @@ jobs:
5454
fi
5555
echo "result=$result" >> $GITHUB_OUTPUT
5656
57+
# This job compares the currently used php version in the docker images
58+
# with the latests php release available @ https://www.php.net/releases/?json&version=X.Y
59+
# If different, a rebuilt will be triggered.
60+
php-new-release:
61+
# Completely avoid forks and pull requests to try this job.
62+
if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch"]'), github.event_name)
63+
runs-on: ubuntu-latest
64+
65+
outputs:
66+
trigger_build: ${{ steps.calculate.outputs.result }}
67+
docker_tag: ${{ steps.calculate.outputs.tag }}
68+
69+
steps:
70+
71+
- name: Configuring git vars
72+
uses: rlespinasse/github-slug-action@v4
73+
74+
- name: Compare current and latest php versions
75+
id: calculate
76+
run: |
77+
# Calculate current image version
78+
# If the branch has has X.Y-xxxxx format, use it as docker tag. Else, use "dev" image (master branch).
79+
tag=dev
80+
if [[ "${{ env.GITHUB_REF_SLUG }}" =~ [0-9]+\.[0-9]+\-[a-z]+ ]]; then
81+
tag=${{ env.GITHUB_REF_SLUG }}
82+
fi
83+
echo "LOG: docker tag: $tag"
84+
echo "tag=$tag" >> $GITHUB_OUTPUT
85+
86+
# Extract the php version from the image.
87+
current=$(docker run -t --rm moodlehq/moodle-php-apache:$tag php -r 'echo PHP_VERSION;')
88+
echo "LOG: current: $current"
89+
90+
# Look for the latest version available @ https://www.php.net/releases/?json&version=X.Y-whatever
91+
latest=$(curl -s "https://www.php.net/releases/?json&version=$tag" | jq -r '.version' || true)
92+
echo "LOG: latest: $latest"
93+
94+
# Compare the versions (digits only), if current < latest, then we need to rebuild.
95+
# (but only if it's not an alpha, beta, rc version, aka, only if it's a pure numerical version)
96+
result='false'
97+
if [[ ! $current =~ ^[0-9\.]+$ ]]; then
98+
echo "LOG: current version ($current) is not stable, skipping"
99+
elif [[ ${current//[!0-9]/} -lt ${latest//[!0-9]/} ]]; then
100+
result='true'
101+
echo "LOG: new php release to trigger image build"
102+
fi
103+
echo "result=$result" >> $GITHUB_OUTPUT
104+
105+
57106
# This job gets the results of all the jobs in the workflow and,
58107
# if any of them has ended with the "trigger_build" output set, then
59108
# will set its own (final) trigger_build output to 'true'.
60109
evaluate-results:
61110
runs-on: ubuntu-latest
62-
needs: [datetimedb-new-release]
111+
needs: [datetimedb-new-release, php-new-release]
63112

64113
outputs:
65114
trigger_build: ${{ steps.evaluate.outputs.result }}
@@ -72,7 +121,8 @@ jobs:
72121
run: |
73122
# Add here more conditions (ORed) when new criteria are added.
74123
result=false
75-
if [[ "${{ needs.datetimedb-new-release.outputs.trigger_build }}" == "true" ]]; then
124+
if [[ "${{ needs.datetimedb-new-release.outputs.trigger_build }}" == "true" ]] ||
125+
[[ "${{ needs.php-new-release.outputs.trigger_build }}" == "true" ]]; then
76126
result=true
77127
echo "LOG: Final evaluation, trigger the build"
78128
fi

0 commit comments

Comments
 (0)