|
| 1 | +name: Trigger new builds based on various criteria. |
| 2 | + |
| 3 | +# If any of the criteria happens, they set the trigger_build |
| 4 | +# output variable to 'true' and the rebuild will happen. |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + schedule: |
| 9 | + # Fridays 16:00 UTC |
| 10 | + - cron: '10 16 * * 5' |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + # This job compares the currently used timezonedb extension version |
| 15 | + # in the docker images with the latest timezonedb release (tag) available |
| 16 | + # @ https://github.com/php/pecl-datetime-timezonedb repository. |
| 17 | + # If different, a rebuilt will be triggered. |
| 18 | + datetimedb-new-release: |
| 19 | + # Completely avoid forks and pull requests to try this job. |
| 20 | + if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch", "schedule"]'), github.event_name) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + outputs: |
| 24 | + trigger_build: ${{ steps.calculate.outputs.result }} |
| 25 | + |
| 26 | + steps: |
| 27 | + |
| 28 | + - name: Configuring git vars |
| 29 | + uses: rlespinasse/github-slug-action@v4 |
| 30 | + |
| 31 | + - name: Compare current and latest datetimedb versions |
| 32 | + id: calculate |
| 33 | + run: | |
| 34 | + # Calculate current image version |
| 35 | + # If the branch has has X.Y-xxxxx format, use it as docker tag. Else, use "dev" image (master branch). |
| 36 | + tag=dev |
| 37 | + if [[ ${{ env.GITHUB_REF_SLUG }} =~ \d+\.\d+\-\w+ ]]; then |
| 38 | + tag=${{ env.GITHUB_REF_SLUG }} |
| 39 | + fi |
| 40 | + echo "LOG: docker tag: $tag" |
| 41 | +
|
| 42 | + # Extract the timezonedb version from the image. |
| 43 | + current=$(docker run -t --rm moodlehq/moodle-php-apache:$tag php -r 'echo timezone_version_get();') |
| 44 | + echo "LOG: current: $current" |
| 45 | +
|
| 46 | + # Look for the latest tag available @ https://github.com/php/pecl-datetime-timezonedb |
| 47 | + latest=$(curl -s "https://api.github.com/repos/php/pecl-datetime-timezonedb/tags" | jq -r '.[0].name') |
| 48 | + echo "LOG: latest: $latest" |
| 49 | +
|
| 50 | + # Compare the versions (digits only), if current < latest, then we need to rebuild. |
| 51 | + if [[ ${current//[!0-9]/} -lt ${latest//[!0-9]/} ]]; then |
| 52 | + echo "result=true" >> $GITHUB_OUTPUT |
| 53 | + echo "LOG: timezonedb to trigger image build" |
| 54 | + fi |
| 55 | +
|
| 56 | + # This job gets the results of all the jobs in the workflow and, |
| 57 | + # if any of them has ended with the "trigger_build" output set, then |
| 58 | + # will set its own (final) trigger_build output to 'true'. |
| 59 | + evaluate: |
| 60 | + # Completely avoid forks and pull requests to try this job. |
| 61 | + if: github.repository_owner == 'moodlehq' && contains(fromJson('["workflow_dispatch", "schedule"]'), github.event_name) |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: [datetimedb-new-release] |
| 64 | + |
| 65 | + outputs: |
| 66 | + trigger_build: ${{ steps.evaluate.outputs.trigger }} |
| 67 | + |
| 68 | + steps: |
| 69 | + |
| 70 | + - name: Evaluate if we have to trigger a build |
| 71 | + id: evaluate |
| 72 | + run: | |
| 73 | + # Add here more conditions (ORed) when new criteria are added. |
| 74 | + if [[ ${{ needs.datetimedb-new-release.outputs.trigger_build }} ]]; then |
| 75 | + echo "trigger=true" >> $GITHUB_OUTPUT |
| 76 | + echo "LOG: Final evaluation, trigger the build" |
| 77 | + fi |
| 78 | +
|
| 79 | + Build: |
| 80 | + # Only if the final workflow.outputs.trigger_build from evaluate job has decided to build. |
| 81 | + if: ${{ needs.evaluate.outputs.trigger_build }} == 'true' |
| 82 | + needs: [evaluate] |
| 83 | + |
| 84 | + # Launch the build job (as reusable workflow). |
| 85 | + uses: ./.github/workflows/test_buildx_and_publish.yml |
| 86 | + secrets: inherit |
0 commit comments