-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New workflow to trigger automatic image builds
This is executed daily and performs various checks: - Is there a newer timezonedb extension available. - (more coming soon). And, if there is any of the checks happening, it automatically dispatches a reposity_dispatch (auto-build-triggered) event, causing the test and build workflow to be triggered. Now the test & build workflow supports workflow_call events That way we can make other workflows in the repository to, conditionally, launch a rebuild when some conditions are met: - When there is a new version of an extension. - When there is a new PHP release. - After X days - ... Note this is related to https://tracker.moodle.org/browse/MDL-76675 Also, update some actions to use new nodejs versions and avoid some deprecation warnings.
- Loading branch information
Showing
2 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Trigger new builds based on various criteria. | ||
|
||
# If any of the criteria happens, they set the trigger_build | ||
# output variable to 'true' and the rebuild will happen. | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
# Fridays 16:00 UTC | ||
- cron: '10 16 * * 5' | ||
|
||
jobs: | ||
|
||
# This job compares the currently used timezonedb extension version | ||
# in the docker images with the latest timezonedb release (tag) available | ||
# @ https://github.com/php/pecl-datetime-timezonedb repository. | ||
# If different, a rebuilt will be triggered. | ||
datetimedb-new-release: | ||
# Completely avoid forks and pull requests to try this job. | ||
if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch", "schedule"]'), github.event_name) | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
trigger_build: ${{ steps.calculate.outputs.result }} | ||
|
||
steps: | ||
|
||
- name: Configuring git vars | ||
uses: rlespinasse/github-slug-action@v4 | ||
|
||
- name: Compare current and latest datetimedb 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 }} =~ \d+\.\d+\-\w+ ]]; then | ||
tag=${{ env.GITHUB_REF_SLUG }} | ||
fi | ||
echo "LOG: docker tag: $tag" | ||
# Extract the timezonedb version from the image. | ||
current=$(docker run -t --rm moodlehq/moodle-php-apache:$tag php -r 'echo timezone_version_get();') | ||
echo "LOG: current: $current" | ||
# Look for the latest tag available @ https://github.com/php/pecl-datetime-timezonedb | ||
latest=$(curl -s "https://api.github.com/repos/php/pecl-datetime-timezonedb/tags" | jq -r '.[0].name') | ||
echo "LOG: latest: $latest" | ||
# Compare the versions (digits only), if current < latest, then we need to rebuild. | ||
if [[ ${current//[!0-9]/} -lt ${latest//[!0-9]/} ]]; then | ||
echo "result=true" >> $GITHUB_OUTPUT | ||
echo "LOG: timezonedb to trigger image build" | ||
fi | ||
# 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: | ||
# Completely avoid forks and pull requests to try this job. | ||
if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch", "schedule"]'), github.event_name) | ||
runs-on: ubuntu-latest | ||
needs: [datetimedb-new-release] | ||
|
||
outputs: | ||
trigger_build: ${{ steps.evaluate.outputs.trigger }} | ||
|
||
steps: | ||
|
||
- name: Evaluate if we have to trigger a build | ||
id: evaluate | ||
run: | | ||
# Add here more conditions (ORed) when new criteria are added. | ||
if [[ ${{ needs.datetimedb-new-release.outputs.trigger_build }} ]]; then | ||
echo "trigger=true" >> $GITHUB_OUTPUT | ||
echo "LOG: Final evaluation, trigger the build" | ||
fi | ||
Build: | ||
# Only if the final workflow.outputs.trigger_build from evaluate job has decided to build. | ||
if: ${{ needs.evaluate.outputs.trigger_build }} == 'true' | ||
needs: [evaluate] | ||
|
||
# Launch the build job (as reusable workflow). | ||
uses: ./.github/workflows/test_buildx_and_publish.yml | ||
secrets: inherit |