Skip to content

Commit

Permalink
Switch from reusable workflow to workflow_dispatch events
Browse files Browse the repository at this point in the history
Main reason being that, when using reusable workflow
the workflow is literally embed into the called one and
that makes badges and integrations to stop working.

We want the "Test and publish" workflow to be executed
standalone, hence, invoking it via workflow_dispatch.
  • Loading branch information
stronk7 committed Jan 27, 2023
1 parent b54f61c commit a5411f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_buildx_and_publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test and publish
name: Test, build and publish

on:
push:
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push to Docker Hub and Github registries
- name: Build and publish to Docker Hub and Github registries
uses: docker/build-push-action@v3
with:
context: .
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/trigger_new_builds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Trigger new builds
name: Conditional new builds

# If any of the criteria happens, they set the trigger_build
# output variable to 'true' and the rebuild will happen.
Expand All @@ -19,6 +19,7 @@ jobs:

outputs:
trigger_build: ${{ steps.calculate.outputs.result }}
docker_tag: ${{ steps.calculate.outputs.tag }}

steps:

Expand All @@ -35,13 +36,14 @@ jobs:
tag=${{ env.GITHUB_REF_SLUG }}
fi
echo "LOG: docker tag: $tag"
echo "tag=$tag" >> $GITHUB_OUTPUT
# 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')
latest=$(curl -s "https://api.github.com/repos/php/pecl-datetime-timezonedb/tags" | jq -r '.[0].name' || true)
echo "LOG: latest: $latest"
# Compare the versions (digits only), if current < latest, then we need to rebuild.
Expand All @@ -56,13 +58,12 @@ jobs:
# 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:
# 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
needs: [datetimedb-new-release]

outputs:
trigger_build: ${{ steps.evaluate.outputs.result }}
docker_tag: ${{ needs.datetimedb-new-release.outputs.docker_tag }}

steps:

Expand All @@ -80,8 +81,12 @@ jobs:
build:
# Only if the final workflow.outputs.trigger_build from evaluate job has decided to build.
if: needs.evaluate-results.outputs.trigger_build == 'true'
runs-on: ubuntu-latest
needs: [evaluate-results]

# Launch the build job (as reusable workflow).
uses: ./.github/workflows/test_buildx_and_publish.yml
secrets: inherit
steps:

- name: Launch the Test and publish workflow (${{ needs.evaluate-results.outputs.docker_tag }})
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Test, build and publish

0 comments on commit a5411f6

Please sign in to comment.